List of usage examples for javax.swing.table DefaultTableModel addRow
public void addRow(Object[] rowData)
From source file:Main.java
public static void main(String s[]) { DefaultTableModel model = new DefaultTableModel(); model.addColumn("Col1"); model.addColumn("Col2"); model.addRow(new Object[] { "1", "v2" }); model.addRow(new Object[] { "2", "v2" }); List<String> numdata = new ArrayList<String>(); for (int count = 0; count < model.getRowCount(); count++) { numdata.add(model.getValueAt(count, 0).toString()); }//w ww. j ava 2 s .c om System.out.println(numdata); }
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);/*w ww . j ava2s . c om*/ 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);//w w w . j a v a 2 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. java 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 two rows to the end of the table model.moveRow(0, 1, model.getRowCount() - 2); JFrame f = new JFrame(); f.setSize(300, 300);// w w w . ja v a2s.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 row to the end of the table model.moveRow(0, 0, model.getRowCount() - 1); JFrame f = new JFrame(); f.setSize(300, 300);//www .j a va2 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" }); // Get all the table data Vector data = model.getDataVector(); JFrame f = new JFrame(); f.setSize(300, 300);/* ww w . j a v a 2 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); model.addColumn("Col1"); model.addRow(new Object[] { "r1" }); model.addRow(new Object[] { "r2" }); model.addRow(new Object[] { "r3" }); // Get all the table data Vector data = model.getDataVector(); // Copy the second row Vector row = (Vector) data.elementAt(1); row = (Vector) row.clone();/* ww w . ja va2s.c o m*/ 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" }); Vector data = model.getDataVector(); Vector row = (Vector) data.elementAt(1); // Overwrite the first row with the copy Vector firstRow = (Vector) data.elementAt(0); for (int i = 0; i < row.size(); i++) { firstRow.set(i, row.get(i));//from w w w . j ava 2s . c om } 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" }); Vector data = model.getDataVector(); Vector row = (Vector) data.elementAt(1); // Copy the first column int mColIndex = 0; List colData = new ArrayList(table.getRowCount()); for (int i = 0; i < table.getRowCount(); i++) { row = (Vector) data.elementAt(i); colData.add(row.get(mColIndex)); }/*from ww w. jav a 2s . c o m*/ JFrame f = new JFrame(); f.setSize(300, 300); f.add(new JScrollPane(table)); f.setVisible(true); }