Skip to Main Content

Java Programming

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!

Warning trying to underline JLabel's text?

807605Aug 30 2007 — edited Aug 30 2007
Hello everyone. I've been trying to make the font of a JLabel underlined. I found this solution:
Map map = myView.getMyJLabel().getFont().getAttributes();
map.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
myView.getMyJLabel().setFont(new Font(map));
However, I can't make this 2 warnings dissapear:
Type safety: The method put(Object, Object) belongs to the raw type Map. References to generic type Map<K,V> should be parameterized.
Type safety: The expression of type Map needs unchecked conversion to conform to Map<? extends AttributedCharacterIterator.Attribute, ?>

I've also tried this:
Map<TextAttribute, ?> map = myView.getMyJLabel().getFont().getAttributes();
map.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
myView.getMyJLabel().setFont(new Font(map));
But in this case I get the following error:
The method put(TextAttribute, capture-of ?) in the type Map<TextAttribute, capture-of ?> is not applicable for the arguments (TextAttribute, Integer)

Does anyone know how can I get rid of this warnings or maybe, a simpler way to underline a JLabel's text?

Thanks in advance :)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 27 2007
Added on Aug 30 2007
4 comments
917 views