I trying to put the text of a JLabel under its icon (centered) at the momemnt I can get this
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?
The short answer is yes, as a JLabel is a Container , so it can accept a Component (a JLabel is a subclass of Component ) to add into the JLabel by using the add method: JLabel outsideLabel = new JLabel("Hello"); JLabel insideLabel = new JLabel("World"); outsideLabel.
See this:
Basically, use this in your case:
north.setHorizontalTextPosition(JLabel.CENTER);
north.setVerticalTextPosition(JLabel.BOTTOM);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With