package awtDemo;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class setBoundsDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
//设置panel的layout以及sieze
JPanel jpanel = new JPanel();
System.out.println("default PreferredSize is " + jpanel.getPreferredSize());
System.out.println("default Size is " + jpanel.getSize());
jpanel.setLayout(null);
System.out.println("In null layout, the PreferredSize is " + jpanel.getPreferredSize());
System.out.println("In null layout, the Size is " + jpanel.getSize());
jpanel.setPreferredSize(new Dimension(400, 400));
//添加按钮
JButton button11 = new JButton("setBounds");
JButton button12 = new JButton("setLocationAndSetSize");
button11.setBounds(20, 20, 100, 100);
button12.setLocation(250, 250);
button12.setSize(100, 100);
jpanel.add(button11);
jpanel.add(button12);
// 设置窗体属性
JFrame frame = new JFrame("setBoundsDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(jpanel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
default PreferredSize is java.awt.Dimension[width=10,height=10] default Size is java.awt.Dimension[width=0,height=0] In null layout, the PreferredSize is java.awt.Dimension[width=0,height=0] In null layout, the Size is java.awt.Dimension[width=0,height=0]
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有