1 package snow.utils; 2 3 import javax.swing.event.TableModelListener ; 4 import snow.sortabletable.SortableTableModel; 5 import javax.swing.table.*; 6 import javax.swing.*; 7 import javax.swing.tree.TreeNode ; 8 import javax.swing.tree.MutableTreeNode ; 9 10 11 13 public final class MemoryUtils 14 { 15 16 private MemoryUtils() 17 { 18 } 19 20 22 public static void freeChilds(MutableTreeNode root) 23 { 24 for(int i=root.getChildCount()-1; i>=0; i--) { 26 TreeNode tn = root.getChildAt(i); 27 if(tn instanceof MutableTreeNode ) 28 { 29 ((MutableTreeNode ) tn).removeFromParent(); 30 } 31 else 32 { 33 root.remove(i); 34 } 35 } 36 } 37 38 40 public static void free(JTable table) 41 { 42 TableModel tm = table.getModel(); 43 if(tm!=null) 44 { 45 table.setModel(new EmptyTableModel()); 46 if(tm instanceof SortableTableModel) 47 { 48 SortableTableModel stm = (SortableTableModel) tm; 49 } 50 } 51 } 52 53 static class EmptyTableModel implements TableModel 54 { 55 public int getRowCount() { return 0; } 56 public int getColumnCount() { return 0; } 57 public String getColumnName(int columnIndex) { return ""; } 58 public Class <?> getColumnClass(int columnIndex) { return String .class; } 59 public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } 60 public Object getValueAt(int rowIndex, int columnIndex) { return ""; } 61 public void setValueAt(Object aValue, int rowIndex, int columnIndex) {} 62 public void addTableModelListener(TableModelListener l) {} 63 public void removeTableModelListener(TableModelListener l) {} 64 } 65 66 } | Popular Tags |