Swing/TextPositionAndAlignment のバックアップの現在との差分(No.2)
- バックアップ一覧
- 差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/TextPositionAndAlignment へ行く。
- 追加された行はこの色です。
- 削除された行はこの色です。
TITLE:JLabelのアイコンと文字列の位置 #navi(../) RIGHT:Posted by [[terai]] at 2009-03-16 *JLabelのアイコンと文字列の位置 [#k61b6047] JLabelのアイコンと文字列の位置をテストします。 --- category: swing folder: TextPositionAndAlignment title: JLabelのアイコンと文字列の位置 tags: [JLabel, Icon, Alignment, JButton] author: aterai pubdate: 2009-03-16T13:43:23+09:00 description: JLabelのアイコンと文字列の位置をテストします。 image: https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTVPS5wBUI/AAAAAAAAAnU/2hri1cAlfoM/s800/TextPositionAndAlignment.png --- * 概要 [#summary] `JLabel`のアイコンと文字列の位置をテストします。 -&jnlp; -&jar; -&zip; #download(https://lh6.googleusercontent.com/_9Z4BYR88imo/TQTVPS5wBUI/AAAAAAAAAnU/2hri1cAlfoM/s800/TextPositionAndAlignment.png) #screenshot **サンプルコード [#yd654120] #code{{ * サンプルコード [#sourcecode] #code(link){{ 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); }} **解説 [#e49a55c3] 上記のサンプルでは、setVerticalAlignment、setVerticalTextPosition、setHorizontalAlignment、setHorizontalTextPositionといったメソッドを使用して、JLabelのアイコンと文字列の位置関係を変更しています。 * 解説 [#explanation] 上記のサンプルでは、`JLabel#setVerticalAlignment(...)`、`JLabel#setVerticalTextPosition(...)`、`JLabel#setHorizontalAlignment(...)`、`JLabel#setHorizontalTextPosition(...)`メソッドを使用して`JLabel`のアイコンと文字列の位置関係を変更しています。 **参考リンク [#f74eb1e7] -[[opus-i | シンプル素材 テンプレート 音楽素材>http://opus-i.biz/]] - `AbstractButton`を継承する`JButton`などにもアイコンと文字列の位置を設定する同名のメソッドが存在する -- 引数は`SwingConstants`インタフェースで定義された共通の定数が使用可能 **コメント [#yeda804e] * 参考リンク [#reference] - [https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/JLabel.html#setVerticalAlignment-int- JLabel#setVerticalAlignment(int) (Java Platform SE 8)] - [https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/JLabel.html#setVerticalTextPosition-int- JLabel#setVerticalTextPosition(int) (Java Platform SE 8)] - [https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/JLabel.html#setHorizontalAlignment-int- JLabel#setHorizontalAlignment(int) (Java Platform SE 8)] - [https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/JLabel.html#setHorizontalTextPosition-int- JLabel#setHorizontalTextPosition(int) (Java Platform SE 8)] - [https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/AbstractButton.html#setVerticalAlignment-int- AbstractButton#setVerticalAlignment(int) (Java Platform SE 8)] - [https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/AbstractButton.html#setVerticalTextPosition-int- AbstractButton#setVerticalTextPosition(int) (Java Platform SE 8)] - [https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/AbstractButton.html#setHorizontalAlignment-int- AbstractButton#setHorizontalAlignment(int) (Java Platform SE 8)] - [https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/AbstractButton.html#setHorizontalTextPosition-int- AbstractButton#setHorizontalTextPosition(int) (Java Platform SE 8)] * コメント [#comment] #comment #comment