How can I align all elements to the left in JPanel?

前端 未结 3 1094
误落风尘
误落风尘 2020-12-14 05:42

I would like to have all elements in my JPanel to be aligned to the left. I try to do it in the following way:

JPanel panel = new JPanel();
panel.setLayout(n         


        
3条回答
  •  天命终不由人
    2020-12-14 06:33

    The easiest way I've found to place objects on the left is using FlowLayout.

    JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    

    adding a component normally to this panel will place it on the left

提交回复
热议问题