java中设置一个按钮用于改变界面皮肤

点击按钮,即更换界面皮肤,这个按钮因该怎么写事件处理啊?

通过UIManager.setLookAndFeel(String className)设置窗口皮肤,然后调用控件的updateUI方法来应用新的UI。示例代码如下:

myButton.addActionListener(new ActionListener()){
   public void actionPerformed(ActionEvent e){
      updateAllUI(topContainer/*最顶层的容器*/); 
   }  
}

public static void updateAllUI(Component c) {
   if (c == null) return;
   try {
      if (c instanceof JComponent) {
         ((JComponent) c).updateUI();//
      } else {
         c.repaint();
      }
   } catch (Exception e) {
      e.printStackTrace(); 
   }
   if (c instanceof Container) {
      if (c instanceof JMenu) {// 注意菜单的更新与其他不同
         Component[] cs = ((JMenu) c).getMenuComponents();
         for (Component c2 : cs) {
            updateAllUI(c2);
         }
      }
      Component[] cs = ((Container) c).getComponents();
      for (Component c2 : cs) {
         updateAllUI(c2);
      }
   }
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-04-05
function String(object){ //当输入的汇率货单位不是数字的时候,提示输入错误,让其从新输入
 var value =object.value;
 var  oinput = object.id;
 var parent=/^[A-Za-z]+$/;
 var c = value.toUpperCase(); 
 if(value!=""){
  if(parent.test(value))  { 
     if(value!=c||c.length!=3){
  document.getElementById(oinput).style.backgroundColor="#FF0000";
  alert("只能输入3位英文大字母!");  
  document.getElementById(oinput).value="";
  return;
     }else{
document.getElementById(oinput).style.backgroundColor="#FFFFFF";
return;
     }
  }else{

  document.getElementById(oinput).style.backgroundColor="#FF0000";
  alert("只能输入3位英文大字母!"); 
  document.getElementById(oinput).value="";
  //document.getElementById(oinput).focus();
  return;
 }
  }else{
  document.getElementById(oinput).style.backgroundColor="#FFFFFF";
  return;
  }
}

你好:这个的话;直接onclick事件就可以了,上面的是设置input的,你可以改成设置background的

追问

你好,可能是我没描述清楚,我是通过UIManager.setLookAndFeel(String className)设置窗口皮肤的,现在我希望可以通过点击界面中的按钮来改变classname,从而改变窗口皮肤,不知道这样做可不可行、 怎么用代码实现。谢谢

相似回答