更新其他类别的LAF [英] Updating the LAF of a different class
问题描述
在我编写的战舰"程序中,我包括了将程序的外观"更改为SystemDefault,"Metal"(Java默认)或"Motif"(也包括在Java中)的可能性.如果您从JComboBox
中选择所需的LAF(->更改预定义的字符串lookFeel
)并按确认按钮,则会调用UIManager.setLookAndFeel(lookFeel)
,还会调用SwingUtilities.updateComponentTreeUI(this)
和方法updateUI()
并具有以下内容代码:
In a "Battleship" program I wrote, I included the possibility to change the "look and feel" of a program to SystemDefault, "Metal" (Java Default) or "Motif" (also included in Java). If you choose the desired LAF from a JComboBox
(--> changes a predefined String, lookFeel
) and press a confirm button, UIManager.setLookAndFeel(lookFeel)
is called, and also SwingUtilities.updateComponentTreeUI(this)
and the method updateUI()
with the following code:
public static void updateUI() {
//SwingUtilities.updateComponentTreeUI();
SwingUtilities.updateComponentTreeUI(colorChooser);
SwingUtilities.updateComponentTreeUI(shipChooser);
SwingUtilities.updateComponentTreeUI(guide);
SwingUtilities.updateComponentTreeUI(menu_bar);
SwingUtilities.updateComponentTreeUI(menu_general);
SwingUtilities.updateComponentTreeUI(menu_customization);
SwingUtilities.updateComponentTreeUI(lafChooser);
SwingUtilities.updateComponentTreeUI(LAN.lanframe);
SwingUtilities.updateComponentTreeUI(LAN.hostframe);
SwingUtilities.updateComponentTreeUI(LAN.joinframe);
}
但是,此代码不会更新属于不同类的其他窗口.因此,如果我启动主程序,然后更改外观,这些窗口将不会受到影响.那些实际上创建框架的类不是问题,但是我的主程序只是扩展了JFrame(我可能不会再做某事,但是当我开始编写该程序时,我是Java的新手). 现在我的问题是:如何更改此类的LAF? 预先感谢!
However, this code will not update other windows that are part of a different class. Hence, if I launch my main program, and then change the look&feel, these windows won't be affected. Those classes that actually create a frame are not a problem, but my main program just extends JFrame (something I probably wouldn't do again, but I was entirely new to Java when I started writing this program). Now my question is: how can I change the LAF of this class? Thanks in advance!
推荐答案
如果 LookAndFeel
,您可以调用 JRootPane
. UIManager默认值中的此处引用了一个完整的示例.
If the result of getSupportsWindowDecorations()
is true
for a given LookAndFeel
, you can invoke setWindowDecorationStyle()
on the JRootPane
. A complete example is cited here in UIManager Defaults.
这篇关于更新其他类别的LAF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!