Swing/ComboItemHeight のバックアップ差分(No.2)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/ComboItemHeight へ行く。
- 1 (2013-01-10 (木) 18:00:32)
- 2 (2013-10-18 (金) 15:54:23)
- 3 (2013-12-20 (金) 20:06:03)
- 4 (2015-02-19 (木) 18:39:29)
- 5 (2015-06-11 (木) 11:03:27)
- 6 (2015-06-11 (木) 15:48:16)
- 7 (2017-03-16 (木) 21:40:17)
- 8 (2017-04-07 (金) 13:51:51)
- 9 (2018-01-18 (木) 16:08:25)
- 10 (2019-10-30 (水) 17:31:42)
- 11 (2021-05-25 (火) 08:29:21)
- 追加された行はこの色です。
- 削除された行はこの色です。
TITLE:JComboBoxの高さを変更する #navi(../) #tags() #tags(JComboBox, ListCellRenderer) RIGHT:Posted by &author(aterai); at 2009-03-02 *JComboBoxの高さを変更する [#fd467807] JComboBox自体の高さや、ドロップダウンリスト内にあるアイテムの高さを変更します。 * JComboBoxの高さを変更する [#fd467807] `JComboBox`自体の高さや、ドロップダウンリスト内にあるアイテムの高さを変更します。 -&jnlp; -&jar; -&zip; - &jnlp; - &jar; - &zip; //#screenshot #ref(http://lh3.ggpht.com/_9Z4BYR88imo/TQTJ6VVptrI/AAAAAAAAAVI/x72zWGymqHk/s800/ComboItemHeight.png) #ref(https://lh3.googleusercontent.com/_9Z4BYR88imo/TQTJ6VVptrI/AAAAAAAAAVI/x72zWGymqHk/s800/ComboItemHeight.png) **サンプルコード [#n266cd55] ** サンプルコード [#n266cd55] #code(link){{ JComboBox combo1 = new JComboBox(items); JLabel renderer1 = (JLabel)combo1.getRenderer(); renderer1.setPreferredSize(new Dimension(0, 32)); }} #code{{ JComboBox combo2 = new JComboBox(items); final ListCellRenderer r = combo2.getRenderer(); final Dimension dim = ((JLabel)r).getPreferredSize(); combo2.setRenderer(new ListCellRenderer() { public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component c = r.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus); c.setPreferredSize(new Dimension(100, (index<0)?dim.height:32)); return c; } }); }} **解説 [#e555ddb2] -上 --レンダラーにsetPreferredSizeで高さを設定しています。 ** 解説 [#e555ddb2] - 上 -- レンダラーに`setPreferredSize`で高さを設定しています。 -下 --レンダラーのgetListCellRendererComponentで、indexが0以上の時だけ、高さを変更しています。 - 下 -- レンダラーの`getListCellRendererComponent`で、`index`が`0`以上の時だけ、高さを変更しています。 //**参考リンク **コメント [#yac29798] ** コメント [#yac29798] #comment