import java.awt.*; 
import java.awt.event.*; 
import javax.swing.*; 
public class SwingTest{ 
public static void main(String[]args){ 
EventQueue.invokeLater(()->showFrame()); 
} 
private static void showFrame(){ 
try{ 
UIManager.setLookAndFeel ( UIManager.getSystemLookAndFeelClassName() ); 
}catch(ClassNotFoundException|InstantiationException|IllegalAccessException|UnsupportedLookAndFeelException x){ 
System.err.println("Could not use system Look and Feel: "+x); 
System.exit(99); 
} 
JFrame frame=new JFrame("SwingTest"); 
JLabel topLabel=new JLabel("SwingTest"); 
frame.addComponentListener( 
new ComponentAdapter (){ 
@Override 
public void componentShown(ComponentEvent e){ 
JOptionPane.showMessageDialog(null,"Font size: "+topLabel.getFont().getSize()); 
} 
} 
); 
frame.add(topLabel,BorderLayout.NORTH); 
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
frame.pack(); 
frame.setVisible(true); 
} 
} 
