C'è una lista da qualche parte dei tasti UIManager.getColor()
per Swing? Non riesco a trovarlo online, solo riferimenti occasionali a stringhe come "Panel.background"
e "Table.selectionBackground"
.Tasti Swing UIManager.getColor()
risposta
che stavo cercando la stessa cosa e ho trovato questa pagina così come un'eccellente panoramica di tutte queste proprietà in http://nadeausoftware.com/node/85.
Sono di tipo Look and Feel dipendenti dall'implementazione. Cerca in BasicLookAndFeel.java
per i tasti di base. Non aspettarti che tutti i PL & F si comportino allo stesso modo, o addirittura rimangano gli stessi tra le versioni.
Non penso che ci sia un insieme standard definito di chiavi. Ma si potrebbe provare questo pezzo di codice per elencare quelle attualmente disponibili in ordine alfabetico:
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);
Questo produce un elenco troppo lungo per riprodurre qui.
Attualmente (jdk1.8.0_45), per 'systemLookAndFeelClassName = com. sun.java.swing.plaf.windows.WindowsLookAndFeel', le classi non sono 'java.awt.Color', ma' com.sun.java.swing.plaf.windows.DesktopProperty', ma sfortunatamente fallisce il controllo instanceof. –
@mmyers mi ha ispirato. Ecco un breve programma per elencare i valori predefiniti di UIManager in una tabella ordinabile.
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);
}
}
Nel builder della GUI NetBeans, quando si modifica un colore, è possibile scegliere da una JList con tutti questi elencati (senza i valori di colore effettivi). In realtà è lì che ho avuto l'idea che sarebbe stato possibile elencarli. Un tavolo è molto più bello, però. –
Questo programma è il migliore che ho visto per la visualizzazione dei valori UIManager (ad esempio caratteri, colori, Borders): http://tips4java.wordpress.com/2008/10/09/uimanager-defaults/
Manca di ricerca, ma può filtrare per componente o tipo di valore, che è abbastanza grande .
- 1. Progetti Maven2 & Swing: Build & run swing application
- 2. swing stelle
- 3. Hibernate + Swing
- 4. Rotate a Swing JLabel
- 5. Swing - Etichetta di aggiornamento
- 6. Java Swing Text Editor
- 7. Layout swing Java
- 8. Swing JTextPane in javafx
- 9. Java Swing FlowLayout Alignments
- 10. Log4J Swing Appender
- 11. Fisarmonica per swing?
- 12. Principiante a Swing
- 13. Java Swing JMenu Mnemonic
- 14. Java Swing Timer
- 15. swing HTML drawString
- 16. Java's Swing Threading
- 17. java swing background image
- 18. Java Swing ActionMap chiavi
- 19. Windows centrale Swing
- 20. Layout variabile in Swing
- 21. Java Swing JTextField inserto
- 22. Corrupted Java Swing Window
- 23. CSS Styling con swing
- 24. Rendering html nell'applicazione Swing
- 25. FlowLayout in Swing
- 26. Java Swing Caricamento Animazione
- 27. Compatibilità swing JavaFX 8
- 28. Confronta SWT con SWING
- 29. Zoom nell'applicazione Java Swing
- 30. Windows Swing trasparente
Ho trovato una pratica app di avvio Web Java che dovrebbe aiutare: http://tips4java.wordpress.com/2008/10/09/uimanager-defaults/ –