按栏目快速找到需要的在线工具。
JSON 解析、格式化、压缩、对比与实体生成。
Base64、URL、进制、哈希与 AES 加密工具。
DNS、SEO、HTTP、robots 与站点检查。
日期、计算器、健康与便民工具。
前端、编程、数据库与服务器教程。
11 个工具栏目,按使用场景分类。
日期:2014-05-16 浏览次数:20694 次
用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" class="java"> </pre> 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" class="java"><pre name="code" class="java"> regist.add(new JLabel("password"), new GridBagConstraints(0,1,1,1, 0.0,0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(2,2,2,2), 0,0));</pre></pre>
<pre name="code" class="java"><pre name="code" class="java"><pre name="code" class="java"> regist.add(password, new GridBagConstraints(1,1,1,1, 0.0,0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(2,2,2,2), 200,0));</pre></pre></pre>
?
这里面用到了GridBagConstraints 来定义组件的位置排列信息。
最终的效果如下:
后面输入框的长度可以修改值200 来改变。
具体GridBagConstraints 可参见GridBagConstraints