Swing支持可插拔Look-n-Feel's。當您在運行時更改L & F時,您需要使用方法updateComponentTreeUI
通知您的所有組件。因爲由於新的L & F可以更改組件大小,Swing必須調用revalidate來重新計算佈局。這裏是方法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();
}
的代碼所以,是的,你可以調用SwingUtilities.updateComponentTreeUI
告知您的GUI約佈局的變化,但它的巨大的開銷(和理論上有一定的副作用)。您的情況下,revalidate
和repaint
的組合更好。