How to center align the title in a JFrame?
问题 I have a JFrame with a Title . I want center align the title , so that it appears in the middle of the JFrame's title . Thanks. 回答1: Consider leaving the title left-justified...but...this will get you near the center. For resizable frames, you need to rewrite the title on resize. JFrame t = new JFrame(); t.setSize(600,300); t.setFont(new Font("System", Font.PLAIN, 14)); Font f = t.getFont(); FontMetrics fm = t.getFontMetrics(f); int x = fm.stringWidth("Hello Center"); int y = fm.stringWidth("