2024年1月22日发(作者:)
ible(true);}public NewJFrame() {super();initGUI();}private void initGUI() {try {BorderLayout thisLayout = new BorderLayout();getContentPane().setLayout(thisLayout);setDefaultCloseOperation(E_ON_CLOSE);{jp1 = new JPanel();getContentPane().add(jp1, );{font = new JButton();ionListener(this);(font);t("font");}{color = new JButton();(color);ionListener(this);t("color");}}{jsp = new JScrollPane();getContentPane().add(jsp, );{jep = new JTextPane();wportView(jep);ument(new DefaultStyledDocument());
}}pack();setSize(400, 300);} catch (Exception e) {tackTrace();}}public static void setFontSize(JEditorPane editor, int size) {if (editor != null) {if ((size > 0) && (size < 512)) {MutableAttributeSet attr = new SimpleAttributeSet();tSize(attr, size);setCharacterAttributes(editor, attr, false);} else {kAndFeel().provideErrorFeedback(editor);}}}public static void setForeground(JEditorPane editor, Color fg) {if (editor != null) {if (fg != null) {MutableAttributeSet attr = new SimpleAttributeSet();eground(attr, fg);setCharacterAttributes(editor, attr, false);} else {kAndFeel().provideErrorFeedback(editor);}}}public static final void setCharacterAttributes(JEditorPane editor,AttributeSet attr, boolean replace) {int p0 = ectionStart();int p1 = ectionEnd();
if (p0 != p1) {StyledDocument doc = getStyledDocument(editor);racterAttributes(p0, p1 - p0, attr, replace);}StyledEditorKit k = getStyledEditorKit(editor);MutableAttributeSet inputAttributes = utAttributes();if (replace) {Attributes(inputAttributes);}ributes(attr);}protected static final StyledDocument getStyledDocument(JEditorPane e) {Document d = ument();if (d instanceof StyledDocument) {return (StyledDocument) d;}throw new IllegalArgumentException("document must be StyledDocument");}protected static final StyledEditorKit getStyledEditorKit(JEditorPane e) {EditorKit k = torKit();if (k instanceof StyledEditorKit) {return (StyledEditorKit) k;}throw new IllegalArgumentException("EditorKit must be StyledEditorKit");}public void actionPerformed(ActionEvent e) {Object obj = rce();if (obj == font) {JEditorPane editor = jep;setFontSize(editor, 20);}if (obj == color) {JEditorPane editor = jep;setForeground(editor, );


发布评论