Java aligning components in panels

后端 未结 1 627
难免孤独
难免孤独 2021-01-25 17:27

I am trying to add components to SOUTH of a BorderLayout I need it to look like this example.

------------------------------------
|                                      


        
相关标签:
1条回答
  • 2021-01-25 18:06

    One way is to use a horizontal Box Layout on the panel. Then you can use glue to separate the groups of components:

    JPanel panel = new JPanel();
    panel.setLayout(...);
    panel.add(textField);
    panel.add(button);
    panel.add(the glue here);
    panel.add(label);
    

    Read the section from the Swing tutorial on How to Use BoxLayout for more information on the glue and working examples.

    0 讨论(0)
提交回复
热议问题