JAVASwing GridBagLayout 布局
用GridBagLayout可实现复杂可控的布局。
以一个输入框为例:
final JTextField username = new JTextField(); final JTextField password = new JTextField(); JPanel regist = new JPanel(); regist.setLayout(new GridBagLayout()); regist.add(new JLabel("username:"), new GridBagConstraints(0,0,1,1, 0.0,0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(2,2,2,2), 0,0)); <pre name="code" name="code"> regist.add(username, new GridBagConstraints(1,0,1,1, 0.0,0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(2,2,2,2), 200,0)); <pre name="code" name="code"><pre name="code" alt="JAVASwing GridBagLayout 格局">
后面输入框的长度可以修改值200 来改变。
具体GridBagConstraints 可参见GridBagConstraints
?