Java learning notes-swing interface with box Layout

Source: Internet
Author: User

These four methods are mainly used.

Createhorizontalbox()

Create a component that displays its components from left to rightBox.

Createhorizontalstrut(INT width) // you can use this method to control the intermediate interval between left and right parts.
Create an invisible, fixed-width component.

Createverticalbox()

Create a componentBox.

Createverticalstrut(INT height) // you can use this method to control the intermediate interval between the upper and lower parts.
Create an invisible, fixed height component.

As follows:

Package COM. geogro. webapp. applet. track; import Java. AWT. *; import javax. swing. *; import javax. swing. border. *;/** on the data filtering Panel of the 3G version, enter the filter value to query the 3G value. ** @ author snil * @ date 07-03-26 * @ version 1.0 */public class fliter3gpanel extends jpanel {Private Static font defaultfont = new font ("simsun", Font. plain, 12); // default font titledborder titledborder1 = new titledborder ("parameter settings"); jtextfield xtextfield; jtextfield ytextf Ield; jtextfield ztextfield; jtextfield intetextfield; datechooserjbutton fliterstarttimebutton; datechooserjbutton fliterendtimebutton; jprogressbar fliterloadbar; jbutton okbutton; jbutton cancelbutton; private void jbinit () throws exception {Box B = Box. createverticalbox (); jlabel bannerlabel = new jlabel ("3G data filtering query"); B. add (bannerlabel); // ------------- settheinputpanel ------------------------- ----- Jpanel inputpanel = new jpanel (); titledborder inputpanelborder = new titledborder ("set parameter"); inputpanelborder. settitlefont (defaultfont); inputpanel. setborder (inputpanelborder); box vtemp = Box. createverticalbox (); box htemp1 = Box. createhorizontalbox (); box htemp2 = Box. createhorizontalbox (); box htemp3 = Box. createhorizontalbox (); box htemp4 = Box. createhorizontalbox (); box htemp5 = Box. crea Tehorizontalbox (); box htemp6 = Box. createhorizontalbox (); box htemp7 = Box. createhorizontalbox (); box htemp8 = Box. createhorizontalbox (); xtextfield = new jtextfield (); xtextfield. setpreferredsize (new dimension (50, 10); htemp1.add (New jlabel (":"); htemp1.add (box. createhorizontalstrut (10); // create the distance between the label and textfied. htemp1.add (xtextfield); htemp1.add (New jlabel ("(example: 3.01)"); ytextfield = new JTE Xtfield (); ytextfield. setpreferredsize (new dimension (50, 10); htemp2.add (New jlabel ("portrait:"); htemp2.add (box. createhorizontalstrut (10); htemp2.add (ytextfield); htemp2.add (New jlabel ("(example: 4.01)"); ztextfield = new jtextfield (); ztextfield. setpreferredsize (new dimension (50, 10); htemp3.add (New jlabel ("vertical:"); htemp3.add (box. createhorizontalstrut (10); htemp3.add (ztextfield); htemp3.add (New jlabel ("(Example: 3.01)"); intetextfield = new jtextfield (); intetextfield. setpreferredsize (new dimension (50, 10); htemp4.add (New jlabel ("Comprehensive:"); htemp4.add (box. createhorizontalstrut (10); htemp4.add (intetextfield); htemp4.add (New jlabel ("(example: 5.01)"); fliterstarttimebutton = new datechooserjbutton (); jlabel tmplabel = new jlabel ("Start Time:"); htemp5.add (tmplabel); htemp5.add (fliterstarttimebutton); fliterendtimeb Utton = new datechooserjbutton (); jlabel tmplabel2 = new jlabel ("End Time:"); htemp6.add (tmplabel2); htemp6.add (fliterendtimebutton); fliterloadbar = new jprogressbar (); jlabel tmplabel3 = new jlabel ("Progress:"); htemp7.add (tmplabel3); htemp7.add (fliterloadbar); okbutton = new jbutton ("filter "); cancelbutton = new jbutton ("undo"); htemp8.add (okbutton); htemp8.add (box. createhorizontalstrut (10); htemp8.add (cancel Button); vtemp. add (htemp1); vtemp. add (box. createverticalstrut (10); // create the upper and lower distance from vtemp. add (htemp2); vtemp. add (box. createverticalstrut (10); vtemp. add (htemp3); vtemp. add (box. createverticalstrut (10); vtemp. add (htemp4); vtemp. add (box. createverticalstrut (10); vtemp. add (htemp5); vtemp. add (box. createverticalstrut (10); vtemp. add (htemp6); vtemp. add (box. createverticalstrut (25); vtemp. add (htemp7); vtemp. A Dd (box. createverticalstrut (5); vtemp. Add (htemp8); inputpanel. Add (vtemp); // samples // ------------ other panel init here ------------------------- // initcode! // ------------------------------------------------------------ B. add (inputpanel); // B. add (otherpanel); this. add (B, borderlayout. north);} public fliter3gpanel () {try {jbinit ();} catch (exception ex) {ex. printstacktrace ();}}}

 

The Code is as follows:

 

 

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.