JLabel with Icon aligned to left

alignment, java, jlabel, swing

Solution

If you mean someting like this, then I cheated.

Basically, I created two `JLabel`s on a `JPanel`. Using a `GridBagLayout` I aligned the two labels onto of each other and anchored to the `WEST`

It would pretty easy to create a custom component for the purpose if you wanted to reuse it.

Problem

I have a JLabel with a Icon and text aligned to bottom, the icon is center to the text, how do i have the Text and the icon aligned to left and the text below the icon. My current code is as below ``` label.setIcon(new ImageIcon(fileName)); label.setText("This text is going to be varying size and can be bit long"); label.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); label.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); ```

Original source