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) {
Retur
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.