如何在swing java中使用布局管理器 [英] how to use the layout managers in swing java

查看:122
本文介绍了如何在swing java中使用布局管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是布局经理的新手,比如 Flow border ,...

我主要使用 setBounds()来设置我的组件的位置。

I'm new to layout managers like Flow, borders, ...
I mostly use setBounds() to set the position of my components.

我读了一篇关于使用的文章 setBounds 是一种不错的做法,最好使用一些布局。

I read on an article that using setBounds is not an good practice and it's better to use some layout.

哪些是最好和最常用的布局?

如何使用布局管理器定位按钮;而不是 setbounds(10,10,100,30)

推荐答案

请看这里: http://download.oracle .com / javase / tutorial / uiswing / layout / using.html

基本上你应该忘记坐标。在更高级别的设计中查看对话框。您应该问自己的问题。

Basically you should forget about coordinates. Look at your dialogs at a higher level of design. Questions you should ask yourself.

1)您的设计中是否存在周围区域较小的主区域。如果是这样的话,请使用BorderLayout。

1) Is there a "main" area with smaller surrounding areas in your design. If so use a BorderLayout.

2)你的设计中是否有相似的网格区域,如果是这样的话,请使用GridLayout。

2) Is there equal grid like areas in your design, If so use a GridLayout.

3)如果您需要自上而下或左右布局,请考虑BoxLayout

3) If you need a top-down, or left-right layout, consider a BoxLayout

4)如果您想要显示复杂的表格,可能使用来自jgoodies的FormLayout。

4) If you want to show a complex form, probably use a FormLayout from jgoodies.

但是你必须从高层看待事物。对话框的任何一个顶级部分都可能有子部分。如果是这种情况,那么您需要在该部分中放置JPanel,然后在该JPanel中使用子布局。再次对该小组使用上述问题。

But you have to look at things from a high level. There may be subsections in any one top level section of your dialog. If that is the case, then you need to put a JPanel in that section, and then use a sub layout in that JPanel. Use the above questions over again for that panel.

这篇关于如何在swing java中使用布局管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆