automatic font resize
问题 How can I find out, if a text in a JTextField is larger than visible area of these JTextField, so that I can change the font size? Thx for any help. Sincerely Christian 回答1: It is possible to compute the text width for a given font with the FontMetrics class and compare this length with the textfield width. JtextField field = new JTextField(); FontMetrics fm = field.getFontMetrics(field.getFont()); int textwidth = fm.stringWidth(field.getText()); 回答2: Instead, ask the JTextField how tall it