简体   繁体   中英

which LayOut Manager is most suitable for my GUI?

I am struggling with the Layout Manager choice. I have to set a GUI which is basically like a stack, for instance:

---------------
'             '
'  ---------  '
'  |       |  '
'  ---------  '
'             '
'  ---------  '
'  |       |  '
'  ---------  '
'             '
'   LABEL     '
'             '
'  ---------  '
'  |       |  '
'  ---------  '
'             '
---------------

I have tried BorderLayout whcih did not work well as the 'LABEL' will replace the second textfield as CENTER. And I cannot use BoxLayout.

and also does Flowlayout set the labels and fields vertical?

Use BoxLayout - easy to use without the complexity of GridbagLayout

BoxLayout allows multiple components to be laid out either vertically or horizontally. The components will not wrap so, for example, a vertical arrangement of components will stay vertically arranged when the frame is resized. Nesting multiple panels with different combinations of horizontal and vertical gives an effect similar to GridBagLayout, without the complexity. The BoxLayout manager is constructed with an axis parameter that specifies the type of layout that will be done. For all directions, components are arranged in the same order as they were added to the container.

You can stack widgets on top like this

在此输入图像描述

or side by side

在此输入图像描述

You can also use TableLayout to achieve a similar effect.

You can use the Grid layout with the constructor, which taken the number of rows and columns as the parameters. Set the number of columns to 1 with the number of rows you want

eg:

GridLayout myLayout =new GridLayout( 3, 1 );

I tend to avoid all the standard Swing layout managers. Apart from GridbagLayout they are all very limited in their usefulness, and the latter is very complicated. At the moment DesignGridLayout is my first choice, MiG Layout is nice as well. While your specific scenario would work in a box layout, it will be hard to extend it.

According to your current requirement. Grid Layout , is the best one. Refer the link and enjoy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM