UIManager.getColor()
Swingのキーのどこかにリストがありますか?私はそれをオンラインで見つけられないようで、ちょうど"Panel.background"
と"Table.selectionBackground"
のような文字列への参照です。Swing UIManager.getColor()keys
答えて
私は同じことを探していると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);
これは、ここに再現するにはあまりにも長いリストを生成します。
現在、(system_lookAndFeelClassName = comの)jdk1.8.0_45です。 sun.java.swing.plaf.windows.WindowsLookAndFeel'の場合、クラスは 'java.awt.Color'ではなく' com.sun.java.swing.plaf.windows.DesktopProperty'であり、残念なことにinstanceofのチェックに失敗しました。 –
@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ビルダーでは、色を編集するときに、実際の色の値を除いて、リストされたすべてのものを含むJListから選択できます。それは実際に私がそれらをリストすることが可能かもしれないという考えを得たところです。しかし、テーブルははるかにいいです。 –
このプログラムは、私がUIManagerの値を可視化するために見た中で最高である(例えばフォント、色、境界線):http://tips4java.wordpress.com/2008/10/09/uimanager-defaults/
それは検索を欠いたが、それはコンポーネントまたはかなり大きな値のタイプによってフィルタリングすることができます。
- 1. Java Swing ActionMap keys
- 2. json keys as numbers
- 3. gpg --export-secret-keys
- 4. JTable enter keys
- 5. tmux send-keysシンタックス
- 6. Javascript onChange arrow keys
- 7. Hibernate、Spring、foreign keys
- 8. Python Dictionary with 2 Keys?
- 9. Django ORM - select_relatedとorder_by foreign keys
- 10. Python Send Keys関数Selenium
- 11. SCAN対RedisのKEYSパフォーマンス
- 12. 連想配列 ".keys()" bashで
- 13. FOREIGN KEYSとのMySQL多対多関係
- 14. Pythonのdir(...)とvars(...).keys()の違いは?
- 15. ボーダーレイアウトSwing
- 16. なぜUIManager.getDefaults().keySet()はUIManager.getDefaults()。keys()と異なる値を返しますか?
- 17. Swingのバーチャルリストボックス
- 18. Java/Swingのセクションリスト?
- 19. Java Swing 2D animation
- 20. QStackedWidget for Java Swing
- 21. Java swing keybinding
- 22. Java Swing JXDatePicker
- 23. java swing single application
- 24. Java Swing OSXウィンドウメニューチェックマーク
- 25. SwingのStackPanel
- 26. SwingカスタムGUIコンポーネント
- 27. SWING用シフトカレンダー
- 28. java swing - paint jcomponent
- 29. Log4J Swing Appender
- 30. Java Swingのキーストローク
便利なJava Web Start Appが見つかりました:http://tips4java.wordpress.com/2008/10/09/uimanager-defaults/ –