Как сделать столбцы в Невидимой операции JTable для Java Swing

После небольшого количества оглядывания это кажется tr, действительно самый простой путь:

export CLEANSTRING="`echo -n "${STRING}" | tr -cd '[:alnum:] [:space:]' | tr '[:space:]' '-'  | tr '[:upper:]' '[:lower:]'`"

бритва Оккама , я предполагаю.

38
задан IAdapter 29 September 2009 в 13:49
поделиться

3 ответа

Remove the TableColumn from the TableColumnModel.

TableColumnModel tcm = table.getColumnModel();
tcm.removeColumn( tcm.getColumn(...) );

If you need access to the data then you use table.getModel().getValueAt(...).

For a more complex solution that allows the user to hide/show columns as they wish check out the Table Column Manager.

62
ответ дан 27 November 2019 в 03:09
поделиться

Set the min, max and "normal" width to 0:

jTable.getColumn("ABC").setMinWidth(0); // Must be set before maxWidth!!
jTable.getColumn("ABC").setMaxWidth(0);
jTable.getColumn("ABC").setWidth(0);

Note: Since you can't set a maxWidth < minWidth, you need to change minWidth, first (javadoc). Same is true for width.

The second approach is to extend TableColumnModel and override all the methods to create the illusion (for the JTable) that your model doesn't have those two columns.

So when you hide a column, you must return one less when the table asks for the number of columns and when it asks for the column X, you may have to add +1 to the column index (depending on whether it is to the left or right of the hidden column), etc.

Let your new table model forward all method calls (with the corrected indexes, etc) to the actual column model and use the new table model in the JTable.

-2
ответ дан 27 November 2019 в 03:09
поделиться

You could create a subclass of the model, and override TableModel.getColumnCount as follows:

int getColumnCount() {
    return super.getColumnCount()-2;
}

The last two columns would then not be displayed in the JTable.

-3
ответ дан 27 November 2019 в 03:09
поделиться
Другие вопросы по тегам:

Похожие вопросы: