Swing/HideComboArrowButton のバックアップ差分(No.5)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - 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)
- 追加された行はこの色です。
- 削除された行はこの色です。
TITLE:JComboBoxのArrowButtonを隠す
#navi(../)
#tags(JComboBox, ArrowButton, UIManager)
RIGHT:Posted by &author(aterai); at 2008-12-22
*JComboBoxのArrowButtonを隠す [#x5fb6947]
``ArrowButton``を隠して、``JComboBox``の表示を``JLabel``風にします。
-&jnlp;
-&jar;
-&zip;
//#screenshot
#ref(http://lh6.ggpht.com/_9Z4BYR88imo/TQTN0Yp0GRI/AAAAAAAAAbY/WvXw5vm2_LI/s800/HideComboArrowButton.png)
**サンプルコード [#l1b78e9d]
#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);
}}
**解説 [#q1e91fd3]
上記のサンプルでは、以下のようにして、``JComboBox``を``JLabel``風に表示しています。
- ``UIManager.put("ComboBox.squareButton", Boolean.FALSE);``で、``ArrowButton``の幅をそのまま使用するように変更
- ``BasicComboBoxUI#createArrowButton``をオーバーライドして、``ArrowButton``の代わりに幅高さ``0``で``setVisible(false)``なボタンを作成
- ``JComboBox``の背景色を親の``JPanel``と同じにする
- ``JComboBox``がフォーカスを取得しないようにする
**参考リンク [#o78e1c11]
-[http://forums.sun.com/thread.jspa?threadID=5337173 Swing - Hide JComboBox Arrow?]
-[http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6337518 Bug ID: 6337518 Null Arrow Button Throws Exception in BasicComboBoxUI]
**コメント [#mce6b916]
#comment