我下载了一个OfficeLnFs_2.4.jar包,就是一个XP的JAVA界面包
try {
    UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");    } catch (Exception e) {
    System.err.println("Oops!  Something went wrong!");
}
这样的画,没有任何变化,如果我加如下条语句:
    SwingUtilities.updateComponentTreeUI(frame);
    SwingUtilities.updateComponentTreeUI(button);
    SwingUtilities.updateComponentTreeUI(txt);
我的程序中的 frame,button,txt才会变成新的界面,
我请问如果一个程序中,我有N多控件,那么有没有什么办法,可以一句代码代替    SwingUtilities.updateComponentTreeUI(); 这个方法把程序内所有控件都改变外观呢??谢谢!!!!

解决方案 »

  1.   

    UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
    这句话放在你初始化其他组件之前
      

  2.   

    或者说在主窗口显示(visable)之前调用,但不要在创建主窗口的过程中调用.
      

  3.   

    可以参考 j2sdk\demo\jfc\Metalworks 的源代码。主要是在在程序运行最开始时候添加下面的listener。(其他的不大记得了,很久前的代码了)。
    对于普通的 lnf 这个可以很好工作,但是对于类似 looks 或者更复杂的 lnf,会部分组件无法更新。
    在jgoodies的付费版本中,很好地解决了这些问题,可以很容易在运行时替换不同的风格。
    //添加界面主题更换事件
    UIManager.addPropertyChangeListener(new UISwitchListener((JComponent) getRootPane()));public class UISwitchListener
        implements PropertyChangeListener {
      JComponent componentToSwitch;  public UISwitchListener(JComponent c) {
        componentToSwitch = c;
      }  public void propertyChange(PropertyChangeEvent e) {
        String name = e.getPropertyName();
        if (name.equals("lookAndFeel")) {
          SwingUtilities.updateComponentTreeUI(componentToSwitch);
          componentToSwitch.invalidate();
          componentToSwitch.validate();
          componentToSwitch.repaint();
        }
      }
    }