List of usage examples for javax.swing.table DefaultTableModel getRowCount
public int getRowCount()
From source file:com.qualixium.executor.command.CommandHelper.java
public static JsonNode getJsonNodeFromCommandsModel(DefaultTableModel model) { ArrayNode jsonArray = MAPPER.createArrayNode(); for (int i = 0; i < model.getRowCount(); i++) { ObjectNode jsonNode = MAPPER.createObjectNode(); String name = (String) model.getValueAt(i, 0); String command = ((String) model.getValueAt(i, 1)).replace("\\", "\\\\"); jsonNode.put(model.getColumnName(0), name); jsonNode.put(model.getColumnName(1), command); jsonArray.add(jsonNode);// w w w. j a v a2 s . c o m } return jsonArray; }
From source file:at.nullpointer.trayrss.gui.tablemodel.TableModelFactory.java
public static Set<Feed> retrieveFeeds(TableModel model) { DefaultTableModel dtm = (DefaultTableModel) model; int rowCount = dtm.getRowCount(); FeedRepository feedRepository = ReferenceCollection.getInstance().getContext().getBean("feedRepository", FeedRepository.class); Set<Feed> result = new HashSet<Feed>(); for (int row = 0; row < rowCount; row++) { Feed erg = null;/*from w w w.j a v a 2 s .co m*/ String valueAt = (String) dtm.getValueAt(row, TableColumnUtil.FEED_URL); if (StringUtils.isNotEmpty(valueAt)) { erg = feedRepository.retrieveFeed(valueAt); } if (erg == null) { erg = new Feed(); } erg.setName((String) dtm.getValueAt(row, TableColumnUtil.FEED_NAME)); erg.setUrl((String) dtm.getValueAt(row, TableColumnUtil.FEED_URL)); erg.setIntervall((Long) dtm.getValueAt(row, TableColumnUtil.INTERVALL)); erg.setMonitored((Boolean) dtm.getValueAt(row, TableColumnUtil.MONITORED)); Date noAction = new Date(0); erg.setLastAction(noAction); result.add(erg); } return result; }
From source file:MainWindowLogic.java
static void addRowToTable(JTable where) { DefaultTableModel tmp = (DefaultTableModel) where.getModel(); int acutalsize = tmp.getRowCount(); acutalsize++;/*from ww w.j a va2 s . c om*/ 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); }// w ww .j a va2s . co m }
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. ja va 2s .c o m*/ }
From source file:MainWindowLogic.java
static Point2D[] rewritePointsTableWitoutDuplicats(JTable jTable1) { deleteDuplicatsFromTable(jTable1);// w w w .java2 s . c o m DefaultTableModel tmp = (DefaultTableModel) jTable1.getModel(); Point2D[] rewritedTableFromTable = new Point2D[tmp.getRowCount()]; for (int i = 0; i < rewritedTableFromTable.length; i++) { rewritedTableFromTable[i] = new Point2D.Double((double) tmp.getValueAt(i, 1), (double) tmp.getValueAt(i, 2)); } return rewritedTableFromTable; }
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 w w.j av a2 s . 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 ww w . ja va2 s. co m j--; somethingChange = true; } } } if (somethingChange) { ponumerujWiersze(jTable); } }
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 }); }// w w w. j a v a 2s . c om }
From source file:com.stam.batchmove.BatchMoveUtils.java
public static void showFilesFrame(Object[][] data, String[] columnNames, final JFrame callerFrame) { final FilesFrame filesFrame = new FilesFrame(); DefaultTableModel model = new DefaultTableModel(data, columnNames) { private static final long serialVersionUID = 1L; @Override//from w ww . j av a2 s .co m public Class<?> getColumnClass(int column) { return getValueAt(0, column).getClass(); } @Override public boolean isCellEditable(int row, int column) { return column == 0; } }; DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setHorizontalAlignment(JLabel.CENTER); final JTable table = new JTable(model); for (int i = 1; i < table.getColumnCount(); i++) { table.setDefaultRenderer(table.getColumnClass(i), renderer); } // table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setRowHeight(30); table.getTableHeader().setFont(new Font("Serif", Font.BOLD, 14)); table.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); table.setRowSelectionAllowed(false); table.getColumnModel().getColumn(0).setMaxWidth(35); table.getColumnModel().getColumn(1).setPreferredWidth(350); table.getColumnModel().getColumn(2).setPreferredWidth(90); table.getColumnModel().getColumn(2).setMaxWidth(140); table.getColumnModel().getColumn(3).setMaxWidth(90); JPanel tblPanel = new JPanel(); JPanel btnPanel = new JPanel(); tblPanel.setLayout(new BorderLayout()); if (table.getRowCount() > 15) { JScrollPane scrollPane = new JScrollPane(table); tblPanel.add(scrollPane, BorderLayout.CENTER); } else { tblPanel.add(table.getTableHeader(), BorderLayout.NORTH); tblPanel.add(table, BorderLayout.CENTER); } btnPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); filesFrame.setMinimumSize(new Dimension(800, 600)); filesFrame.setLayout(new BorderLayout()); filesFrame.add(tblPanel, BorderLayout.NORTH); filesFrame.add(btnPanel, BorderLayout.SOUTH); final JLabel resultsLabel = new JLabel(); JButton cancelBtn = new JButton("Cancel"); cancelBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { filesFrame.setVisible(false); callerFrame.setVisible(true); } }); JButton moveBtn = new JButton("Copy"); moveBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setDialogTitle("Choose target directory"); int selVal = fileChooser.showOpenDialog(null); if (selVal == JFileChooser.APPROVE_OPTION) { File selection = fileChooser.getSelectedFile(); String targetPath = selection.getAbsolutePath(); DefaultTableModel dtm = (DefaultTableModel) table.getModel(); int nRow = dtm.getRowCount(); int copied = 0; for (int i = 0; i < nRow; i++) { Boolean selected = (Boolean) dtm.getValueAt(i, 0); String filePath = dtm.getValueAt(i, 1).toString(); if (selected) { try { FileUtils.copyFileToDirectory(new File(filePath), new File(targetPath)); dtm.setValueAt("Copied", i, 3); copied++; } catch (Exception ex) { Logger.getLogger(SelectionFrame.class.getName()).log(Level.SEVERE, null, ex); dtm.setValueAt("Failed", i, 3); } } } resultsLabel.setText(copied + " files copied. Finished!"); } } }); btnPanel.add(cancelBtn); btnPanel.add(moveBtn); btnPanel.add(resultsLabel); filesFrame.revalidate(); filesFrame.setVisible(true); callerFrame.setVisible(false); }