JTable动态地改变行高 [英] JTable change the row height dynamically

查看:204
本文介绍了JTable动态地改变行高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法动态更改行的高度,是否需要重载的方法?

i am having trouble changing the height of the my rows dynamically, is there a method i need to overload?

- 编辑 -

很抱歉这是我的第一篇短信....我的问题与根据内容改变行高有关。所以到目前为止我所做的是一个实现TabelCellRenderer的内部类。

Sorry for the short post it was my first ....My problems was really to do with changing the row height depending on the content. So what i have done so far is made a inner class that implements TabelCellRenderer.

这就是我正在进行的行高计算。

This is what i am doing at the moment for my row height calculations.

  private static class TextAreaRenderer extends JTextPane implements TableCellRenderer
  {


  public Component getTableCellRendererComponent(JTable table, Object value,
                                                 boolean isSelected,
                                                 boolean hasFocus, int row,
                                                 int column)
  {
      /* Setup Code here */

      this.setText(((String)value).getEntityName());
      int height = new Double(this.getPreferredSize().getHeight()).intValue();
      if (table.getRowHeight(row) < height)
          table.setRowHeight(row, height);

      /* some more code */

      return this;
  }

}

这是正确的方法吗?
谢谢。

Would this be the correct way to do this ? Thanks.

推荐答案

table.setRowHeight(...);

如果您需要更多帮助,请发布 SSCCE

If you need more help post your SSCCE.

这篇关于JTable动态地改变行高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆