且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在swing java中使用布局管理器

更新时间:2023-01-15 10:03:32

请看这里: 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.