How to align JLabel to the left of the JPanel?

后端 未结 2 1749
伪装坚强ぢ
伪装坚强ぢ 2021-02-15 12:50

I want to align my JLabel to the left.

    String lText = \"mybook<         


        
相关标签:
2条回答
  • 2021-02-15 13:14

    FlowLayout uses CENTER alignment by default. Try using LEFT alignment for your JLabel JPanel container

    myJPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    
    0 讨论(0)
  • 2021-02-15 13:16

    You might wish to set the JLabel's horizontalAlignment property. One way is via its constructor. Try:

    JLabel label = new JLabel(lText, SwingConstants.LEFT);
    

    This can also be done via the expected setter method:

    label.setHorizontalAlignment(SwingConstants.LEFT);
    
    0 讨论(0)
提交回复
热议问题