<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 閱讀(2005) 評論(1)  編輯  收藏 所屬分類: Swing
    主站蜘蛛池模板: 亚洲AV中文无码乱人伦下载| 免费人成年激情视频在线观看| 亚洲成A人片在线观看无码不卡| 四虎影视久久久免费观看| 亚洲va久久久噜噜噜久久| selaoban在线视频免费精品| 亚洲人成色7777在线观看不卡| 美女无遮挡免费视频网站| 免费在线观看日韩| 青青青视频免费观看| 四虎永久在线精品免费影视| 美女视频黄频a免费观看| 亚洲国产精品一区二区第一页免 | 老司机69精品成免费视频| 国产AV无码专区亚洲AV毛网站| 高清一区二区三区免费视频| 亚洲福利视频一区| 18禁网站免费无遮挡无码中文 | 亚洲无码日韩精品第一页| 国产精品无码永久免费888| 亚洲国产一二三精品无码| 免费A级毛片无码专区| 亚洲成人激情小说| 日韩精品亚洲专区在线观看| 精品久久亚洲中文无码| 色吊丝最新永久免费观看网站 | 100000免费啪啪18免进| 亚洲高清国产拍精品熟女| 亚洲精品国产综合久久一线| 日韩免费电影网站| 亚洲综合无码无在线观看| 亚洲电影日韩精品| 最近免费字幕中文大全视频| 亚洲乱亚洲乱妇24p| 国产亚洲真人做受在线观看| 中文字幕乱码免费视频| 四虎国产精品永免费| 亚洲色欲或者高潮影院| 99久久人妻精品免费一区| 国产精品亚洲综合久久| a级亚洲片精品久久久久久久 |