Swing/WindowTitleBackground のバックアップ差分(No.1)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/WindowTitleBackground へ行く。
- 追加された行はこの色です。
- 削除された行はこの色です。
--- title: JFrameがデフォルトのウィンドウ装飾を使用する場合のタイトルバー背景色を変更 tags: [JFrame, UIManager] author: aterai pubdate: 2014-10-20T00:23:21+09:00 description: JFrameがデフォルトのウィンドウ装飾を使用する場合、タイトルバーの文字色、背景色などを変更します。 --- * 概要 [#y9898e67] `JFrame`がデフォルトのウィンドウ装飾を使用する場合、タイトルバーの文字色、背景色などを変更します。 #download(https://lh5.googleusercontent.com/-kMDDoLGWoSA/VEPUosVXWPI/AAAAAAAACQw/94kmPEN2CT8/s800/WindowTitleBackground.png) * サンプルコード [#s82d93ab] #code(link){{ Object[][] data = { {"activeCaption", UIManager.getColor("activeCaption")}, {"activeCaptionBorder", UIManager.getColor("activeCaptionBorder")}, {"activeCaptionText", UIManager.getColor("activeCaptionText")}, {"control", UIManager.getColor("control")}, {"controlDkShadow", UIManager.getColor("controlDkShadow")}, {"controlHighlight", UIManager.getColor("controlHighlight")}, {"controlLtHighlight", UIManager.getColor("controlLtHighlight")}, {"controlShadow", UIManager.getColor("controlShadow")}, {"controlText", UIManager.getColor("controlText")}, {"desktop", UIManager.getColor("desktop")}, {"inactiveCaption", UIManager.getColor("inactiveCaption")}, {"inactiveCaptionBorder", UIManager.getColor("inactiveCaptionBorder")}, {"inactiveCaptionText", UIManager.getColor("inactiveCaptionText")}, {"info", UIManager.getColor("info")}, {"infoText", UIManager.getColor("infoText")}, {"menu", UIManager.getColor("menu")}, {"menuPressedItemB", UIManager.getColor("menuPressedItemB")}, {"menuPressedItemF", UIManager.getColor("menuPressedItemF")}, {"menuText", UIManager.getColor("menuText")}, {"scrollbar", UIManager.getColor("scrollbar")}, {"text", UIManager.getColor("text")}, {"textHighlight", UIManager.getColor("textHighlight")}, {"textHighlightText", UIManager.getColor("textHighlightText")}, {"textInactiveText", UIManager.getColor("textInactiveText")}, {"textText", UIManager.getColor("textText")}, {"window", UIManager.getColor("window")}, {"windowBorder", UIManager.getColor("windowBorder")}, {"windowText", UIManager.getColor("windowText")} }; DefaultTableModel model = new DefaultTableModel(data, columnNames) { @Override public boolean isCellEditable(int row, int column) { return column == 1; } @Override public Class<?> getColumnClass(int column) { return getValueAt(0, column).getClass(); } }; JTable table = new JTable(model); //... model.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { if(e.getType()==TableModelEvent.UPDATE && e.getColumn() == 1) { int row = e.getFirstRow(); String key = (String) model.getValueAt(row, 0); Color color = (Color) model.getValueAt(row, 1); UIManager.put(key, new ColorUIResource(color)); EventQueue.invokeLater(new Runnable() { @Override public void run() { Window w = SwingUtilities.getWindowAncestor(table); SwingUtilities.updateComponentTreeUI(w); } }); } } }); }} * 解説 [#c020b7f3] 上記のサンプルでは、`JFrame.setDefaultLookAndFeelDecorated(true);`で`JFrame`がデフォルトのウィンドウ装飾を使用するよう設定し、`UIManager.setColor(...)`を使用して、タイトルバーの文字色、背景色を変更するテストを実行することが可能です。 - `activeCaption`: タイトルバーの背景色 - `activeCaptionBorder`: タイトルバーの`Border`の色 - `activeCaptionText`: タイトルバーの文字色 * 参考リンク [#z2201ae3] - [[SystemColorの使用>Swing/SystemColor]] - [http://docs.oracle.com/javase/jp/8/api/java/awt/SystemColor.html SystemColor (Java Platform SE 8)] - [http://docs.oracle.com/javase/jp/8/api/javax/swing/plaf/metal/MetalLookAndFeel.html#initSystemColorDefaults-javax.swing.UIDefaults- MetalLookAndFeel#initSystemColorDefaults (Java Platform SE 8)] - [http://docs.oracle.com/javase/jp/8/api/javax/swing/plaf/metal/MetalTheme.html MetalTheme (Java Platform SE 8)] * コメント [#jcb9ce2d] #comment #comment