TITLE:JComboBoxのItemを左右に配置

JComboBoxのItemを左右に配置

編集者:Terai Atsuhiro~

作成日:2005-01-17
更新日:2022-03-06 (日) 07:22:26
  • 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

概要

JComboBoxItemにテキストを左右に分けて配置します。

概要

JComboBoxのItemにテキストを左右に分けて配置します。

サンプルコード

#spanend
#spanadd
class LRItem {
#spanend
  private final String leftText;
  private final String rightText;
  public LRItem(String strLeft, String strRight) {
    leftText  = strLeft;
    rightText = strRight;
  }

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

#spandel
**サンプルコード [#oace48f1]
#spanend
 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;
  }

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

参考リンク

解説

JComboBoxItemtableタグを使用して文字列を左右に振り分けています。

コメント

  • JComboBoxのリストにカラムを追加・削除可能
  • JComboBoxのサイズ変更に未対応

参考リンク

コメント