Arrange the Label with its respective field Swing

前端 未结 6 1878
小鲜肉
小鲜肉 2021-01-20 18:06

I need to align all the fields with the respective labels,

\"enter

here is my

6条回答
  •  不思量自难忘°
    2021-01-20 18:48

    After some findings - MigLayout looks to be the best option for me

    Code will be just the following:

    JPanel parentPanel = new JPanel(new MigLayout("wrap 2")); //Autowrap after each 2 elements
    parentPanel.add(label1);
    parentPanel.add(field1);
    parentPanel.add(label2);
    parentPanel.add(field2);
    ...
    

    No need to specify indexes by hand or create some huge layout infrastructure - simple code to get conceptually simple result. Please see the QuickStart guide: http://www.miglayout.com/QuickStart.pdf

    You can plug it in or directly download from Maven: https://mvnrepository.com/artifact/com.miglayout/miglayout

提交回复
热议问题