Java swing boundary learning notes

Source: Internet
Author: User

There are several boundaries defined in swing: EmptyBorder, LineBorder, BevelBorder, SoftBevelBorder, MatteBorder, CompoundBorder, TitledBorder, etchedBorder: the following uses a small example to describe how these boundaries are used and how they work.

 

 

Class labelpanel extends jpanel {Border border; jlabel label; Public labelpanel () {// 3. setlayout (New gridlayout (3, 4, 15, 15) for grid layout with 3 rows * 4 columns and 5 Vertical spaces; // 4. create an emptyborder label Label = new jlabel ("empty", jlabel. center); label. setopaque (true); // create an emptyborder (top, left, bottom, right) Border = new emptyborder (1, 1, 1, 1 ); // assign the border to the tag. label. setborder (Border); add (Label); // 5. (roate a label wi lt. AR. etched border. label = new jlabel ("etched raised", jlabel. center); label. setopaque (true); // create a raised etching boundary border = new etchedborder (etchedborder. raised); label. setborder (Border); add (Label); // 6. create a label with a color border. label = new jlabel ("etched lowered", jlabel. center); label. setopaque (true); // etchedborder (INT etchtype, color highlighted, color shadow) Border = new etchedborder (etchedborder. lowered, color. red, color. blue); label. setborder (Border); add (Label); // 7. create a label with a convex and oblique cut boundary. label = new jlabel ("bevel up", jlabel. center); label. setopaque (true); border = new bevelborder (bevelborder. raised); // raisedbevel typelabel. setborder (Border); add (Label); // 8. create a label with the concave and oblique cut boundary. label = new jlabel ("bevel down", jlabel. center); label. setopaque (true); border = new bevelborder (bevelborder. lowered); // lowered bevel typelabel. setborder (Border); add (Label); // 9. create a label Label with highlighted and oblique cut boundary = new jlabel ("coloredbevel", jlabel. center); label. setopaque (true); border = new bevelborder (bevelborder. raised, // raised bevel typecolor. gray, color. yellow); // hightlight and SBA & 'colorslabel. setborder (Border); add (Label); // 10. create a label with a concave soft oblique cut boundary. label = new jlabel ("softbevel lowered", jlabel. center); label. setopaque (true); border = new softbevelborder (bevelborder. lowered); label. setborder (Border); add (Label); // 11. create a label with a rough border .. label = new jlabel ("matte icon", jlabel. center); label. setopaque (true); icon = new imageicon ("a.gif"); // Top = 20, Left = 20, Bottom = 20; right = 20 and matte iconborder = new matteborder (20, 20, 20, 20, icon); label. setborder (Border); add (Label); // 12. create a line border label .. label = new jlabel ("line", jlabel. center); label. setopaque (true); border = new lineborder (color. red, // line color = red5); // line thickness 5. label. setborder (Border); add (Label); // 13. create a gray line border label = new jlabel ("grayline", jlabel. center); label. setopaque (true); // create a gray lineborderborder = lineborder with a width of 1. creategraylineborder (); label. setborder (Border); add (Label); // 14. create a label for the hybrid border. label = new jlabel ("bevelborder \ n etchedborder", jlabel. center); label. setopaque (true); // create boundary border = new compoundborder (New bevelborder (bevelborder. raised), new etchedborder (etchedborder. raised); label. setborder (Border); add (Label); // 15. Create a label with a title boundary. label = new jlabel ("titled", jlabel. center); label. setopaque (true); border = new titledborder (New lineborder (color. red), "lined & titled", // Title titledborder. center, // Title just_ficaticr.titledborder.center, // Title location. new font ("sans", Font. bold, 16), // font. color. blue); // color label. setborder (Border); add (Label );}}

Create a new window and add the panel above.

 

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.