SetBounds method, with setlayout (null)

Source: Internet
Author: User

Reproduced from: http://blog.csdn.net/taoweiji2008/article/details/8585306



First, the layout of the relevant container is set to setlayout (null);

Then call the component's SetBounds () method

Set the position of the button to (100,100) long width, respectively, 60,25

Jbutton.setbounds (New Rectangle (100, 100, 60, 25));

[Java] View Plain copy import java.awt.container;   import java.awt.dimension;   Import  java.awt.Rectangle;   import java.awt.toolkit;      import  javax.swing.jbutton;   import javax.swing.jcheckbox;   import  javax.swing.jcombobox;   import javax.swing.jframe;   import  javax.swing.jpasswordfield;   import javax.swing.jtextfield;      public  class log extends jframe {       public static void  main (String[] args)  {           log log  = new log ();       }       private  JButton btLog;       private JTextField tfUser;       private jpasswordfield tfpwd;       private JCheckBox pwdKeep;        private JComboBox adminType;          public  log ()  {           super ("Fixed Asset Management system");           super.setsize (380, 292);            super.setvisible (true);            super.setdefaultcloseoperation (jframe.exit_on_close);            centered (this);           btlog = new  jbutton ("Login       record");            Btlog.setbounds (New rectangle (93, 220, 180, 30))//parameters are coordinates x,y, wide, high         &nbSp;   this.setlayout (null);/Set layout manager to empty             this.add (btlog);           tfUser = new  JTextField ();           tfuser.setbounds (New Rectangle ( 73, 115, 220, 25));           this.add (TfUser) ;           tfpwd = new jpasswordfield ();            tfpwd.setbounds (New rectangle (73, 150,  220, 25));           this.add (TFPWD);           pwdkeep = new jcheckbox ("Remember Password");           pwdkeep.setbounds (New rectangle (68, 185, 110,  25));  &nbsp         this.add (pwdkeep);            admintype = new jcombobox (new string[] {  "General Staff",  "admin",   "Senior administrator" &nbsp});           admintype.setbounds (new  rectangle (183, 185, 100, 25));            this.add (admintype);          }  //Layout Center method        public void centered (Container container)  {            toolkit toolkit = toolkit.getdefaulttoolkit ();            Dimension screenSize =  Toolkit.getscreensize ();           int w =  Container.getwidth ();   &nbsP;       int h = container.getheight ();            container.setbounds ((screensize.width - w)  / 2,                     ( SCREENSIZE.HEIGHT - H)  / 2, w, h);       }   } 

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.