Вопрос

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