質問

can anyone please tell me how to underline text on JTextField? I create a code that have a JPopupMenu when you right clicked on textfield the menu "bold,italic,underline,plain" will popup and when you clicked underline it will underline the text inside JtextField.

役に立ちましたか?

解決

Yes - by adjusting the Font attributes of the component

Font font = textField.getFont();
Map attributes = font.getAttributes();
attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
textField.setFont(font.deriveFont(attributes));
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top