绝对布局,setLayout(null)


package com.company;

import javax.swing.*;
import java.awt.*;

public class Main extends JFrame {
    public Main(){
        setBounds(100,100,200,150);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        Container c=getContentPane();
        c.setLayout(null);//将容器的布局设为绝对布局
        JButton b1=new JButton("按钮1"),b2=new JButton("按钮2");//创建两个按钮
        b1.setBounds(10,30,80,30);//设置按钮在容器中的坐标和大小
        b2.setBounds(60,70,100,20);
        c.add(b1);
        c.add(b2);
        setVisible(true);
    }

    public static void main(String[] args) {
        new Main();
    // write your code here
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM