Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Centering Text within JLabel

843805Apr 24 2006 — edited Apr 25 2006
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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 23 2006
Added on Apr 24 2006
6 comments
242 views