■■■ ■■■■■■■■■ ■■■■■■■■■ ■■■■■■请问我如何把六个控件排成以上的布局?(左三个一样宽,右三个一样宽,且不要紧挨着)把每个控件SetBounds的方法,我觉得太傻。用LayOut可以实现么?GridLayout实现的好象不满足我的要求,因为它总是使所有控件width相同,而且紧挨在一起。谢谢!!
■■■ ■■■■■■■■■ ■■■■■■■■■ ■■■■■■请问我如何把六个控件排成以上的布局?(左三个一样宽,右三个一样宽,且不要紧挨着)把每个控件SetBounds的方法,我觉得太傻。用LayOut可以实现么?GridLayout实现的好象不满足我的要求,因为它总是使所有控件width相同,而且紧挨在一起。谢谢!!
我觉得没必要把精力放在排版上
咱们又不是干美工的
flowlayout,borderlayou,boxlayou结合使用,然后设置间隔就行
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;public class T
{
public static void main(String[] args)
{
JLabel label1 = new JLabel("姓名:");
JLabel label2 = new JLabel("出生日期:");
JLabel label3 = new JLabel("地址:");
JTextField textfield1 = new JTextField(10);
JTextField textfield2 = new JTextField(10);
JTextField textfield3 = new JTextField(10);
JPanel p = new JPanel(new GridBagLayout());
p.add(label1, new GridBagConstraints(
0, 0, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE,
new Insets(5, 5, 5, 5), 0, 0));
p.add(textfield1, new GridBagConstraints(
1, 0, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(5, 5, 5, 5), 0, 0)); p.add(label2, new GridBagConstraints(
0, 1, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE,
new Insets(0, 5, 5, 5), 0, 0));
p.add(textfield2, new GridBagConstraints(
1, 1, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(0, 5, 5, 5), 0, 0)); p.add(label3, new GridBagConstraints(
0, 2, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.NONE,
new Insets(0, 5, 5, 5), 0, 0));
p.add(textfield3, new GridBagConstraints(
1, 2, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(0, 5, 5, 5), 0, 0)); JFrame f = new JFrame();
f.getContentPane().add(p, BorderLayout.CENTER);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}