• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:JComboBoxのItemを左右に配置
#navi(../)
*JComboBoxのItemを左右に配置 [#v60ec86f]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2005-01-17~
更新日:&lastmod;
---
category: swing
folder: LRComboBox
title: JComboBoxのItemを左右に配置
tags: [JComboBox, Html]
author: aterai
pubdate: 2005-01-17T00:09:58+09:00
description: JComboBoxのItemにテキストを左右に分けて配置します。
image: https://lh3.googleusercontent.com/_9Z4BYR88imo/TQTPk2QD9aI/AAAAAAAAAeM/xrl0d1ms74g/s800/LRComboBox.png
---
* 概要 [#summary]
`JComboBox`の`Item`にテキストを左右に分けて配置します。

#contents
#download(https://lh3.googleusercontent.com/_9Z4BYR88imo/TQTPk2QD9aI/AAAAAAAAAeM/xrl0d1ms74g/s800/LRComboBox.png)

**概要 [#m0d6bf26]
JComboBoxのItemにテキストを左右に分けて配置します。
* サンプルコード [#sourcecode]
#code(link){{
class LRItem {
  private final String leftText;
  private final String rightText;
  public LRItem(String strLeft, String strRight) {
    leftText  = strLeft;
    rightText = strRight;
  }

#screenshot
  public String getHtmlText() {
    return "<html><table width='240'><tr><td align='left'>" + leftText +
    "</td><td align='right'>" + rightText + "</td></tr></table></html>";
  }

**サンプルコード [#oace48f1]
 class LRItem{
   private final String leftText;
   private final String rightText;
   public LRItem(String strLeft, String strRight) {
     leftText  = strLeft;
     rightText = strRight;
   }
   public String getHtmlText() {
     return "<html><table width='240'><tr><td align='left'>"+leftText+
     "</td><td align='right'>"+rightText+"</td></tr></table></html>";
   }
   public String getLeftText()  { return leftText; }
   public String getRightText() { return rightText; }
   public String toString()     { return getHtmlText(); }
 }
  public String getLeftText() {
    return leftText;
  }

-&jnlp;
-&jar;
-&zip;
  public String getRightText() {
    return rightText;
  }

**解説 [#h9d560bf]
JComboBoxにhtmlのtableタグを使うことで、Itemに設定した文字列を左右に振り分けています。
  public String toString() {
    return getHtmlText();
  }
}
}}

**参考リンク [#k039e984]
-[[JComboBoxのItemを左右にクリップして配置>Swing/ClippedLRComboBox]]
* 解説 [#explanation]
`JComboBox`の`Item`に`table`タグを使用して文字列を左右に振り分けています。

**コメント [#fe8212eb]
- `JComboBox`のリストにカラムを追加・削除可能
- `JComboBox`のサイズ変更に未対応

* 参考リンク [#reference]
- [[JComboBoxのItemを左右にクリップして配置>Swing/ClippedLRComboBox]]
-- セルレンダラーに`JLabel`とレイアウトマネージャを適用してカラムを生成

* コメント [#comment]
#comment
#comment