Swing/TextPositionAndAlignment のバックアップ(No.5)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/TextPositionAndAlignment へ行く。
- 1 (2009-03-16 (月) 13:43:23)
- 2 (2009-03-17 (火) 19:06:18)
- 3 (2013-01-10 (木) 17:56:55)
- 4 (2014-01-19 (日) 19:32:42)
- 5 (2014-10-29 (水) 01:36:17)
- 6 (2015-11-15 (日) 19:37:01)
- 7 (2017-05-11 (木) 12:21:12)
- 8 (2018-05-09 (水) 15:47:59)
- 9 (2020-04-29 (水) 19:50:15)
- 10 (2021-10-30 (土) 21:39:39)
- 11 (2025-01-03 (金) 08:57:02)
- 12 (2025-01-03 (金) 09:01:23)
- 13 (2025-01-03 (金) 09:02:38)
- 14 (2025-01-03 (金) 09:03:21)
- 15 (2025-01-03 (金) 09:04:02)
- title: JLabelのアイコンと文字列の位置 tags: [JLabel, Icon, Alignment, JButton] author: aterai pubdate: 2009-03-16T13:43:23+09:00 description: JLabelのアイコンと文字列の位置をテストします。
概要
JLabel
のアイコンと文字列の位置をテストします。
Screenshot

Advertisement
サンプルコード
label.setVerticalAlignment(SwingConstants.CENTER);
label.setVerticalTextPosition(SwingConstants.TOP);
label.setHorizontalAlignment(SwingConstants.RIGHT);
label.setHorizontalTextPosition(SwingConstants.LEFT);
View in GitHub: Java, Kotlin解説
上記のサンプルでは、setVerticalAlignment
、setVerticalTextPosition
、setHorizontalAlignment
、setHorizontalTextPosition
といったメソッドを使用して、JLabel
のアイコンと文字列の位置関係を変更しています。
JButton
などにも、アイコンと文字列の位置を設定する同名のメソッドが存在します(引数はSwingConstants
インタフェースで定義された共通の定数が使用可)。