List of usage examples for javax.swing.table DefaultTableModel DefaultTableModel
public DefaultTableModel()
DefaultTableModel
which is a table of zero columns and zero rows. From source file:Main.java
public static void main(String[] argv) throws Exception { DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); model.addColumn("Col1"); model.addRow(new Object[] { "r1" }); model.addRow(new Object[] { "r2" }); model.addRow(new Object[] { "r3" }); // Remove the first row model.removeRow(0);/*from w ww . j a v a 2s . com*/ JFrame f = new JFrame(); f.setSize(300, 300); f.add(new JScrollPane(table)); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); model.addColumn("Col1"); model.addRow(new Object[] { "r1" }); model.addRow(new Object[] { "r2" }); model.addRow(new Object[] { "r3" }); // Move the last row to the beginning of the table model.moveRow(model.getRowCount() - 1, model.getRowCount() - 1, 0); JFrame f = new JFrame(); f.setSize(300, 300);//from w ww .j a va2 s .co m f.add(new JScrollPane(table)); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); model.addColumn("Col1"); model.addRow(new Object[] { "r1" }); model.addRow(new Object[] { "r2" }); model.addRow(new Object[] { "r3" }); // Move the last two rows to the start of the table model.moveRow(model.getRowCount() - 2, model.getRowCount() - 1, 0); JFrame f = new JFrame(); f.setSize(300, 300);/*from w w w .j a v a 2s .com*/ f.add(new JScrollPane(table)); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); model.addColumn("Col1"); model.addRow(new Object[] { "r1" }); model.addRow(new Object[] { "r2" }); model.addRow(new Object[] { "r3" }); // Move the first two rows to the end of the table model.moveRow(0, 1, model.getRowCount() - 2); JFrame f = new JFrame(); f.setSize(300, 300);/*from ww w . jav a 2 s . c o m*/ f.add(new JScrollPane(table)); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); model.addColumn("Col1"); model.addRow(new Object[] { "r1" }); model.addRow(new Object[] { "r2" }); model.addRow(new Object[] { "r3" }); // Move the first row to the end of the table model.moveRow(0, 0, model.getRowCount() - 1); JFrame f = new JFrame(); f.setSize(300, 300);//from w ww . ja v a2 s . c o m f.add(new JScrollPane(table)); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); // Create some data model.addColumn("Col1"); model.addRow(new Object[] { "r1" }); model.addRow(new Object[] { "r2" }); model.addRow(new Object[] { "r3" }); model.removeRow(model.getRowCount() - 1); JFrame f = new JFrame(); f.setSize(300, 300);//from w w w .j a v a2 s.c om f.add(new JScrollPane(table)); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); model.addColumn("Col1"); model.addColumn("Col2"); // Create the first row model.insertRow(0, new Object[] { "r1" }); // Append a row model.insertRow(model.getRowCount(), new Object[] { "r5" }); JFrame f = new JFrame(); f.setSize(300, 300);//from w w w .j a v a2s .c om f.add(new JScrollPane(table)); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); model.addColumn("Col1"); model.addColumn("Col2"); // Create the first row model.insertRow(0, new Object[] { "r1" }); // Insert a row at position p int p = 1;/*from www .j av a 2 s. c om*/ model.insertRow(p, new Object[] { "r3" }); JFrame f = new JFrame(); f.setSize(300, 300); f.add(new JScrollPane(table)); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); model.addColumn("Col1"); model.addColumn("Col2"); model.addRow(new Object[] { "v1", "v2" }); model.addRow(new Object[] { "v1" }); model.addRow(new Object[] { "v1", "v2", "v3" }); JFrame f = new JFrame(); f.setSize(300, 300);// w w w .j av a2 s . com f.add(new JScrollPane(table)); f.setVisible(true); }
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 av a2s. c o m Arrays.sort(colData, new ColumnSorter()); for (int i = 0; i < colData.length; i++) { ((Vector) data.get(i)).set(0, colData[i]); } model.fireTableStructureChanged(); }