スイングはプラガブル対応Look-n-Feelです。実行時にL & Fを変更する場合は、updateComponentTreeUI
メソッドを使用して、この変更についてすべてのコンポーネントに通知する必要があります。新しいL & Fにより、コンポーネントのサイズを変更することができるため、Swingはrevalidateを呼び出してレイアウトを再計算する必要があります。ここではそうです、あなたはレイアウト変更についてのあなたのGUIを知らせるためにSwingUtilities.updateComponentTreeUI
を呼び出すことができる方法updateComponentTreeUI
/**
* A simple minded look and feel change: ask each node in the tree
* to <code>updateUI()</code> -- that is, to initialize its UI property
* with the current look and feel.
*/
public static void updateComponentTreeUI(Component c) {
updateComponentTreeUI0(c);
c.invalidate();
c.validate();
c.repaint();
}
のコードですが、それは巨大なオーバーヘッドだ(と理論的にはいくつかの副作用を持つことができます)。あなたのケースでは、revalidate
とrepaint
の組み合わせが良いです。