我在獲取 flatlaf 主題中包含的某些值時遇到了一點問題,我給你舉個例子,“@accentBase2Color”的值回傳 null,我不明白為什么,因為主題包含這個鍵(sry for我的英語不好)。
public static void main(String[] args) throws UnsupportedLookAndFeelException {
UIManager.setLookAndFeel(flatLaf);
Color obj = UIManager.getColor("@accentBaseColor");
System.out.println(obj);
}
uj5u.com熱心網友回復:
@accentBase2Color 僅存在于主題檔案中,因此無法從 UIManager 訪問。您可以使用以下代碼訪問每個 UIManager 鍵/顏色屬性,例如,我認為您要查找的顏色存盤在“Object.pink”或“Object.purple”中。
private static void DrawGizmos(String search) {
UIDefaults defaults = UIManager.getDefaults();
System.out.println(defaults.size() " properties defined !");
Map<String, Color> mapString = new HashMap<>();
for (Enumeration<Object> e = defaults.keys(); e.hasMoreElements();) {
Object key = e.nextElement();
if (key.toString().toUpperCase().contains(search.toUpperCase())) {
if (defaults.get(key) instanceof Color) {
mapString.put(key.toString(), (Color) defaults.get(key));
}
}
}
JPanel jPanel = new JPanel();
for (Map.Entry<String, Color> entry:mapString.entrySet()){
JButton btn = new JButton(entry.getKey() " |-| " entry.getValue().toString());
btn.setBackground(entry.getValue());
jPanel.add(btn);
}
JFrame p = new JFrame("UIManager");
jPanel.setLayout(new VerticalLayout());
p.add(new JScrollPane(jPanel));
p.setVisible(true);
p.setSize(400, 500);
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(new FlatCarbonIJTheme());
} catch (UnsupportedLookAndFeelException e) {
throw new RuntimeException(e);
}
DrawGizmos("Objects");
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/511838.html
標籤:爪哇摇摆平板电脑
下一篇:在指定時間后自動更新JPanel
