Swing/AuxiliaryLookAndFeel のバックアップ差分(No.6)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/AuxiliaryLookAndFeel へ行く。
- 1 (2012-04-09 (月) 14:26:00)
- 2 (2012-12-12 (水) 19:10:43)
- 3 (2014-11-01 (土) 00:46:09)
- 4 (2014-12-11 (木) 15:00:56)
- 5 (2015-05-21 (木) 19:40:31)
- 6 (2016-06-14 (火) 20:09:15)
- 7 (2016-06-30 (木) 18:52:34)
- 8 (2017-04-04 (火) 14:13:45)
- 9 (2017-09-24 (日) 15:22:21)
- 10 (2017-11-02 (木) 15:34:40)
- 11 (2019-03-15 (金) 17:17:38)
- 12 (2019-05-22 (水) 19:35:38)
- 13 (2021-01-01 (金) 17:25:01)
- 14 (2022-08-20 (土) 22:15:25)
- 15 (2022-10-21 (金) 11:54:59)
- 追加された行はこの色です。
- 削除された行はこの色です。
--- title: AuxiliaryLookAndFeelを追加する tags: [LookAndFeel, UIManager, JComboBox] author: aterai pubdate: 2012-04-09T14:26:00+09:00 description: AuxiliaryLookAndFeelを追加して、WindowsLookAndFeelの場合の動作を変更します。 --- * 概要 [#ua0f3e60] `AuxiliaryLookAndFeel`を追加して、`WindowsLookAndFeel`の場合の動作を変更します。 #download(https://lh4.googleusercontent.com/-SxIyCqWRFhk/T4JxXw96NSI/AAAAAAAABLQ/gM_5mjZPn1o/s800/AuxiliaryLookAndFeel.png) * サンプルコード [#lc13bf97] #code(link){{ JCheckBox check = (JCheckBox) e.getSource(); String lnf = UIManager.getLookAndFeel().getName(); if (check.isSelected() && lnf.contains("Windows")) { UIManager.addAuxiliaryLookAndFeel(auxLookAndFeel); } else { UIManager.removeAuxiliaryLookAndFeel(auxLookAndFeel); } SwingUtilities.updateComponentTreeUI(MainPanel.this); SwingUtilities.updateComponentTreeUI(getRootPane()); }} * 解説 [#r33184aa] `WindowsLookAndFeel`の場合、`JComboBox`のドロップダウンリストで右クリックを無効にするような`ComboBoxUI`を`UIManager.addAuxiliaryLookAndFeel(...)`を使って追加しています。 - [[JComboBoxのドロップダウンリストで右クリックを無効化>Swing/DisableRightClick]] #code{{ public class AuxiliaryWindowsComboBoxUI extends WindowsComboBoxUI { public static ComponentUI createUI(JComponent c) { return new AuxiliaryWindowsComboBoxUI(); } @Override protected ComboPopup createPopup() { return new BasicComboPopup2(comboBox); } @Override public void addEditor() { removeEditor(); ComboBoxEditor cbe = comboBox.getEditor(); if (cbe != null) { editor = cbe.getEditorComponent(); if (editor != null) { configureEditor(); comboBox.add(editor); if (comboBox.isFocusOwner()) { editor.requestFocusInWindow(); } } } } //Override all UI-specific methods your UI classes inherit. @Override public void removeEditor() {} @Override protected void configureEditor() {} @Override protected void unconfigureEditor() {} @Override public void update(Graphics g, JComponent c) {} @Override public void paint(Graphics g, JComponent c) {} //... }} - 注 -- `LookAndFeel`を`Nimbus`にすると`ClassCastException`が発生する --- [http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6631956 Bug ID: 6631956 Nimbus: ClassCastException when running with MultiLookAndFeel] -- `UIManager.addPropertyChangeListener(new PropertyChangeListener() {...});`を追加して、`WindowsLookAndFeel`以外の場合は、`UIManager.removeAuxiliaryLookAndFeel(auxLookAndFeel);` -- 編集可能な`JComboBox`の場合、`NullPointerException`が発生する --- `WindowsComboBoxUI#addEditor()`をオーバーライド * 参考リンク [#ybc6bf3b] - [http://docs.oracle.com/javase/7/docs/api/javax/swing/plaf/multi/doc-files/multi_tsc.html Using the Multiplexing Look and Feel] * コメント [#nd54a516] #comment - いつか修正: `AuxiliaryLookAndFeel`の作成方法、使い方などをいろいろ間違えているような気がする…。 -- &user(aterai); &new{2012-04-09 (月) 14:41:52}; #comment