How to align JLabel to the left of the JPanel?

Archit Verma picture Archit Verma · Jul 7, 2013 · Viewed 29.3k times · Source

I want to align my JLabel to the left.

    String lText = "<html><b><font color = white face = comic sans ms size = 20>mybook</font></b></html>";
    JLabel label = new JLabel(lText);
    label.setBorder(new EmptyBorder(25,0,25,500));

I tried to do it using EmptyBorder but it isnt aligning properly. I am using FlowLayout

Answer

Reimeus picture Reimeus · Jul 7, 2013

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

myJPanel.setLayout(new FlowLayout(FlowLayout.LEFT));