List of usage examples for javax.swing.table DefaultTableModel fireTableStructureChanged
public void fireTableStructureChanged()
From source file:Main.java
public static void main(String[] argv) throws Exception { DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); table.setAutoCreateColumnsFromModel(false); Vector data = model.getDataVector(); Collections.sort(data, new ColumnSorter(0)); model.fireTableStructureChanged(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); table.setAutoCreateColumnsFromModel(false); boolean ascending = false; Vector data = model.getDataVector(); Object[] colData = new Object[model.getRowCount()]; for (int i = 0; i < colData.length; i++) { colData[i] = ((Vector) data.get(i)).get(0); }/*from w w w. j a va2 s . co m*/ Arrays.sort(colData, new ColumnSorter()); for (int i = 0; i < colData.length; i++) { ((Vector) data.get(i)).set(0, colData[i]); } model.fireTableStructureChanged(); }
From source file:vn.edu.vttu.ui.PanelStatiticsPaymentRawmaterialInvoice.java
public void sortAllRowsBy(DefaultTableModel model, int colIndex, boolean ascending) { Vector data = model.getDataVector(); Collections.sort(data, new ColumnSorter(colIndex, ascending)); model.fireTableStructureChanged(); }
From source file:org.isatools.isacreator.gui.formelements.SubForm.java
protected void removeColumn(int curColDelete) { if ((curColDelete == -1) || (curColDelete == 0)) { return;/* w w w . j a v a 2s . com*/ } if (defaultTableModel.getColumnCount() == 2 && curColDelete == (defaultTableModel.getColumnCount() - 1)) { clearColumn(curColDelete); return; } else { clearColumn(curColDelete); } if (fieldType == FieldTypes.ASSAY && (dataEntryForm != null) && !uneditableRecords.contains(curColDelete)) { clearColumn(curColDelete); return; } DefaultTableModel model = (DefaultTableModel) scrollTable.getModel(); // get the column. because 1 was added on previously to take account of the first column, we need to remove // it this time since the column indexes are now coming from the table. TableColumn col = scrollTable.getColumnModel().getColumn(curColDelete - 1); int columnModelIndex = col.getModelIndex(); Vector data = model.getDataVector(); Vector<String> colIds = new Vector<String>(); for (int i = 0; i < model.getColumnCount(); i++) { colIds.addElement(model.getColumnName(i)); } scrollTable.removeColumn(col); colIds.removeElementAt(columnModelIndex); // remove any data present in the column on deletion for (Object aData : data) { Vector row = (Vector) aData; row.removeElementAt(columnModelIndex); } model.setDataVector(data, colIds); // decrease each column index after deleted column by 1 so that indexes can be kept intact. Enumeration columnEnumeration = scrollTable.getColumnModel().getColumns(); while (columnEnumeration.hasMoreElements()) { TableColumn c = (TableColumn) columnEnumeration.nextElement(); if (c.getModelIndex() >= columnModelIndex) { c.setModelIndex(c.getModelIndex() - 1); } } if (fieldType == FieldTypes.ASSAY && uneditableRecords.contains(defaultTableModel.getColumnCount() - 1)) { uneditableRecords.remove(defaultTableModel.getColumnCount() - 1); } // update the model model.fireTableStructureChanged(); updateTables(); }