JAVA BorderLayout 设置
setLayout(BorderLayout)如何控制东南西北的大小和方向我是用design绘制的但是没法拖动大小...
setLayout(BorderLayout)如何控制 东南西北的大小和方向
我是用design 绘制的 但是没法拖动大小 展开
我是用design 绘制的 但是没法拖动大小 展开
展开全部
BorderLayout控制大小好像不可以,控制方向到时没问题.
示例:
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.WindowConstants;
public class Demo2 extends javax.swing.JFrame {
private JButton jButton1;
private JButton jButton2;
private JButton jButton3;
private JButton jButton4;
private JButton jButton5;
public static void main(String[] args) {
Demo2 inst = new Demo2();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
public Demo2() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
jButton1 = new JButton("北");
jButton2 = new JButton("南");
jButton3 = new JButton("东");
jButton4 = new JButton("西");
jButton5 = new JButton("中");
getContentPane().add(jButton1, BorderLayout.NORTH);
getContentPane().add(jButton2, BorderLayout.SOUTH);
getContentPane().add(jButton3, BorderLayout.EAST);
getContentPane().add(jButton4, BorderLayout.WEST);
getContentPane().add(jButton5, BorderLayout.CENTER);
pack();
setSize(400, 300);
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例:
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.WindowConstants;
public class Demo2 extends javax.swing.JFrame {
private JButton jButton1;
private JButton jButton2;
private JButton jButton3;
private JButton jButton4;
private JButton jButton5;
public static void main(String[] args) {
Demo2 inst = new Demo2();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
public Demo2() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
jButton1 = new JButton("北");
jButton2 = new JButton("南");
jButton3 = new JButton("东");
jButton4 = new JButton("西");
jButton5 = new JButton("中");
getContentPane().add(jButton1, BorderLayout.NORTH);
getContentPane().add(jButton2, BorderLayout.SOUTH);
getContentPane().add(jButton3, BorderLayout.EAST);
getContentPane().add(jButton4, BorderLayout.WEST);
getContentPane().add(jButton5, BorderLayout.CENTER);
pack();
setSize(400, 300);
} catch (Exception e) {
e.printStackTrace();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询