how to use the layout managers in swing java

后端 未结 3 866
青春惊慌失措
青春惊慌失措 2021-01-14 18:28

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

I read

3条回答
  •  萌比男神i
    2021-01-14 19:18

    look here: 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) Is there a "main" area with smaller surrounding areas in your design. If so use a BorderLayout.

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

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

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

    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.

提交回复
热议问题