package com.test;
import javax.swing.*;
import java.awt.*;
import java.net.URL;
/**
* @Author:xiexu
* @Date:2023/12/3 19:48
*/
public class BorderLayoutTest extends JFrame {
JButton njButton = new JButton("北边的按钮");
JLabel sLabel = new JLabel("南边的标签");
JRadioButton wRadioBtn = new JRadioButton("男");
JTextArea eArea = new JTextArea("输入内容", 10, 20);
JButton centerButton = new JButton("中间的按钮");
public BorderLayoutTest() {
super("测试边界布局"); // 边界布局尽可能充满整个容器
Container contentPane = getContentPane();
// 设置布局管理器:
contentPane.setLayout(new BorderLayout());
contentPane.add(njButton, BorderLayout.NORTH);
sLabel.setPreferredSize(new Dimension(0, 100));
contentPane.add(sLabel, BorderLayout.SOUTH);
wRadioBtn.setPreferredSize(new Dimension(100, 0)); // 0 表示默认
contentPane.add(wRadioBtn, BorderLayout.WEST);
contentPane.add(eArea, BorderLayout.EAST);
contentPane.add(centerButton, BorderLayout.CENTER);
// 设置窗体图标
URL resource = JframeTest.class.getClassLoader().getResource("tumblr.png");
Image image = new ImageIcon(resource).getImage();
setIconImage(image);
setSize(600, 400); // 单位是像素
// 面板居中显示
setLocationRelativeTo(null);
// 关闭退出程序
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 大小不可改变
setResizable(false);
setVisible(true);
}
public static void main(String[] args) {
new BorderLayoutTest();
}
}
02-03
941
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-08
3575
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交