开发者

JTable change the row height dynamically [duplicate]

开发者 https://www.devze.com 2023-01-11 14:32 出处:网络
This question already has answers here: Auto adjust the height of rows in a JTable (3 answers) Closed 9 years ago.
This question already has answers here: Auto adjust the height of rows in a JTable (3 answers) Closed 9 years ago.

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

--Edit--

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();
      i开发者_运维知识库f (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(...);

If you need more help post your SSCCE.


You simply call setRowHeight(row, height);. For example:

JTable t = new JTable(5, 5);
t.setRowHeight(2, 30);

will set the 3rd row to 30 high.

Is your question more complicated? You haven't said much about the problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消