JTable hide and show columns

后端 未结 6 860
南旧
南旧 2021-01-11 13:03

I want to add some columns to a table (Swing JTable). Some of them will have a default size (e.g. 250), others will be hidden (so their size will be 0). I use this code:

6条回答
  •  不知归路
    2021-01-11 13:24

    I think you have named your methods incorrectly, when you want to hide a column you will set

    column.setMinWidth(0);
    column.setMaxWidth(0);
    column.setPreferredWidth(0);
    

    but in your code you are doing this when you want to show a column which is exactly opposite.

    Also there is no need to call this "setWidth" method on a TableColumn, read TableColumn#setWidth(int).

提交回复
热议问题