Swing/SetColumns のバックアップ差分(No.7)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/SetColumns へ行く。
- 1 (2006-12-18 (月) 16:11:14)
- 2 (2007-06-26 (火) 14:52:56)
- 3 (2008-03-12 (水) 19:34:47)
- 4 (2008-03-21 (金) 19:29:25)
- 5 (2008-03-30 (日) 02:58:17)
- 6 (2008-03-31 (月) 14:06:58)
- 7 (2014-10-03 (金) 14:06:47)
- 8 (2015-05-18 (月) 00:01:14)
- 9 (2017-03-10 (金) 18:12:42)
- 10 (2018-01-13 (土) 19:53:38)
- 11 (2018-09-06 (木) 13:11:25)
- 12 (2020-08-28 (金) 15:52:41)
- 13 (2022-02-25 (金) 15:12:12)
- 追加された行はこの色です。
- 削除された行はこの色です。
TITLE:JComboBoxなどの幅をカラム数で指定 #navi(../) *JComboBoxなどの幅をカラム数で指定 [#ve8ef0dc] Posted by [[terai]] at 2006-12-18 --- title: JComboBoxなどの幅をカラム数で指定 tags: [JTextField, JPasswordField, JSpinner, JComboBox] author: aterai pubdate: 2006-12-18T16:11:14+09:00 --- * 概要 [#ve8ef0dc] `JTextField`,`JPasswordField`,`JSpinner`,`JComboBox`の幅をカラム数で指定して比較しています。 #contents #download(https://lh3.googleusercontent.com/_9Z4BYR88imo/TQTS72PP0tI/AAAAAAAAAjk/RRG_w2fJBtA/s800/SetColumns.png) **概要 [#hb1df07a] JTextField,JPasswordField,JSpinner,JComboBox の幅をカラム数で指定して比較しています。 -&jnlp; -&jar; -&zip; #screenshot **サンプルコード [#ib603a1f] #code{{ * サンプルコード [#ib603a1f] #code(link){{ JTextField field = new JTextField(20); JPasswordField passwd = new JPasswordField(20); JSpinner.DefaultEditor e = (JSpinner.DefaultEditor)spinner.getEditor(); e.getTextField().setColumns(20); combo1.setEditable(true); Component c = combo1.getEditor().getEditorComponent(); if(c instanceof JTextField) ((JTextField)c).setColumns(20); }} **解説 [#fd934c68] 上記のサンプルでは、要素が空のJComboBoxなどのカラム幅を同じにして((下二つはdefaultのまま))、以下のような順番で並べています。 +JTextField [setColumns(20)] +JPasswordField [setColumns(20)] +JSpinner [setColumns(20)] +JComboBox [setEditable(true), setColumns(20)] +JComboBox [setEditable(true), default] +JComboBox [setEditable(false), default] * 解説 [#fd934c68] 上記のサンプルでは、要素が空の`JComboBox`などのカラム幅を同じにして(下二つは`default`のまま)、以下のような順番で並べています。 + `JTextField` [`setColumns(20)`] + `JPasswordField` [`setColumns(20)`] + `JSpinner` [`setColumns(20)`] + `JComboBox` [`setEditable(true)`, `setColumns(20)`] + `JComboBox` [`setEditable(true)`, `default`] + `JComboBox` [`setEditable(false)`, `default`] スクリーンショットは、左(上)が 1.6.0(Java SE 6) で、右(下)が、1.5.0_10 で実行したものになっています(どちらもWindows L&F)。1.6.0 ではきれいに揃っていますが、1.5.0_10 などでは幅も高さも余白もガタガタ((1.5では左の内余白もJTextFieldは広すぎ、JComboBoxなどは狭すぎるなどバラバラ))なので、レイアウトマネージャーで工夫するか、setPreferredSize(Dimension)を使って幅を揃える方がよさそうです([[JButtonなどの高さを変更せずに幅を指定>Swing/ButtonWidth]])。 スクリーンショットは、左が`JDK 1.6.0`、右が、`JDK 1.5.0_10`で実行したものになっています(どちらも`WindowsLookAndFeel`)。`1.6.0`ではきれいに揃っていますが、`1.5.0_10`などでは幅も高さも余白もガタガタ(左の内余白も`JTextField`は広すぎ、`JComboBox`などは狭すぎるなどバラバラ)なので、レイアウトマネージャーで工夫するか、`setPreferredSize(Dimension)`を使って幅を揃える方がよさそうです([[JButtonなどの高さを変更せずに幅を指定>Swing/ButtonWidth]])。 **参考リンク [#oe03e66c] -[[JButtonなどの高さを変更せずに幅を指定>Swing/ButtonWidth]] * 参考リンク [#oe03e66c] - [[JButtonなどの高さを変更せずに幅を指定>Swing/ButtonWidth]] **コメント [#w970c125] * コメント [#w970c125] #comment #comment