Swing/TextPositionAndAlignment のバックアップの現在との差分(No.1)
TITLE:JLabelのアイコンと文字列の位置
Posted by terai at 2009-03-16
JLabelのアイコンと文字列の位置
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:
概要
JLabel
のアイコンと文字列の位置をテストします。
- &jnlp;
- &jar;
- &zip;
Screenshot
Advertisement
#screenshot
サンプルコード
#spanend
#spanadd
* サンプルコード [#sourcecode]
#spanend
#spanadd
#code(link){{
#spanend
#spanadd
JLabel label = new JLabel("Test Test", icon, SwingConstants.CENTER);
#spanend
label.setVerticalAlignment(SwingConstants.CENTER);
label.setVerticalTextPosition(SwingConstants.TOP);
label.setHorizontalAlignment(SwingConstants.RIGHT);
label.setHorizontalTextPosition(SwingConstants.LEFT);
解説
上記のサンプルでは、setVerticalAlignment、setVerticalTextPosition、setHorizontalAlignment、setHorizontalTextPositionといったメソッドを使用して、JLabelのアイコンと文字列の位置関係を変更しています。解説
上記のサンプルでは、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)