How to put the text of a JLabel under its icon

Bilal Syed Hussain picture Bilal Syed Hussain · Mar 1, 2012 · Viewed 11.6k times · Source

I trying to put the text of a JLabel under its icon (centered) at the momemnt I can get this

Current

using JLabel north = new JLabel("North")

I tried using html in the label JLabel("<HTML><BR>North</HTML>") but it is not aligned properly. Any suggestions?


Answer

icyrock.com picture icyrock.com · Mar 1, 2012

See this:

Basically, use this in your case:

north.setHorizontalTextPosition(JLabel.CENTER);
north.setVerticalTextPosition(JLabel.BOTTOM);