Question

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.

Was it helpful?

Solution

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));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top