GridBagLayout比较复杂,要具体问题具体分析,你不妨多用一点PANEL和简单的布局器
解决方案 »
- java 内存回收问题
- hibernate 使用联合查询的时候报空指针异常
- 大家的公司用junit么?
- BufferedReader 字符串输出后替换特定字符问题
- 刚刚接触JAVA,三个月后会达到什么水平?
- 求救!本人课程设计,想编写一个多媒体播放程序,请教各位一些问题。
- 关于java打印的问题--给一串html的String,将它按html的格式打印出来
- 收集应用JAVA程序访问 Berkeley DB 的资料!急!
- 已生成类字节码文件,但运行通不过.
- 我想让一窗体始终在最上面,如何做?不是ShowModal()
- java怎样判断一个文本里有多少个单词
- 我的一个工程有很多不同的包当然也放在不同的目录中,用javac如何便宜
import javax.swing.*;public class Test extends JFrame {
JPanel p;
JButton b1, b2, b3, b4, b5, b6, b7, b8;
GridBagLayout gb;
GridBagConstraints gbc; public Test() {
super("MyLayout Test");
gb = new GridBagLayout();
gbc = new GridBagConstraints();
p = new JPanel();
p.setLayout(gb);
getContentPane().add(p); b1 = new JButton("1");
b2 = new JButton("2");
b3 = new JButton("3");
b4 = new JButton("4");
b5 = new JButton("5");
b6 = new JButton("6");
b7 = new JButton("7");
b8 = new JButton("8"); gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(1,1,1,1); gbc.gridy = 1;
gbc.gridwidth = 1;
p.add(b1,gbc);
gbc.gridwidth = 2;
p.add(new JLabel(""),gbc);
gbc.gridwidth = 1;
p.add(b2,gbc);
gbc.gridy++;
p.add(new JLabel(""),gbc);
p.add(b3,gbc);
p.add(b4,gbc);
gbc.gridy++;
p.add(new JLabel(""),gbc);
p.add(b5,gbc);
p.add(b6,gbc);
gbc.gridy++;
p.add(b7,gbc);
gbc.gridwidth = 2;
p.add(new JLabel(""),gbc);
gbc.gridwidth = 1;
p.add(b8,gbc); /*gbc.anchor = GridBagConstraints.NORTHWEST;
gbc.gridx = 0;
gbc.gridy = 1;
gb.setConstraints(b1, gbc);
p.add(b1); gbc.gridx = 1;
gbc.gridy = 1;
gb.setConstraints(b2, gbc);
p.add(b2); gbc.gridx = 0;
gbc.gridy = 2;
gb.setConstraints(b3, gbc);
p.add(b3); gbc.gridx = 1;
gbc.gridy = 2;
gb.setConstraints(b4, gbc);
p.add(b4);//********************************************
gbc.anchor = GridBagConstraints.NORTHEAST;
gbc.gridx = 0;
gbc.gridy = 1;
gb.setConstraints(b5, gbc);
p.add(b5); gbc.gridx = 0;
gbc.gridy = 2;
gb.setConstraints(b6, gbc);
p.add(b6); gbc.gridx = 1;
gbc.gridy = 1;
gb.setConstraints(b7, gbc);
p.add(b7); gbc.gridx = 1;
gbc.gridy = 2;
gb.setConstraints(b8, gbc);
p.add(b8);*/ pack();
setSize(400, 400);
setVisible(true);
setDefaultCloseOperation(Test.EXIT_ON_CLOSE); } public static void main(String args[]) {
new Test();
}
}
有问题了再说