Swing/HideComboArrowButton のバックアップ差分(No.10)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/HideComboArrowButton へ行く。
- 1 (2009-11-11 (水) 19:40:37)
- 2 (2012-08-07 (火) 16:10:26)
- 3 (2013-01-13 (日) 19:24:19)
- 4 (2013-06-05 (水) 14:40:31)
- 5 (2013-09-01 (日) 01:37:56)
- 6 (2014-11-01 (土) 00:46:09)
- 7 (2014-11-25 (火) 03:03:31)
- 8 (2015-03-07 (土) 15:38:43)
- 9 (2017-02-03 (金) 16:05:32)
- 10 (2017-11-02 (木) 15:34:40)
- 11 (2017-12-21 (木) 14:29:19)
- 12 (2018-12-14 (金) 19:48:08)
- 13 (2020-11-14 (土) 16:51:32)
- 14 (2022-08-20 (土) 22:15:25)
- 15 (2022-12-02 (金) 12:06:58)
- 追加された行はこの色です。
- 削除された行はこの色です。
--- category: swing folder: HideComboArrowButton title: JComboBoxのArrowButtonを隠す tags: [JComboBox, ArrowButton, UIManager] author: aterai pubdate: 2008-12-22T13:06:25+09:00 description: ArrowButtonを隠して、JComboBoxの表示をJLabel風にします。 image: https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTN0Yp0GRI/AAAAAAAAAbY/WvXw5vm2_LI/s800/HideComboArrowButton.png --- * 概要 [#summary] `ArrowButton`を隠して、`JComboBox`の表示を`JLabel`風にします。 #download(https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTN0Yp0GRI/AAAAAAAAAbY/WvXw5vm2_LI/s800/HideComboArrowButton.png) * サンプルコード [#sourcecode] #code(link){{ JPanel p = new JPanel(new BorderLayout(5, 5)); Object[] items = {"JComboBox 11111:", "JComboBox 222:", "JComboBox 33:"}; UIManager.put("ComboBox.squareButton", Boolean.FALSE); JComboBox comboBox = new JComboBox(items); comboBox.setUI(new BasicComboBoxUI() { @Override protected JButton createArrowButton() { JButton button = new JButton(); //super.createArrowButton(); button.setBorder(BorderFactory.createEmptyBorder()); button.setVisible(false); return button; } }); comboBox.setOpaque(true); comboBox.setBackground(p.getBackground()); comboBox.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2)); comboBox.setFocusable(false); UIManager.put("ComboBox.squareButton", Boolean.TRUE); }} * 解説 [#explanation] 上記のサンプルでは、以下のようにして、`JComboBox`を`JLabel`風に表示しています。 上記のサンプルでは、以下のようにして`JComboBox`の矢印ボタンを非表示に設定しています。 - `UIManager.put("ComboBox.squareButton", Boolean.FALSE);`で、`ArrowButton`の幅をそのまま使用するように変更 - `BasicComboBoxUI#createArrowButton`をオーバーライドして、`ArrowButton`の代わりに幅高さ`0`で`setVisible(false)`なボタンを作成 - `JComboBox`の背景色を親の`JPanel`と同じにする - `JComboBox`がフォーカスを取得しないようにする - `BasicComboBoxUI#createArrowButton`をオーバーライドして、`ArrowButton`の代わりに幅と高さが`0`で`setVisible(false)`なボタンを作成 - `JComboBox`の背景色を親の`JPanel`と同じ色に変更 - `JComboBox`がフォーカスを取得不可になるよう設定 * 参考リンク [#reference] - [https://community.oracle.com/thread/1359216 Swing - Hide JComboBox Arrow?] - [http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6337518 Bug ID: 6337518 Null Arrow Button Throws Exception in BasicComboBoxUI] * コメント [#comment] #comment #comment