Skip to Main Content

New to Java

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!

underline text in java without using html tags

807598Feb 19 2006 — edited Feb 19 2006
can you plz tell me that how to underline text in java without using html tags,
sample code i tried but it is not working, Plz help


JFrame f = new JFrame("Underline Frame");
JLabel b = new JLabel("The font that doesnt get underlined");
Map m = b.getFont().getAttributes(); //Note I dont need to define which

System.out.println(m);
m.put( TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
m.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
m.put(TextAttribute.SIZE, new Float(20));
b.setFont(b.getFont().deriveFont(m));
System.out.println(b.getFont().getAttributes());
f.getContentPane().add(b);
f.pack();
f.setVisible(true);
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 19 2006
Added on Feb 19 2006
1 comment
198 views