This article is your own study notes, welcome reprint, but please indicate the source: http://blog.csdn.net/jesson20121020
1. Border
JComponent has a setborder () method that allows you to set a variety of borders for any visual component. The following example demonstrates some of the available borders using the Showborder () method. This method first creates a JPanel, then sets the appropriate border, and also displays the name of the border in JLabel.
public class Borders extends JFrame {private static JPanel Showborder (Border b) {JPanel JP = new JPanel (); Jp.setlayout (new BorderLayout ()); String nm = B.getclass (). toString (); nm = nm.substring (Nm.lastindexof ('. ') +1); Jp.add (new JLabel (Nm,jlabel.center), borderlayout.center); Jp.setborder (b); return JP;} Public Borders () {//TODO auto-generated constructor Stubsetlayout (new GridLayout (2,4)); SetSize (500,300); setvisible ( true), add (Showborder ("Title")), Add (Showborder (new Etchedborder ())), Add (Showborder (new Lineborder (Color.Blue)), Add (Showborder (New Matteborder (5, 5, (), Color.green)), Add (Showborder (New BevelBorder ( bevelborder.raised)), Add (Showborder (new Softbevelborder (bevelborder.lowered))), Add (Showborder (new Compoundborder (New Etchedborder (), New Lineborder (color.red)));} /** * @param args */public static void main (string[] args) {//TODO auto-generated method Stubnew Borders ();}}
Operation Result:
2. Editor
The editor here refers to the Jtextpanel component, which can support many editing operations without any trouble, the following example is a simple application of this component, click the button, the defined text is displayed in the Jtextpanel.
public class TextPane extends JFrame {private JButton B = new JButton ("Add Text");p rivate jtextpane tp = new Jtextpane ();p Ublic TextPane () {//TODO auto-generated constructor stubsetvisible (true); SetSize (500,300); Add (new JScrollPane (TP)); Add (borderlayout.south,b); B.addactionlistener (new ActionListener () {@Overridepublic void actionperformed ( ActionEvent e) {//TODO auto-generated method stubfor (int i = 0;i < 10;i++) {Tp.settext (Tp.gettext () + "This is test str ing "+i+" \ n ");}}); /** * @param args */public static void main (string[] args) {//TODO auto-generated method Stubnew TextPane ();}}
Operation Result:
In addition, Jtextpane has built-in features such as auto-wrapping and other features that can be referenced in the JDK documentation.
Java Interface Programming (7)------borders and editors