Java borders how to do

Source: Internet
Author: User

The

JComponent also includes a method called SetBorder (), which allows us to place a variety of interesting borders onto some visible components. The following program example uses a method called Showborder () that creates jpanel and places a border into each example, demonstrating some useful different borders. Again, it uses Rtti to find the name of the border we use (culling all the path information), and then place the border name in the middle of the jlable:
 

: Borders.java//different Swing Borders package c13.swing;
Import java.awt.*;
Import java.awt.event.*;
Import javax.swing.*;

Import javax.swing.border.*;
    public class Borders extends JPanel {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 () {setlayout (new GridLayout (2,4));
    Add (Showborder ("Title")) (new Titledborder);
    Add (Showborder (new Etchedborder ()));
    Add (Showborder (new Lineborder (Color.Blue));
    Add (Showborder (new Matteborder (5,5,30,30,color.green));
    Add (Showborder (new BevelBorder (bevelborder.raised));
    Add (Showborder (new Softbevelborder (bevelborder.lowered)); Add (Showborder (New Compoundborder (), New Etchedborder (), New Lineborder (color.red))));
  public static void Main (String args[]) {show.inframe (New Borders (), 500, 300); }
} ///:~

Most of the program examples in this section use Titledborder, but we can note that the rest of the borders are also easy to use. Can create our own borders and place them into buttons, tags, and so on--anything from jcomponent.

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.