TitledBorderのタイトル位置
Total: 8640
, Today: 2
, Yesterday: 2
Posted by aterai at
Last-modified:
概要
TitledBorder
のタイトル位置や揃えを切り替えてテストします。
Screenshot

Advertisement
サンプルコード
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;
}
panel.repaint();
View in GitHub: Java, Kotlin解説
上記のサンプルでは、以下のような定数フィールド値を指定してTitledBorder
のタイトル位置や揃えを変更できます。
- タイトルの位置を
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 (Java Platform SE 8)
- TitledBorderのタイトルにアイコンを表示する
- JDK-4199867 TitledBorder MIDDLE Veritcal Alignment - Java Bug System