Java Interface Programming (7)------borders and editors

Source: Internet
Author: User

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

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.