How to set the RowHeight dynamically in a JTable

后端 未结 5 1409
感动是毒
感动是毒 2020-12-09 20:39

I want to put a String in a JTable that is longer than the given cell-width. How can I set the rowHeight dynamically so that I can read the whole S

5条回答
  •  有刺的猬
    2020-12-09 21:24

    Normally we are setting the RowHeight when the text in the row goes beyond the height of a row, to set the height of a row we do this:

    table.setRowHeight(40);
    

    I want to put a String in a JTable that is longer than the given cell-width. How can I set the rowHeight dynamically so that I can read the whole String?

    To read complete string from the jtable row you don't need to set RowHeight you need to set the PreferredWidth of a column as you are already doing so. Just add a line like:

    textTable.getColumnModel().getColumn(2).setPreferredWidth(300);
    

    And you will be able to read the whole string.


    Output

    output

提交回复
热议问题