`

UIManager

阅读更多
关于 UIManager.getColor(Object key) 的使用 
Posted on 2004年12月16日 20:06 
   在做界面主题的变换的时候,我们经常要对系统的一些颜色进行默认设置,而获得在主题变换时,组件的颜色自动转换到该主题相应的颜色的一种效果。UIManager在这方面是一种很关键的应用。
   在UIManager(Java 2 Platform SE v1.4.2)的方法public static Color getColor(Object key)注释中,key是一个指定颜色的对象,而具体包括哪些可以使用则不得知。
    我们阅读jdk的源代码可以知道,运行UIManager.getColor的时候,其实是通过运行[return getDefaults().getColor(key); ]这段代码获得颜色的。而getDefaults() 返回了一个UIDefaults。再看看UIDefaults,它是通过[Object value = get(key);]来获得颜色的对象,通过它调用的最低层的代码,我们知道,这些对象列表是保存在一个Hashtable(UIDefaults继承了Hashtable)中的,而Hashtable提供了一个接口[public synchronized Enumeration keys()]来获得这些值。
    因此,我们可以通过一段简单的代码来获得可以使用的颜色的关键对象。

import java.awt.*;
import java.util.*;
import javax.swing.*;

public class UIManagerColorTest {
  public UIManagerColorTest() {
  }

  public static void main(String[] args) {

    UIDefaults uiDefaults = UIManager.getDefaults();
    Enumeration enum = uiDefaults.keys();
    while (enum.hasMoreElements()) {
      Object key = enum.nextElement();
      Object val = uiDefaults.get(key);
 
      //如果是颜色对象,则打印
      try {
        Color color = (Color) val;
        System.out.println("[" + key.toString() + "]");
      }
      catch (ClassCastException cce) {
      }
    }

  }
}
以下是运行程序后的结果:
[DesktopIcon.background]
[windowText]
[activeCaptionBorder]
[InternalFrame.borderColor]
[ScrollBar.highlight]
[ComboBox.disabledBackground]
[Tree.selectionBackground]
[FormattedTextField.inactiveBackground]
[InternalFrame.inactiveTitleBackground]
[Table.selectionForeground]
[Label.foreground]
[ToggleButton.highlight]
[Button.background]
[FormattedTextField.caretForeground]
[RadioButtonMenuItem.selectionForeground]
[ToggleButton.shadow]
[OptionPane.errorDialog.titlePane.shadow]
[EditorPane.background]
[RadioButtonMenuItem.foreground]
[RadioButton.light]
[ToggleButton.focus]
[OptionPane.warningDialog.titlePane.background]
[TextArea.caretForeground]
[Button.highlight]
[CheckBox.focus]
[Separator.foreground]
[TabbedPane.light]
[Tree.selectionBorderColor]
[inactiveCaptionText]
[ToolTip.backgroundInactive]
[PasswordField.caretForeground]
[EditorPane.inactiveForeground]
[ToolTip.foreground]
[ToolBar.dockingBackground]
[ToggleButton.disabledText]
[ToggleButton.background]
[Slider.focus]
[ToolBar.floatingForeground]
[TabbedPane.background]
[ComboBox.foreground]
[ScrollBar.shadow]
[RadioButtonMenuItem.acceleratorForeground]
[InternalFrame.borderDarkShadow]
[PopupMenu.background]
[controlLtHighlight]
[CheckBoxMenuItem.background]
[TextPane.foreground]
[FormattedTextField.background]
[Viewport.background]
[TextField.light]
[MenuItem.background]
[TabbedPane.tabAreaBackground]
[Button.focus]
[inactiveCaptionBorder]
[CheckBoxMenuItem.selectionBackground]
[textInactiveText]
[OptionPane.errorDialog.titlePane.background]
[TextField.inactiveBackground]
[Tree.selectionForeground]
[Menu.selectionBackground]
[Tree.background]
[InternalFrame.inactiveTitleForeground]
[control]
[SplitPane.background]
[textText]
[RadioButton.foreground]
[menu]
[EditorPane.foreground]
[SplitPane.shadow]
[OptionPane.warningDialog.titlePane.foreground]
[TabbedPane.selectHighlight]
[RadioButton.shadow]
[Menu.disabledForeground]
[ToggleButton.light]
[windowBorder]
[OptionPane.questionDialog.border.background]
[ToggleButton.foreground]
[Panel.background]
[TabbedPane.foreground]
[RadioButtonMenuItem.background]
[Table.gridColor]
[ScrollBar.foreground]
[TextPane.caretForeground]
[ToolBar.shadow]
[ToggleButton.select]
[Spinner.foreground]
[FormattedTextField.foreground]
[Viewport.foreground]
[RadioButton.darkShadow]
[infoText]
[MenuItem.acceleratorSelectionForeground]
[MenuItem.foreground]
[MenuBar.background]
[OptionPane.errorDialog.titlePane.foreground]
[Button.light]
[menuText]
[ToggleButton.darkShadow]
[TextPane.background]
[MenuItem.acceleratorForeground]
[TabbedPane.darkShadow]
[CheckBox.background]
[TextField.highlight]
[TextArea.selectionBackground]
[Panel.foreground]
[OptionPane.questionDialog.titlePane.background]
[RadioButton.background]
[TextArea.inactiveForeground]
[Slider.shadow]
[textHighlightText]
[SplitPane.darkShadow]
[RadioButton.select]
[PasswordField.foreground]
[ScrollBar.thumb]
[activeCaptionText]
[MenuBar.foreground]
[OptionPane.warningDialog.titlePane.shadow]
[ScrollBar.background]
[Menu.foreground]
[CheckBox.disabledText]
[Spinner.background]
[TextPane.selectionForeground]
[ComboBox.selectionBackground]
[ScrollBar.track]
[CheckBox.foreground]
[TextField.caretForeground]
[ScrollBar.thumbDarkShadow]
[List.selectionBackground]
[OptionPane.messageForeground]
[TextPane.inactiveForeground]
[Button.shadow]
[Menu.acceleratorForeground]
[TextArea.selectionForeground]
[Menu.acceleratorSelectionForeground]
[TextField.foreground]
[textHighlight]
[OptionPane.questionDialog.titlePane.foreground]
[TabbedPane.selected]
[controlShadow]
[MenuItem.disabledForeground]
[MenuItem.selectionForeground]
[MenuItem.checkIcon]
[ColorChooser.swatchesDefaultRecentColor]
[ToolBar.highlight]
[OptionPane.foreground]
[controlText]
[TextArea.background]
[Tree.line]
[CheckBoxMenuItem.disabledForeground]
[Separator.highlight]
[TextField.darkShadow]
[Tree.textForeground]
[ComboBox.selectionForeground]
[ToolBar.foreground]
[PasswordField.selectionBackground]
[Label.disabledShadow]
[FormattedTextField.selectionBackground]
[PasswordField.background]
[ProgressBar.background]
[List.selectionForeground]
[Checkbox.select]
[MenuBar.highlight]
[ComboBox.buttonShadow]
[Menu.background]
[info]
[TextPane.selectionBackground]
[PasswordField.inactiveBackground]
[controlHighlight]
[ScrollBar.darkShadow]
[SplitPane.highlight]
[TableHeader.background]
[InternalFrame.activeTitleForeground]
[TextArea.foreground]
[TextField.background]
[InternalFrame.borderShadow]
[Button.select]
[MenuItem.selectionBackground]
[TextField.shadow]
[ScrollBar.thumbShadow]
[ScrollBar.thumbHighlight]
[scrollbar]
[window]
[PasswordField.selectionForeground]
[TextField.selectionForeground]
[FormattedTextField.selectionForeground]
[OptionPane.background]
[Separator.shadow]
[ComboBox.buttonBackground]
[Table.focusCellBackground]
[ColorChooser.background]
[ProgressBar.foreground]
[Table.foreground]
[Tree.hash]
[RadioButtonMenuItem.acceleratorSelectionForeground]
[TitledBorder.titleColor]
[inactiveCaption]
[Slider.highlight]
[Tree.textBackground]
[EditorPane.selectionBackground]
[ProgressBar.selectionForeground]
[Button.disabledText]
[ToolBar.background]
[Label.disabledForeground]
[PasswordField.inactiveForeground]
[TabbedPane.shadow]
[TabbedPane.highlight]
[List.background]
[InternalFrame.borderHighlight]
[TableHeader.foreground]
[Slider.background]
[RadioButtonMenuItem.disabledForeground]
[controlDkShadow]
[OptionPane.questionDialog.titlePane.shadow]
[DesktopIcon.foreground]
[InternalFrame.activeTitleBackground]
[CheckBoxMenuItem.acceleratorForeground]
[Desktop.background]
[Table.focusCellForeground]
[ColorChooser.foreground]
[RadioButton.highlight]
[Menu.checkIcon]
[OptionPane.errorDialog.border.background]
[ComboBox.buttonHighlight]
[ToolBar.light]
[EditorPane.selectionForeground]
[ComboBox.disabledForeground]
[ScrollPane.background]
[FormattedTextField.inactiveForeground]
[CheckBoxMenuItem.acceleratorSelectionForeground]
[activeCaption]
[TextField.selectionBackground]
[Button.foreground]
[Table.background]
[RadioButton.disabledText]
[MenuBar.shadow]
[List.foreground]
[text]
[desktop]
[ComboBox.buttonDarkShadow]
[ProgressBar.selectionBackground]
[Slider.foreground]
[ToolBar.dockingForeground]
[ToolTip.foregroundInactive]
[RadioButton.focus]
[Table.selectionBackground]
[ScrollBar.trackHighlight]
[Label.background]
[OptionPane.warningDialog.border.background]
[TabbedPane.focus]
[RadioButtonMenuItem.selectionBackground]
[ToolBar.darkShadow]
[Separator.background]
[PopupMenu.foreground]
[CheckBoxMenuItem.foreground]
[EditorPane.caretForeground]
[Button.darkShadow]
[ToolTip.background]
[CheckBoxMenuItem.selectionForeground]
[ToolBar.floatingBackground]
[ComboBox.background]
[TextField.inactiveForeground]
[ScrollPane.foreground]
[Menu.selectionForeground]
[InternalFrame.borderLight]
[Tree.foreground]
 同样的,我们可以修改上面的源代码以获得其他UIManager的其他获得特性的关键词。
 
参考文档:http://bdn.borland.com/article/0,1410,29991,00.html


 
分享到:
评论

相关推荐

    swing UIManager皮肤

    swing UIManager皮肤 swing UIManager皮肤 swing UIManager皮肤 swing UIManager皮肤 swing UIManager皮肤

    UIManager_Unity3DUI框架_

    UI框架开发:通过Json解析各个面板文件,搭建一套控制面板层级显示与隐藏的UI框架

    UImanager皮肤包

    不光包含了皮肤包,还有介绍JBuider 2006怎样倒入皮肤包,很是详细,代码也有。

    UIManager.class

    UIManager.class

    UIManager.rar_UIManag_uimanager_visual c

    小游戏界面管理 UI 适合初学者学习使用

    UIManager.cs

    UIManager.cs

    CocosCreator开源游戏开发框架

    包含GameMain、AudioManager、ConfigManager、GameController、GameDataManager、ListenerManager、TimeManager、UIManager、ShaderManager、MathExtension、StringExtension、UIHelp、LogWrap、gulpfile自动化处理...

    Java Gui 皮肤包 

    Java Gui 皮肤包 8个 Java Gui 皮肤包  UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel"); 一般引入jar包中已LookAndFeel结尾的类就行了

    JTatoo Swing LookAndFeel 外观

    有以下十种风格可以设置: javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.smart.SmartLookAndFeel"); javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel"); ...

    DuiLib界面库编程总结

    国内首个开源的Directui界面库,开放,共享,惠众,共赢,遵循bsd协议,可以免费用于商业项目,目前支持Windows 32 、Window CE、Mobile等平台。 著名界面库duilib的升级版... ......\.......\.....\....\UIManager.h

    java GUI 美化包!!!1

    UIManager.setLookAndFeel(new org.jvnet.substance.skin.SubstanceModerateLookAndFeel()) ; } catch (UnsupportedLookAndFeelException e) { e.printStackTrace(); } FontUIResource f = new ...

    Java美化包3!!!!

    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); Font font = new Font("SimSun", 0, 12); Enumeration keys = UIManager.getLookAndFeelDefaults().keys(); while (keys....

    Java制作多种风格的窗口界面一例.rar

      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); //设置界面样式  }  else if (type.equals("Motif")) {  UIManager.setLookAndFeel(...

    手机管理系统源代码(虽然简单仅供大家参考)

    import javax.swing.UIManager; import javax.swing.border.EtchedBorder; //import com.qhit.LandAppend; //import com.qhit.PasswordAmend; import Kehuxinxi.Kehumain; import Shouhoumain.Main; import ...

    期末数据库课程设计基于Java+MySQL+JDBC+JavaSwing的简易图书进销管理系统源码+数据库

    期末数据库课程设计基于Java+MySQL+JDBC+JavaSwing的简易图书进销管理... UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { // TODO: handle exception }

    java联网版五指棋 界面漂亮 可以边下边聊天 适合初学者

    里面有注释哦, 要先打开服务器端,再开客户端。

    Java的小技巧(很小的)

    2,Swing常常显示中文乱码,对于使用了UIManager.getSystemLookAndFeelClassName() 的程序,可以采用如下方法; 解决:在UIManager.getSystemLookAndFeelClassName() 下方添加代码 java.util.Enumeration enum = ...

    贝叶斯主观推理算法java源码

    package subjectivebayes;... UIManager.setLookAndFeel(UIManager. getSystemLookAndFeelClassName()); } catch (Exception exception) { exception.printStackTrace(); } new MyApp(); } }); } }

    java弹窗美化Demo

    UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("宋体", Font.ITALIC, 13))); // 设置文本显示效果 UIManager.put("OptionPane.messageFont", new FontUIResource...

    项目源码-java酒店管理系统

    import javax.swing.UIManager; import com.mwq.frame.LandFrame; public class DrinkeryManage { public DrinkeryManage() { // Center the window Toolkit toolkit = Toolkit.getDefaultToolkit(); ...

Global site tag (gtag.js) - Google Analytics