The updateComponentTreeUI(...) method (referenced in the Changing the LAF After Startup link provided by trashgod) will only work on a FontUIResource, not a Font. This is only relevant if you need to change the Font multiple times after startup.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.*;
public class ChangeFont extends JFrame
{
private int size = 12;
private JComponent component;
public ChangeFont()
{
JTextArea textArea = new JTextArea();
textArea.append( "updateComponentTreeUI will only work on a FontUIResource\n\n" );
textArea.append( "1) click the FontUIResource button as many times as you want\n" );
textArea.append( "2) after you click the Font button, neither button will work" );
getContentPane().add(textArea, BorderLayout.NORTH);
JButton west = new JButton( "FontUIResource" );
west.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
update( new FontUIResource("monospaced", Font.PLAIN, size) );
}
});
getContentPane().add(west, BorderLayout.WEST );
JButton east = new JButton( "Font" );
east.addActionListener( new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
update( new Font("monospaced", Font.PLAIN, size) );
}
});
getContentPane().add(east, BorderLayout.EAST );
component = new JTable(5, 5);
getContentPane().add(component, BorderLayout.SOUTH);
}
private void update(Font font)
{
UIManager.put("Table.font", font);
UIManager.put("TextArea.font", font);
SwingUtilities.updateComponentTreeUI( this );
size += 2;
pack();
}
public static void main(String[] args)
{
ChangeFont frame = new ChangeFont();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setLocationRelativeTo( null );
frame.setVisible(true);
}
}