I am trying to figure out a way to center the text within a JLabel. I trying to set a specific size of the label, and then center the text in the very middle (horizontally) of that label. I have tried many different methods from this forum and other places on Google, but none of them have had any effect. For example:
label = new JLabel ("<html>blah, blah, blah, blahblah, blah...</html>");
// HTML tags make the lines wrap.
label.setHorizontalAlignment(JLabel.CENTER);
label.setPreferredSize (new Dimension (84, 48));
The text remains aligned left within the label. Is there a way to get it to center within the label?