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