Java Swing Absolute Layout management method, NULL layout

Source: Internet
Author: User

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

Then call the component's SetBounds () method

The position of the button is set to (100,100) the length width is 60,25

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

?
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("固定资产管理系统");        super.setSize(380, 292);        super.setVisible(true);        super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        centered(this);        btLog = new JButton("登     录");        btLog.setBounds(new Rectangle(93, 220, 180, 30));//参数分别是坐标x,y,宽,高        this.setLayout(null);//设置布局管理器为空        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("记住密码");        pwdKeep.setBounds(new Rectangle(68, 185, 110, 25));        this.add(pwdKeep);        adminType = new JComboBox(new String[] { "普通职员", "管理员", "高级管理员" });        adminType.setBounds(new Rectangle(183, 185, 100, 25));        this.add(adminType);    }//布局居中方法    public void centered(Container container) {        Toolkit toolkit = Toolkit.getDefaultToolkit();        Dimension screenSize = toolkit.getScreenSize();        int w = container.getWidth();        int h = container.getHeight();        container.setBounds((screenSize.width - w) / 2,                (screenSize.height - h) / 2, w, h);    }}

Http://www.cnblogs.com/taoweiji/archive/2013/02/17/2914311.html

Java Swing Absolute Layout management method, null layout (GO)

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.