如何在Container的BorderLayout的SOUTH位置画一条水平线?

发布于 2024-12-07 02:43:18 字数 2183 浏览 4 评论 0原文

我有一个布局为 BorderLayout 的容器。我想在南位置画一条水平线,因为这个容器是重复绘制的,所以我想用水平线分隔每个容器。

这是代码:

tList = new List(tModel);
tList.setListCellRenderer(new CTable(listclient));

public class CTable extends Container implements ListCellRenderer {

  private Label pic = new Label("");
  private Container cnt;
  private Label name = new Label("");
  private Label credit = new Label("");
  private ligneHorizontal ligne;

  private Font fontLibelle = (MenuPrincipalForm.r).getFont("FontTextFieldBold");

  private Label focus = new Label("");

  public CTable(Vector valeur)
  {
      setLayout(new BorderLayout());
      addComponent(BorderLayout.WEST, pic);
      cnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
      name.getStyle().setBgTransparency(0);
      name.getStyle().setFont(fontLibelle);
      credit.getStyle().setBgTransparency(0);
      cnt.addComponent(name);
      cnt.addComponent(credit);
      ligne = new ligneHorizontal(100);
      cnt.addComponent(ligne);
      addComponent(BorderLayout.CENTER, cnt);
      focus.getStyle().setBgTransparency(100);
  }

  public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected)
  {
      if ("-".equalsIgnoreCase(String.valueOf(value)))
      {
          name.setText(" - ");
          credit.setText("Encours : -  Impayés : -");
          pic.setIcon(null);
      }
      else
      {
          if (index%2 == 0)
              this.setUIID("evenRowsCell");
          else
              this.setUIID("oddRowsCell");
          name.setText("123456789012 - Rasolofomanana Marc");
          credit.setText("Crédits : 15.000 (Ar) Impayés : 10.000 (Ar)");
          pic.setIcon(null);
      }
      return this;
  }
  public Component getListFocusComponent(List list)
  {
      return focus;
  }
}

public class ligneHorizontal extends Label {
    public ligneHorizontal(int l)
    {
        String t = "";
        do
        {
            t.concat(new String("-"));
        }
        while(t.length()<l);
        this.setText(t);
        this.setPreferredH(5);
        this.getStyle().setBgColor(0);
    }
}

而且我还想知道如何为列表的偶数行和奇数行着色,因为我尝试过,但直到单击单元格才获得颜色。

I have a Container whose Layout is BorderLayout. I want to draw a horizontal line at the SOUTH position because this Container is drawn repeatedly so I want to delimit each by the horizontal line.

Here is the code:

tList = new List(tModel);
tList.setListCellRenderer(new CTable(listclient));

public class CTable extends Container implements ListCellRenderer {

  private Label pic = new Label("");
  private Container cnt;
  private Label name = new Label("");
  private Label credit = new Label("");
  private ligneHorizontal ligne;

  private Font fontLibelle = (MenuPrincipalForm.r).getFont("FontTextFieldBold");

  private Label focus = new Label("");

  public CTable(Vector valeur)
  {
      setLayout(new BorderLayout());
      addComponent(BorderLayout.WEST, pic);
      cnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
      name.getStyle().setBgTransparency(0);
      name.getStyle().setFont(fontLibelle);
      credit.getStyle().setBgTransparency(0);
      cnt.addComponent(name);
      cnt.addComponent(credit);
      ligne = new ligneHorizontal(100);
      cnt.addComponent(ligne);
      addComponent(BorderLayout.CENTER, cnt);
      focus.getStyle().setBgTransparency(100);
  }

  public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected)
  {
      if ("-".equalsIgnoreCase(String.valueOf(value)))
      {
          name.setText(" - ");
          credit.setText("Encours : -  Impayés : -");
          pic.setIcon(null);
      }
      else
      {
          if (index%2 == 0)
              this.setUIID("evenRowsCell");
          else
              this.setUIID("oddRowsCell");
          name.setText("123456789012 - Rasolofomanana Marc");
          credit.setText("Crédits : 15.000 (Ar) Impayés : 10.000 (Ar)");
          pic.setIcon(null);
      }
      return this;
  }
  public Component getListFocusComponent(List list)
  {
      return focus;
  }
}

public class ligneHorizontal extends Label {
    public ligneHorizontal(int l)
    {
        String t = "";
        do
        {
            t.concat(new String("-"));
        }
        while(t.length()<l);
        this.setText(t);
        this.setPreferredH(5);
        this.getStyle().setBgColor(0);
    }
}

And also I want to know how to coloriate even rows and odd rows of the List because I tried but the color is not get until I click on the cell.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒几许 2024-12-14 02:43:18

好的,我找到了解决方案:我派生了 BackgroundPainterpublic void Paint(Graphics g,Rectangle rect) 方法中绘制了线条 ( g.drawLine( rect.getX(), rect.getY()+h-1, rect.getX()+w, rect.getY()+h-1);)。
因此,当我想在容器中画一条线时,我会编写 myContainer.getStyle().setBgPainter(new obligedClassName(myContainer));

Ok , I found the solution : I derived BackgroundPainter where in the public void paint(Graphics g,Rectangle rect) method I draw the line ( g.drawLine(rect.getX(), rect.getY()+h-1, rect.getX()+w, rect.getY()+h-1); ).
So when I want to draw a line in the container then I write myContainer.getStyle().setBgPainter(new derivedClassName(myContainer));

半世蒼涼 2024-12-14 02:43:18

添加首选高度为 5 的 Label,容器之间的背景颜色为黑色

add Label with preferred height 5, with black bg color between containers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文