Swing 空布局

试了盒布局,说实话不太会用,很多地方都没法更加的细节,又翻了翻资料,知道了还有一个空布局,一看,真不错,很适合我这种菜鸡

用坐标就可以完成界面的布局,不错

话不多说,直接代码

package ui;

import javax.swing.*;

public class TestDemoNull extends JFrame {

    JPanel jp=new JPanel();    //创建面板
    JLabel label1=new JLabel("地点");    //创建标签
    JComboBox cmb=new JComboBox();    //创建JComboBox
    JButton btn0=new JButton("夜泊秦淮 ice paper");
    JButton btn1=new JButton("月光不解风情");
    JButton btn2=new JButton("行人故作冷静");
    JButton btn3=new JButton("夜色更难分明");
    JButton btn4=new JButton("一丝一扣朦胧了倒映");
    JButton btn5=new JButton("你背影何处寻");
    JButton btn6=new JButton("愁眉啼妆难平");
    JButton btn7=new JButton("如烟遮望眼");
    JButton btn8=new JButton("飞鸟随风乱了序");
    JButton btn9=new JButton("*这不比丫的流量明星好听*");


    /********************************************/

    TestDemoNull() {
        cmb.addItem("");    //向下拉列表中添加一项
        cmb.addItem("北京");
        cmb.addItem("上海");
        cmb.addItem("深圳");
        JRadioButton  chkbox1=new JRadioButton ("ice");    //创建指定文本和状态的复选框
        JRadioButton  chkbox2=new JRadioButton ("paper");    //创建指定文本的复选框
        JRadioButton  chkbox3=new JRadioButton ("yyds",true);    //创建指定文本的复选框
        jp.add(chkbox1);
        jp.add(chkbox2);
        jp.add(chkbox3);

        /********************************************/

        init();
        this.setTitle("空");
        this.setResizable(true);
        this.setSize(1920, 1080);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setVisible(true);
    }

    void init() {
        this.setLayout(null);
        label1.setBounds(130,20,100,20);
        cmb.setBounds(190,20,140,20);
        jp.setBounds(130,50,210,35);
        btn0.setBounds(100, 100, 300, 20);
        btn1.setBounds(100, 130, 300, 20);
        btn2.setBounds(100, 160, 300, 20);
        btn3.setBounds(100, 190, 300, 20);
        btn4.setBounds(100, 220, 300, 20);
        btn5.setBounds(100, 250, 300, 20);
        btn6.setBounds(100, 280, 300, 20);
        btn7.setBounds(100, 310, 300, 20);
        btn8.setBounds(100, 340, 300, 20);
        btn9.setBounds(100, 370, 300, 20);
//        label1.setBounds(0,20,100,20);
//        cmb.setBounds(60,20,140,20);
//        jp.setBounds(0,50,210,35);
//        btn1.setBounds(40, 100, 120, 20);
//        btn2.setBounds(40, 130, 120, 20);
//        btn3.setBounds(40, 160, 120, 20);
//        btn4.setBounds(40, 190, 120, 20);
//        btn5.setBounds(40, 220, 120, 20);
//        btn6.setBounds(40, 250, 120, 20);
        this.add(btn0);
        this.add(btn1);
        this.add(btn1);
        this.add(btn2);
        this.add(btn3);
        this.add(btn4);
        this.add(btn5);
        this.add(btn6);
        this.add(btn7);
        this.add(btn8);
        this.add(btn9);
        this.add(label1);
        this.add(cmb);
        this.add(jp);
    }

    public static void main(String args[]) {
        new TestDemoNull();
    }
}

效果如下

Java Swing 空布局_复选框

这种布局就比很舒服,打点一样的把东西都放上去

感谢观看,文笔有限,博客不出彩,还请多多见谅