<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 38,  comments - 22,  trackbacks - 0


    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    import javax.swing.JButton;
    import javax.swing.JEditorPane;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextPane;
    import javax.swing.UIManager;
    import javax.swing.WindowConstants;
    import javax.swing.text.AttributeSet;
    import javax.swing.text.DefaultStyledDocument;
    import javax.swing.text.Document;
    import javax.swing.text.EditorKit;
    import javax.swing.text.MutableAttributeSet;
    import javax.swing.text.SimpleAttributeSet;
    import javax.swing.text.StyleConstants;
    import javax.swing.text.StyledDocument;
    import javax.swing.text.StyledEditorKit;

    public class NewJFrame extends javax.swing.JFrame implements ActionListener {
    ?private JPanel jp1;

    ?private JButton color;

    ?private JTextPane jep;

    ?private JScrollPane jsp;

    ?private JButton font;

    ?/**
    ? * Auto-generated main method to display this JFrame
    ? */
    ?public static void main(String[] args) {
    ??NewJFrame inst = new NewJFrame();
    ??inst.setVisible(true);
    ?}

    ?public NewJFrame() {
    ??super();
    ??initGUI();
    ?}

    ?private void initGUI() {
    ??try {
    ???BorderLayout thisLayout = new BorderLayout();
    ???getContentPane().setLayout(thisLayout);
    ???setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    ???{
    ????jp1 = new JPanel();
    ????getContentPane().add(jp1, BorderLayout.NORTH);
    ????{
    ?????font = new JButton();
    ?????font.addActionListener(this);
    ?????jp1.add(font);
    ?????font.setText("font");
    ????}
    ????{
    ?????color = new JButton();
    ?????jp1.add(color);
    ?????color.addActionListener(this);
    ?????color.setText("color");
    ????}
    ???}
    ???{
    ????jsp = new JScrollPane();
    ????getContentPane().add(jsp, BorderLayout.CENTER);
    ????{
    ?????jep = new JTextPane();
    ?????jsp.setViewportView(jep);
    ?????jep.setDocument(new DefaultStyledDocument());
    ????}
    ???}
    ???pack();
    ???setSize(400, 300);
    ??} catch (Exception e) {
    ???e.printStackTrace();
    ??}
    ?}

    ?public static void setFontSize(JEditorPane editor, int size) {
    ??if (editor != null) {
    ???if ((size > 0) && (size < 512)) {
    ????MutableAttributeSet attr = new SimpleAttributeSet();
    ????StyleConstants.setFontSize(attr, size);
    ????setCharacterAttributes(editor, attr, false);
    ???} else {
    ????UIManager.getLookAndFeel().provideErrorFeedback(editor);
    ???}
    ??}
    ?}

    ?public static void setForeground(JEditorPane editor, Color fg) {
    ??if (editor != null) {
    ???if (fg != null) {
    ????MutableAttributeSet attr = new SimpleAttributeSet();
    ????StyleConstants.setForeground(attr, fg);
    ????setCharacterAttributes(editor, attr, false);
    ???} else {
    ????UIManager.getLookAndFeel().provideErrorFeedback(editor);
    ???}
    ??}
    ?}

    ?public static final void setCharacterAttributes(JEditorPane editor,
    ???AttributeSet attr, boolean replace) {
    ??int p0 = editor.getSelectionStart();
    ??int p1 = editor.getSelectionEnd();
    ??if (p0 != p1) {
    ???StyledDocument doc = getStyledDocument(editor);
    ???doc.setCharacterAttributes(p0, p1 - p0, attr, replace);
    ??}
    ??StyledEditorKit k = getStyledEditorKit(editor);
    ??MutableAttributeSet inputAttributes = k.getInputAttributes();
    ??if (replace) {
    ???inputAttributes.removeAttributes(inputAttributes);
    ??}
    ??inputAttributes.addAttributes(attr);
    ?}

    ?protected static final StyledDocument getStyledDocument(JEditorPane e) {
    ??Document d = e.getDocument();
    ??if (d instanceof StyledDocument) {
    ???return (StyledDocument) d;
    ??}
    ??throw new IllegalArgumentException("document must be StyledDocument");
    ?}

    ?protected static final StyledEditorKit getStyledEditorKit(JEditorPane e) {
    ??EditorKit k = e.getEditorKit();
    ??if (k instanceof StyledEditorKit) {
    ???return (StyledEditorKit) k;
    ??}
    ??throw new IllegalArgumentException("EditorKit must be StyledEditorKit");
    ?}

    ?public void actionPerformed(ActionEvent e) {
    ??Object obj = e.getSource();
    ??if (obj == font) {
    ???JEditorPane editor = jep;
    ???setFontSize(editor, 20);
    ??}
    ??if (obj == color) {
    ???JEditorPane editor = jep;
    ???setForeground(editor, Color.red);
    ??}
    ?}

    }

    posted on 2007-01-25 16:58 aaabbb 閱讀(1997) 評論(1)  編輯  收藏 所屬分類: Swing
    主站蜘蛛池模板: 免费福利在线观看| 99国产精品视频免费观看| 亚洲免费在线视频播放| 亚洲人成人网站色www| 一级毛片大全免费播放下载| 国产免费直播在线观看视频| 亚洲欧美成aⅴ人在线观看| 成人无码区免费视频观看| 亚洲三级视频在线| 麻豆最新国产剧情AV原创免费| 亚洲性无码av在线| 久久国产免费福利永久| 亚洲国产一区在线观看| 国产在线观看麻豆91精品免费| 亚洲不卡1卡2卡三卡2021麻豆| 成人免费网站在线观看| 亚洲av日韩av永久无码电影| 和老外3p爽粗大免费视频| 亚洲精品无码mⅴ在线观看| 日本免费一区二区在线观看| 一级A毛片免费观看久久精品 | 亚洲av永久无码精品天堂久久 | 成人免费一区二区无码视频| 亚洲色偷偷综合亚洲av78| 天天摸天天碰成人免费视频| 亚洲av成人中文无码专区| 亚洲成a人片在线观看国产| 你是我的城池营垒免费看| 亚洲综合精品一二三区在线| 免费无码又爽又刺激聊天APP| 亚洲AV色欲色欲WWW| 久久精品国产精品亚洲艾草网美妙| 免费日本一区二区| 亚洲欧洲国产日韩精品| 国产偷国产偷亚洲高清在线| 亚洲乱色伦图片区小说| 国产AV无码专区亚洲AV毛网站| 成人精品视频99在线观看免费| 亚洲va中文字幕无码| 在线免费视频你懂的| 亚洲一区二区三区四区视频 |