Swing/ComboItemHeight のバックアップソース(No.4)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - 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の高さを変更する tags: [JComboBox, ListCellRenderer] author: aterai pubdate: 2009-03-02T12:37:58+09:00 description: JComboBox自体の高さや、ドロップダウンリスト内にあるアイテムの高さを変更します。 --- * 概要 [#fd467807] `JComboBox`自体の高さや、ドロップダウンリスト内にあるアイテムの高さを変更します。 #download(https://lh3.googleusercontent.com/_9Z4BYR88imo/TQTJ6VVptrI/AAAAAAAAAVI/x72zWGymqHk/s800/ComboItemHeight.png) * サンプルコード [#n266cd55] #code(link){{ JComboBox combo1 = new JComboBox(items); JLabel renderer1 = (JLabel)combo1.getRenderer(); renderer1.setPreferredSize(new Dimension(0, 32)); JComboBox combo2 = new JComboBox(items); final ListCellRenderer r = combo2.getRenderer(); final Dimension dim = ((JLabel)r).getPreferredSize(); combo2.setRenderer(new ListCellRenderer() { @Override 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`で高さを設定しています。 - 下 -- レンダラーの`getListCellRendererComponent`で、`index`が`0`以上の時だけ、高さを変更しています。 //* 参考リンク * コメント [#yac29798] #comment - `html`タグを使用するサンプルなどを追加。 -- &user(aterai); &new{2013-12-20 (金) 20:06:03}; #comment