List of usage examples for javax.swing JTable getModel
public TableModel getModel()
From source file:Main.java
/** * Save the contents of a table to a TSV file * Note: uses toString() on the header cells as well as the data cells. If you've got funny columns, * expect funny behavior// w w w .j a va2 s .co m * @param table * @param outFile * @throws IOException */ public static void SaveTableAsTSV(JTable table, File outFile) throws IOException { PrintWriter outPW = new PrintWriter(outFile); TableModel tableModel = table.getModel(); TableColumnModel columnModel = table.getColumnModel(); StringBuffer headerLineBuf = new StringBuffer(); for (int i = 0; i < columnModel.getColumnCount(); i++) { if (i > 0) headerLineBuf.append("\t"); headerLineBuf.append(columnModel.getColumn(i).getHeaderValue().toString()); } outPW.println(headerLineBuf.toString()); outPW.flush(); for (int i = 0; i < tableModel.getRowCount(); i++) { StringBuffer lineBuf = new StringBuffer(); for (int j = 0; j < tableModel.getColumnCount(); j++) { if (j > 0) lineBuf.append("\t"); lineBuf.append(tableModel.getValueAt(i, j).toString()); } outPW.println(lineBuf.toString()); outPW.flush(); } outPW.close(); }
From source file:Main.java
/** * Selects a the specified row in the specified JTable and scrolls * the specified JScrollpane to the newly selected row. More importantly, * the call to repaint() delayed long enough to have the table * properly paint the newly selected row which may be offscre * @param table should belong to the specified JScrollPane *//*w ww.j a v a2s . c om*/ public static void selectRow(int row, JTable table, JScrollPane pane) { if (table == null || pane == null) { return; } if (contains(row, table.getModel()) == false) { return; } moveAdjustable(row * table.getRowHeight(), pane.getVerticalScrollBar()); selectRow(row, table.getSelectionModel()); // repaint must be done later because moveAdjustable // posts requests to the swing thread which must execute before // the repaint logic gets executed. repaintLater(table); }
From source file:MainClass.java
public static JScrollPane createPagingScrollPaneForTable(JTable jt) { JScrollPane jsp = new JScrollPane(jt); TableModel tmodel = jt.getModel(); if (!(tmodel instanceof PagingModel)) { return jsp; }//ww w . j a v a2 s .c o m final PagingModel model = (PagingModel) tmodel; final JButton upButton = new JButton("UP"); upButton.setEnabled(false); final JButton downButton = new JButton("DOWN"); if (model.getPageCount() <= 1) { downButton.setEnabled(false); } upButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { model.pageUp(); if (model.getPageOffset() == 0) { upButton.setEnabled(false); } downButton.setEnabled(true); } }); downButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { model.pageDown(); if (model.getPageOffset() == (model.getPageCount() - 1)) { downButton.setEnabled(false); } upButton.setEnabled(true); } }); jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); jsp.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, upButton); jsp.setCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER, downButton); return jsp; }
From source file:MainWindowLogic.java
static void addRowToTable(JTable where) { DefaultTableModel tmp = (DefaultTableModel) where.getModel(); int acutalsize = tmp.getRowCount(); acutalsize++;/* ww w .j av a 2 s . co m*/ tmp.addRow(new Object[] { acutalsize + ".", 0.0, 0.0, false }); }
From source file:MainWindowLogic.java
static private void ponumerujWiersze(JTable where) { DefaultTableModel tmp = (DefaultTableModel) where.getModel(); for (int i = 0; i < tmp.getRowCount(); i++) { String val = (i + 1) + "."; tmp.setValueAt(val, i, 0); }//from w w w. j av a2s . c o m }
From source file:MainWindowLogic.java
static void inputValuesIntoTableFromDataForwarder(Point2D[] pointsCollection, JTable jTabela) { DefaultTableModel tmp = (DefaultTableModel) jTabela.getModel(); for (Point2D point : pointsCollection) { tmp.addRow(new Object[] { (tmp.getRowCount() + 1) + ".", point.getX(), point.getY(), false }); }// ww w. j a v a 2s . c o m }
From source file:FindHullWindowLogic.java
static public void fullfilTableWithConvexHull(JTable jTableDest, ArrayList<Point2D> convexHull) { DefaultTableModel jTableDestModel = (DefaultTableModel) jTableDest.getModel(); jTableDestModel.setRowCount(0);//w w w.jav a 2 s.co m int i = 1; for (Point2D onePoint : convexHull) { if (i != 1 && areTheSamePoints(onePoint, convexHull.get(0))) break; jTableDestModel.addRow(new Object[] { i + ".", onePoint.getX(), onePoint.getY() }); i++; } }
From source file:MainWindowLogic.java
static void deleteSelectedRow(JTable where) { DefaultTableModel tmp = (DefaultTableModel) where.getModel(); System.out.println("Wielko tabeli przed usuniciem: " + tmp.getRowCount()); for (int i = 0; i < tmp.getRowCount(); i++) { boolean result = (boolean) tmp.getValueAt(i, 3); if (result) { tmp.removeRow(i);/*w ww .ja v a 2s.co m*/ i--; } } System.out.println("Wielko tabeli po usuniciu: " + tmp.getRowCount()); //TODO naprawi numeracje tabeli ponumerujWiersze(where); }
From source file:MainWindowLogic.java
private static void deleteDuplicatsFromTable(JTable jTable) { DefaultTableModel tmp = (DefaultTableModel) jTable.getModel(); boolean somethingChange = false; for (int i = 0; i < tmp.getRowCount(); i++) { for (int j = i + 1; j < tmp.getRowCount(); j++) { if (((double) tmp.getValueAt(i, 1) == (double) tmp.getValueAt(j, 1)) && ((double) tmp.getValueAt(i, 2) == (double) tmp.getValueAt(j, 2))) { tmp.removeRow(j);/*from w w w .jav a2 s . c o m*/ j--; somethingChange = true; } } } if (somethingChange) { ponumerujWiersze(jTable); } }
From source file:MainWindowLogic.java
static private void addPointsToSeries(XYSeries seriesDestination, JTable jTableSource) { DefaultTableModel defaultModelOfJTable = (DefaultTableModel) jTableSource.getModel(); for (int i = 0; i < defaultModelOfJTable.getRowCount(); i++) { seriesDestination.add((double) defaultModelOfJTable.getValueAt(i, 1), (double) defaultModelOfJTable.getValueAt(i, 2)); }/*from w w w. j a va2s . c om*/ }