How to align JLabel-JTextField pairs vertically

前端 未结 7 1168
独厮守ぢ
独厮守ぢ 2020-12-11 02:33

What I mean by a JLabel-JTextField pair is a JLabel component followed by a JTextField one, for example, \"Parameter 1: -----\" where \"-----\" denotes a blank JTextField.

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-11 03:32

    This is a perfect use case for DesignGridLayout:

    DesignGridLayout layout = new DesignGridLayout(contentPane);
    layout.labelAlignment(LabelAlignment.RIGHT);
    layout.row().grid(label1).add(field1);
    layout.row().grid(label2).add(field2);
    ...
    

提交回复
热议问题