List of usage examples for javax.swing.table DefaultTableModel getRowCount
public int getRowCount()
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 ww . j a va 2 s . 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(); }
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 ww 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 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 w w .j av a 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); // 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 ww. ja v a 2s . 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.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 va 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);// w w w .java2 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 first row to the end of the table model.moveRow(0, 0, model.getRowCount() - 1); JFrame f = new JFrame(); f.setSize(300, 300);/* ww w. ja 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 first two rows to the end of the table model.moveRow(0, 1, model.getRowCount() - 2); JFrame f = new JFrame(); f.setSize(300, 300);/* ww w .j a v a2 s. c o m*/ f.add(new JScrollPane(table)); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { int maximum = 100; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Integer[] oneRow = { 0, 0, 0, 0 }; String[] headers = { "A", "B", "C", "D" }; Integer[][] data = { oneRow, oneRow, oneRow, oneRow, oneRow, }; DefaultTableModel model = new DefaultTableModel(data, headers); JTable table = new JTable(model); table.setDefaultRenderer(Object.class, new ProgressRenderer(0, maximum)); table.setPreferredScrollableViewportSize(table.getPreferredSize()); frame.add(new JScrollPane(table)); frame.pack();//from w w w. j ava 2s. com frame.setVisible(true); new Thread(new Runnable() { @Override public void run() { Object waiter = new Object(); synchronized (waiter) { int rows = model.getRowCount(); int columns = model.getColumnCount(); Random random = new Random(System.currentTimeMillis()); boolean done = false; while (!done) { int row = random.nextInt(rows); int column = random.nextInt(columns); Integer value = (Integer) model.getValueAt(row, column); value++; if (value <= maximum) { model.setValueAt(value, row, column); try { waiter.wait(15); } catch (InterruptedException e) { e.printStackTrace(); } } done = true; for (row = 0; row < rows; row++) { for (column = 0; column < columns; column++) { if (!model.getValueAt(row, column).equals(maximum)) { done = false; break; } } if (!done) { break; } } } } } }).start(); }
From source file:Main.java
public static void clearAllRows(JTable table) { DefaultTableModel tableModel = (DefaultTableModel) table.getModel(); int rowCount = tableModel.getRowCount(); for (int i = 0; i < rowCount; i++) { tableModel.removeRow(rowCount - i - 1); }//w w w . j a v a 2 s . c om }