<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九九国产免费看小说| 国色精品va在线观看免费视频| 日本免费人成在线网站| 久久精品国产亚洲av影院| 日本免费一区二区久久人人澡 | 国产偷国产偷亚洲高清人| 日本一区免费电影| 免费VA在线观看无码| 亚洲成a人无码av波多野按摩 | 国产成人高清亚洲一区久久 | 香港a毛片免费观看| 亚洲资源在线观看| av免费不卡国产观看| 亚洲人成小说网站色| 歪歪漫画在线观看官网免费阅读 | 成在人线av无码免费高潮水| 亚洲精品无码永久在线观看你懂的 | 黄色短视频免费看| 久久精品国产亚洲精品2020| 毛片基地免费观看| 视频一区在线免费观看| 亚洲中文字幕无码日韩| 18禁黄网站禁片免费观看不卡| 亚洲真人无码永久在线观看| 免费久久精品国产片香蕉| 成人妇女免费播放久久久| 亚洲精品永久www忘忧草| 高清国语自产拍免费视频国产 | 国产亚洲男人的天堂在线观看 | 亚洲精品视频免费观看| 国内少妇偷人精品视频免费| 亚洲成a人片7777| 午夜国产羞羞视频免费网站| aa级女人大片喷水视频免费| 亚洲国产成人资源在线软件| 国产成人一区二区三区免费视频| 热99RE久久精品这里都是精品免费| 亚洲精品一卡2卡3卡三卡四卡| 国产乱子伦精品免费无码专区 | 18勿入网站免费永久| 一区二区免费国产在线观看 |