List of usage examples for javax.swing.table DefaultTableModel insertRow
public void insertRow(int row, Object[] rowData)
row
in the model. 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" }); JFrame f = new JFrame(); f.setSize(300, 300);//from www. ja v 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.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 av 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.addColumn("Col2"); // Create the first row model.insertRow(0, new Object[] { "r1" }); // Insert a row at position p int p = 1;/*from w w w .jav a 2s .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 args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultTableModel model = new DefaultTableModel(); model.setColumnIdentifiers(new Object[] { "Column 1", "Column 2", "Column 3" }); JTable table = new JTable(model); for (int count = 0; count < 3; count++) { model.insertRow(count, new Object[] { count, "name", "age" }); }/*from w ww. ja v a 2 s .c o m*/ table.setRowHeight(1, 30); frame.add(new JScrollPane(table)); frame.setLocationByPlatform(true); frame.pack(); frame.setVisible(true); }
From source file:de.main.sessioncreator.ReportingHelper.java
public DefaultTableModel getTableModel() { charterMap.clear();//from w w w. j a v a 2s. c om getCharterBackgroundW(directory); Set<String> keys = charterMap.keySet(); String col[] = { "Charter", "Number of Testsessions" }; DefaultTableModel model = new DefaultTableModel(null, col) { @Override public boolean isCellEditable(int row, int column) { return false; } }; for (String k : keys) { model.insertRow(0, new Object[] { k, charterMap.get(k) }); } return model; }
From source file:ExtendedDnDDemo.java
protected void importString(JComponent c, String str) { JTable target = (JTable) c; DefaultTableModel model = (DefaultTableModel) target.getModel(); int index = target.getSelectedRow(); //Prevent the user from dropping data back on itself. //For example, if the user is moving rows #4,#5,#6 and #7 and //attempts to insert the rows after row #5, this would //be problematic when removing the original rows. //So this is not allowed. if (rows != null && index >= rows[0] - 1 && index <= rows[rows.length - 1]) { rows = null;/*from ww w .j a v a 2 s . c o m*/ return; } int max = model.getRowCount(); if (index < 0) { index = max; } else { index++; if (index > max) { index = max; } } addIndex = index; String[] values = str.split("\n"); addCount = values.length; int colCount = target.getColumnCount(); for (int i = 0; i < values.length && i < colCount; i++) { model.insertRow(index++, values[i].split(",")); } }
From source file:motor.part.MainPanel.java
private void update_Cart_Table(Product_Class p, int rowI, DefaultTableModel t_model) { t_model.insertRow(rowI, new Object[] { p.getType_ID(), p.getNameString(), p.getQuantity() }); }
From source file:motor.part.MainPanel.java
private void fill_table3(ResultSet rs, DefaultTableModel model) throws SQLException { int present_row = 0; do {//from w ww . j a v a2 s. c o m String n1 = rs.getString(1); String n2 = rs.getString(2); String n3 = rs.getString(3); String n4 = rs.getString(4); String n5 = rs.getString(5); String n8 = rs.getString(8); //Object[][]data={{n,e}}; // This will add row from the DB as the last row in the JTable. model.insertRow(present_row, new Object[] { n8, n1, n4, n5 }); present_row++; } while (rs.next()); }
From source file:motor.part.MainPanel.java
private void fill_table2(ResultSet rs, int row, DefaultTableModel model) throws SQLException { int present_row = row; do {/* w w w . j av a 2 s .c o m*/ String n1 = rs.getString(1); String n2 = rs.getString(2); String n3 = rs.getString(3); String n4 = rs.getString(4); String n7 = rs.getString(7); String n8 = rs.getString(8); //Object[][]data={{n,e}}; // This will add row from the DB as the last row in the JTable. model.insertRow(present_row, new Object[] { n1, n2, n8, n4, n3, n7 }); present_row++; } while (rs.next()); }
From source file:motor.part.MainPanel.java
private void fill_table21(ResultSet rs, int row, DefaultTableModel model) throws SQLException { int present_row = row; double total = 0; int quantity = 0; do {/*from www.jav a 2 s . c o m*/ String n1 = rs.getString(1); String n2 = rs.getString(2); String n3 = rs.getString(3); String n4 = rs.getString(4); String n5 = rs.getString(5); total += Double.parseDouble(n4); quantity += Integer.parseInt(n3); String name = ""; st1 = conn.createStatement(); reslt = st1.executeQuery( "SELECT * FROM Inventory WHERE Type = '" + Product_Field.getText().trim() + "' ;"); if (reslt.next()) name = reslt.getString(2); model.insertRow(present_row, new Object[] { n1, n2, name, n3, n4, n5 }); present_row++; } while (rs.next()); model.insertRow(present_row, new Object[] { "Quantity Total :", quantity, "", "", "Total :", total }); }