Swing的UIManager.getColor()
键有一个列表吗?我似乎无法在网上找到它,只是偶尔引用像"Panel.background"
和"Table.selectionBackground"
这样的字符串。Swing UIManager.getColor()键
回答
我一直在寻找同样的事情,并找到了这个网页,以及所有这些特性对http://nadeausoftware.com/node/85了很好的概述。
他们是一种外观和感觉实施依赖。在BasicLookAndFeel.java
查看基本密钥。不要指望所有PL & F的行为相同,甚至在版本之间保持不变。
我不认为有一个定义的标准的一组密钥。但你可以尝试这段代码可以列出当前按字母顺序排列的可用的:
List<String> colors = new ArrayList<String>();
for (Map.Entry<Object, Object> entry : UIManager.getDefaults().entrySet()) {
if (entry.getValue() instanceof Color) {
colors.add((String) entry.getKey()); // all the keys are strings
}
}
Collections.sort(colors);
for (String name : colors)
System.out.println(name);
这就产生太长,这里再现列表。
目前(jdk1.8.0_45),用于`systemLookAndFeelClassName = com。 sun.java.swing.plaf.windows.WindowsLookAndFeel`,类不是`java.awt.Color`,而是`com.sun.java.swing.plaf.windows.DesktopProperty`,不幸的是,instanceof检查失败。 – 2015-06-24 19:51:39
@ mmyers让我受到启发。这里有一个简短的程序,列出可排序表中的UIManager默认值。
package com.example.test.gui;
import java.awt.Color;
import java.awt.Component;
import java.util.Map;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableCellRenderer;
import ca.odell.glazedlists.BasicEventList;
import ca.odell.glazedlists.EventList;
import ca.odell.glazedlists.GlazedLists;
import ca.odell.glazedlists.SortedList;
import ca.odell.glazedlists.gui.AbstractTableComparatorChooser;
import ca.odell.glazedlists.gui.TableFormat;
import ca.odell.glazedlists.swing.EventTableModel;
import ca.odell.glazedlists.swing.TableComparatorChooser;
public class UIManagerDefaultsViewer {
public static class UIEntry
{
final private String key;
final private Object value;
UIEntry(Map.Entry<Object,Object> e)
{
this.key = e.getKey().toString();
this.value = e.getValue();
}
public String getKey() {
return key;
}
public Object getValue() {
return value;
}
public Class getValueClass() {
if (value == null)
return null; // ?!?!?!
return value.getClass();
}
public String getClassName() {
// doesn't handle arrays properly
if (value == null)
return "";
return value.getClass().getName();
}
}
public static class UIEntryRenderer extends DefaultTableCellRenderer
{
Color[] defaults = new Color[4];
public UIEntryRenderer()
{
super();
defaults[0] = UIManager.getColor("Table.background");
defaults[1] = UIManager.getColor("Table.selectionBackground");
defaults[2] = UIManager.getColor("Table.foreground");
defaults[3] = UIManager.getColor("Table.selectionForeground");
}
public void setDefaultColors(Component cell, boolean isSelected)
{
cell.setBackground(defaults[isSelected ? 1 : 0]);
cell.setForeground(defaults[isSelected ? 3 : 2]);
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column)
{
Component cell = super.getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, column);
if (table.convertColumnIndexToModel(column) == 1) // the value column
{
final EventTableModel<UIEntry> tableModel =
(EventTableModel<UIEntry>) table.getModel();
UIEntry e = tableModel.getElementAt(row);
JLabel l = (JLabel)cell;
if (value instanceof Color)
{
Color c = (Color)value;
cell.setBackground(c);
cell.setForeground(
c.getRed()+c.getGreen()+c.getBlue() >= 128*3
? Color.black : Color.white);
// choose either black or white depending on brightness
l.setText(String.format("Color 0x%08x (%d,%d,%d alpha=%d)",
c.getRGB(), c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()));
return cell;
}
else if (e.getKey().endsWith("ont"))
// possible font, not always ".font"
{
// fonts are weird, for some reason the value returned
// in the entry set of UIManager.getDefaults()
// is not the same type as the value "v" below
Object v = UIManager.get(e.getKey());
if (v instanceof javax.swing.plaf.FontUIResource)
{
javax.swing.plaf.FontUIResource font =
(javax.swing.plaf.FontUIResource)v;
l.setText("Font "+font.getFontName()+" "+font.getSize());
}
}
}
setDefaultColors(cell, isSelected);
return cell;
}
}
public static void main(String[] args) {
final EventList<UIEntry> uiEntryList =
GlazedLists.threadSafeList(new BasicEventList<UIEntry>());
for (Map.Entry<Object,Object> key : UIManager.getDefaults().entrySet())
{
uiEntryList.add(new UIEntry(key));
}
final SortedList<UIEntry> sortedUIEntryList = new SortedList<UIEntry>(uiEntryList, null);
// build a JTable
String[] propertyNames = new String[] {"key","value","className"};
String[] columnLabels = new String[] {"Key", "Value", "Class"};
TableFormat<UIEntry> tf = GlazedLists.tableFormat(UIEntry.class, propertyNames, columnLabels);
EventTableModel<UIEntry> etm = new EventTableModel<UIEntry>(sortedUIEntryList, tf);
JTable t = new JTable(etm);
TableComparatorChooser<UIEntry> tcc = TableComparatorChooser.install(t,
sortedUIEntryList, AbstractTableComparatorChooser.SINGLE_COLUMN,
tf);
sortedUIEntryList.setComparator(tcc.getComparatorsForColumn(0).get(0));
// default to sort by the key
t.setDefaultRenderer(Object.class, new UIEntryRenderer());
JFrame f = new JFrame("UI Manager Defaults Viewer");
// show the frame
f.add(new JScrollPane(t));
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
在NetBeans GUI构建器中,编辑颜色时,您可以从列表中选择所有列表(不包含实际颜色值)。这实际上是我认为有可能列出它们的想法。不过,表格更好。 – 2009-04-09 14:22:20
这个节目是我见过的可视化UIManager的值最好的(如字体,颜色,边框):http://tips4java.wordpress.com/2008/10/09/uimanager-defaults/
它缺乏的搜索,但它可以通过组件或值类型,这是非常伟大的过滤器。
- 1. UIManager.getColor返回null有时
- 2. 右键单击Swing
- 3. Swing屏幕键盘
- 4. Java Swing的键值对JList
- 5. 在Swing中制作F1快捷键
- 6. 在java中使用swing创建热键
- 7. 为java swing表单创建热键
- 8. Java Swing中的按键问题
- 9. Scala Swing GUI不响应按下的键
- 10. Java/Swing:关键听众的问题
- 11. Java Swing中的键盘“保持”事件?
- 12. Java Swing如何重置JTextArea
- 13. java swing键绑定 - 丢失释放的键的操作
- 14. JPanel中的java swing快捷键/键绑定
- 15. 如何使用Java Swing重新映射键盘键?
- 16. Java Swing - KeyListener
- 17. java swing复选框java swing
- 18. java swing swing与多线程
- 19. Keybindings not working - swing
- 20. java swing - paint jcomponent
- 21. BorderLayout Swing
- 22. 在Swing
- 23. Swing addWindowFocusListener
- 24. 与Swing
- 25. java swing-转义键事件导致classCastException的外观
- 26. 使用swing在java中创建JButton的热键
- 27. Swing中的可链接键盘处理程序
- 28. Java/AWT/Swing:如何区分按下的输入或返回键
- 29. 如何忽略Swing中的按键事件?
- 30. 非GPL带键盘导航的Swing日期选择器?
我发现一个方便的Java Web Start应用程序应该有所帮助:http://tips4java.wordpress.com/2008/10/09/uimanager-defaults/ – 2012-01-05 19:24:53