Reputation: 657
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);
Upvotes: 4
Views: 1479
Reputation: 1
your just setting the Position of your text in your code..not the Icon it self
Try to separate the icon in the label then format it using set bounds or any formlayout
Upvotes: 0
Reputation: 347314
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.
Upvotes: 5