• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:JTabbedPaneのサムネイルをJToolTipsで表示
#navi(../)
*TitledBorderのタイトル位置 [#x572c279]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2007-08-06~
更新日:&lastmod;
---
category: swing
folder: TitledBorder
title: TitledBorderのタイトル位置
tags: [TitledBorder, Border]
author: aterai
pubdate: 2007-08-06T12:08:09+09:00
description: TitledBorderのタイトル位置や揃えを切り替えてテストします。
image: https://lh3.googleusercontent.com/_9Z4BYR88imo/TQTVZeDhwBI/AAAAAAAAAnk/QmV1N3Uqp3o/s800/TitledBorder.png
---
* 概要 [#summary]
`TitledBorder`のタイトル位置や揃えを切り替えてテストします。

#contents
#download(https://lh3.googleusercontent.com/_9Z4BYR88imo/TQTVZeDhwBI/AAAAAAAAAnk/QmV1N3Uqp3o/s800/TitledBorder.png)

**概要 [#i5faf1bc]
TitledBorderのタイトル位置や揃えを切り替えてテストします。
* サンプルコード [#sourcecode]
#code(link){{
VerticalOrientation vo = (VerticalOrientation) vertChoices.getSelectedItem();
switch (vo) {
  case DEFAULT_POSITION:
    border.setTitlePosition(TitledBorder.DEFAULT_POSITION);
    break;
  case ABOVE_TOP:
    border.setTitlePosition(TitledBorder.ABOVE_TOP);
    break;
  case TOP:
    border.setTitlePosition(TitledBorder.TOP);
    break;
  case BELOW_TOP:
    border.setTitlePosition(TitledBorder.BELOW_TOP);
    break;
  case ABOVE_BOTTOM:
    border.setTitlePosition(TitledBorder.ABOVE_BOTTOM);
    break;
  case BOTTOM:
    border.setTitlePosition(TitledBorder.BOTTOM);
    break;
  case BELOW_BOTTOM:
    border.setTitlePosition(TitledBorder.BELOW_BOTTOM);
    break;
}

#screenshot

**サンプルコード [#ae811e62]
#code{{
VerticalOrientation vo = (VerticalOrientation)verticalOrientationChoices.getSelectedItem();
switch(vo) {
  case DEFAULT_POSITION: border.setTitlePosition(TitledBorder.DEFAULT_POSITION); break;
  case ABOVE_TOP:        border.setTitlePosition(TitledBorder.ABOVE_TOP);        break;
  case TOP:              border.setTitlePosition(TitledBorder.TOP);              break;
  case BELOW_TOP:        border.setTitlePosition(TitledBorder.BELOW_TOP);        break;
  case ABOVE_BOTTOM:     border.setTitlePosition(TitledBorder.ABOVE_BOTTOM);     break;
  case BOTTOM:           border.setTitlePosition(TitledBorder.BOTTOM);           break;
  case BELOW_BOTTOM:     border.setTitlePosition(TitledBorder.BELOW_BOTTOM);     break;
Justification jc = (Justification) justificationChoices.getSelectedItem();
switch (jc) {
  case DEFAULT_JUSTIFICATION:
    border.setTitleJustification(TitledBorder.DEFAULT_JUSTIFICATION);
    break;
  case LEFT:
    border.setTitleJustification(TitledBorder.LEFT);
    break;
  case CENTER:
    border.setTitleJustification(TitledBorder.CENTER);
    break;
  case RIGHT:
    border.setTitleJustification(TitledBorder.RIGHT);
    break;
  case LEADING:
    border.setTitleJustification(TitledBorder.LEADING);
    break;
  case TRAILING:
    border.setTitleJustification(TitledBorder.TRAILING);
    break;
}
Justification jc = (Justification)justificationChoices.getSelectedItem();
switch(jc) {
  case DEFAULT_JUSTIFICATION: border.setTitleJustification(
                                              TitledBorder.DEFAULT_JUSTIFICATION); break;
  case LEFT:     border.setTitleJustification(TitledBorder.LEFT);     break;
  case CENTER:   border.setTitleJustification(TitledBorder.CENTER);   break;
  case RIGHT:    border.setTitleJustification(TitledBorder.RIGHT);    break;
  case LEADING:  border.setTitleJustification(TitledBorder.LEADING);  break;
  case TRAILING: border.setTitleJustification(TitledBorder.TRAILING); break;
}
panel.repaint();
}}
-&jnlp;
-&jar;
-&zip;

**解説 [#e93f52ba]
上記のサンプルでは、以下のような定数フィールド値をコンボボックスで指定することで、タイトルの位置や揃えを変更できるようになっています。
* 解説 [#explanation]
上記のサンプルでは、以下のような定数フィールド値を指定して`TitledBorder`のタイトル位置や揃えを変更できます。

-タイトルの位置をTitledBorder#setTitlePositionメソッドで指定します。
--DEFAULT_POSITION
--ABOVE_TOP
--TOP
--BELOW_TOP
--ABOVE_BOTTOM
--BOTTOM
--BELOW_BOTTOM
- タイトルの位置を`TitledBorder#setTitlePosition(int)`メソッドで指定
-- `TitledBorder.DEFAULT_POSITION`
-- `TitledBorder.ABOVE_TOP`
-- `TitledBorder.TOP`
-- `TitledBorder.BELOW_TOP`
-- `TitledBorder.ABOVE_BOTTOM`
-- `TitledBorder.BOTTOM`
-- `TitledBorder.BELOW_BOTTOM`
- タイトルの揃えを`TitledBorder#setTitleJustification(int)`メソッドで指定
-- `TitledBorder.LEFT`
-- `TitledBorder.CENTER`
-- `TitledBorder.RIGHT`
-- `TitledBorder.LEADING`
-- `TitledBorder.TRAILING`

-タイトルの揃えをTitledBorder#setTitleJustificationメソッドで指定します。
--LEFT
--CENTER
--RIGHT
--LEADING
--TRAILING
* 参考リンク [#reference]
- [https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/border/TitledBorder.html TitledBorder (Java Platform SE 8)]
- [[TitledBorderのタイトルにアイコンを表示する>Swing/IconTitledBorder]]
- [https://bugs.openjdk.org/browse/JDK-4199867 JDK-4199867 TitledBorder MIDDLE Veritcal Alignment - Java Bug System]

//**参考リンク
**コメント [#t2d56f55]
* コメント [#comment]
#comment
- メモ: [https://bugs.openjdk.org/browse/JDK-6658876 TitledBorder API inconsitent with implementation: uses TOP instead of DEFAULT_POSITION] -- &user(aterai); &new{2008-04-12 (土) 00:35:59};

#comment