0
我使用的JXTable有一個setColumnControlVisible(true),它顯示了滾動上方右上角的一個按鈕,我們可以通過按下來顯示和隱藏列。我想記住應用程序關閉時的更改,但還不能確定,在這裏我嘗試了至今。我檢查JxTable的src,但沒有如何獲取隱藏的列索引或列號。Jtable顯示並隱藏列並保存配置。
package paractice;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.table.AbstractTableModel;
import org.jdesktop.swingx.JXTable;
public class TableTest extends JFrame{
private static final long serialVersionUID = 1L;
private JXTable table;
public TableTest() {
setLayout(new BorderLayout());
table = new JXTable(new model());
//add(table.getTableHeader(), BorderLayout.NORTH);
add(new JScrollPane(table), BorderLayout.CENTER);
table.setColumnControlVisible(true);
setSize(700, 700);
}
public class model extends AbstractTableModel{
String[] columns = {"column1", "column2", "column3", "column4", "column5"};
@Override
public String getColumnName(int column) {
return columns[column];
}
@Override
public boolean isCellEditable(int arg0, int arg1) {
return super.isCellEditable(arg0, arg1);
}
@Override
public void setValueAt(Object arg0, int row, int col) {
super.setValueAt(arg0, row, col);
fireTableCellUpdated(row, col);
}
public int getColumnCount() {
return columns.length;
}
public int getRowCount() {
return 0;
}
public Object getValueAt(int arg0, int arg1) {
return null;
}
}
public static void main(String args[]) {
TableTest test = new TableTest();
test.setVisible(true);
}
}
謝謝。這樣一個簡單的邏輯。 –