Swing/TextPositionAndAlignment のバックアップ(No.9)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - 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)
- category: swing
folder: TextPositionAndAlignment
title: JLabelのアイコンと文字列の位置
tags: [JLabel, Icon, Alignment, JButton]
author: aterai
pubdate: 2009-03-16T13:43:23+09:00
description: JLabelのアイコンと文字列の位置をテストします。
image:
概要
JLabel
のアイコンと文字列の位置をテストします。
Screenshot

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