List of usage examples for javax.swing.table DefaultTableModel getValueAt
public Object getValueAt(int row, int column)
row
and column
. From source file:graph.plotter.BarMenu.java
/** * This method works for showing clicked data in textFields * @param evt /*w ww .j a v a2 s . c o m*/ */ private void TableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TableMouseClicked // TODO add your handling codejhkjnuk here: DefaultTableModel model = (DefaultTableModel) Table.getModel(); jTextField1.setText(model.getValueAt(Table.getSelectedRow(), 0).toString()); jTextField2.setText(model.getValueAt(Table.getSelectedRow(), 1).toString()); }
From source file:com.emr.mappings.MappingsForm.java
/** * Method to get the contents of a {@link JTable} as an array * @param table {@link JTable} The table to be parsed * @return {@link Object[][]} A multidimensional array *//*from ww w . j a va2 s . co m*/ public Object[][] getTableData(JTable table) { DefaultTableModel dtm = (DefaultTableModel) table.getModel(); int nRow = dtm.getRowCount(), nCol = dtm.getColumnCount(); Object[][] tableData = new Object[nRow][nCol]; for (int i = 0; i < nRow; i++) for (int j = 0; j < nCol; j++) { if (dtm.getValueAt(i, j) != null) { tableData[i][j] = dtm.getValueAt(i, j); } } return tableData; }
From source file:Software_Jframes.chart.java
void print_pdf_report(JTable jTable5) { Access ac = new Access(); try {/* ww w . j av a 2 s .c o m*/ String filename = ac.chooseFile(); com.itextpdf.text.Document document = new com.itextpdf.text.Document(); PdfWriter.getInstance(document, new FileOutputStream(filename + ".pdf")); document.open(); document.add(new Paragraph("")); Image image1 = Image.getInstance("src/images/ROPA_Logo_without_claim.jpg"); document.add(new Paragraph("")); image1.scaleAbsolute(80, 50); image1.setAbsolutePosition(50, 800); document.add(image1); PdfPTable table = new PdfPTable(3); // 3 columns. DefaultTableModel dtm = (DefaultTableModel) jTable5.getModel(); Vector v = new Vector(); int count_row = dtm.getRowCount(); int count_col = dtm.getColumnCount(); for (int i = 0; i < count_row; i++) { for (int j = 0; j < count_col; j++) { table.addCell(new PdfPCell(new Paragraph(dtm.getValueAt(i, j) + ""))); } } table.setWidthPercentage(100); float[] columnWidths = { 2f, 1f, 1f }; table.setWidths(columnWidths); document.add(table); document.close(); JOptionPane.showMessageDialog(null, "Successfully Created."); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.mirth.connect.client.ui.RegexAttachmentDialog.java
private void closeButtonActionPerformed(ActionEvent evt) { attachmentHandlerProperties.getProperties().put("regex.pattern", regexTextField.getText()); attachmentHandlerProperties.getProperties().put("regex.mimetype", mimeTypeField.getText()); DefaultTableModel inboundTableModel = (DefaultTableModel) inboundReplacementTable.getModel(); for (int row = 0; row < inboundTableModel.getRowCount(); row++) { String replaceKey = (String) inboundTableModel.getValueAt(row, 0); String replaceValue = (String) inboundTableModel.getValueAt(row, 1); attachmentHandlerProperties.getProperties().put("regex.replaceKey" + row, replaceKey); attachmentHandlerProperties.getProperties().put("regex.replaceValue" + row, replaceValue); }/*w w w .j av a2s. c om*/ DefaultTableModel outboundTableModel = (DefaultTableModel) outboundReplacementTable.getModel(); for (int row = 0; row < outboundTableModel.getRowCount(); row++) { String replaceKey = (String) outboundTableModel.getValueAt(row, 0); String replaceValue = (String) outboundTableModel.getValueAt(row, 1); attachmentHandlerProperties.getProperties().put("outbound.regex.replaceKey" + row, replaceKey); attachmentHandlerProperties.getProperties().put("outbound.regex.replaceValue" + row, replaceValue); } attachmentHandlerProperties = null; this.dispose(); }
From source file:maltcms.ui.fileHandles.csv.CSV2JFCLoader.java
private int[] getRanksDescending(DefaultTableModel dtm, int column) { int rows = dtm.getRowCount(); int[] ranks = new int[rows]; List<Tuple2D<Double, Integer>> valueToIndex = new ArrayList<>(); for (int i = 0; i < rows; i++) { Object o = dtm.getValueAt(i, column); if (o instanceof Double) { Double d = (Double) o; valueToIndex.add(new Tuple2D<>(d, i)); } else if (o instanceof String) { Double d = Double.parseDouble((String) o); valueToIndex.add(new Tuple2D<>(d, i)); }//from w w w . j av a 2 s . c om } Collections.sort(valueToIndex, new Comparator<Tuple2D<Double, Integer>>() { @Override public int compare(Tuple2D<Double, Integer> t, Tuple2D<Double, Integer> t1) { return t.getFirst().compareTo(t1.getFirst()); } }); for (int i = 0; i < ranks.length; i++) { ranks[i] = valueToIndex.get(i).getSecond(); } return ranks; }
From source file:userInterface.SystemAdmin.PovertyAnalysisJPanel.java
private void downloadPDFJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downloadPDFJButtonActionPerformed Document document = new Document(); try {// w ww. ja v a 2s. c o m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("AddTableExample.pdf")); document.open(); Font helveticaBold = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.NORMAL, new GrayColor(1)); Font helveticaNormal = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL, new GrayColor(1)); Paragraph paragraphOne = new Paragraph("Safety Meter Report", helveticaBold); document.add(paragraphOne); document.add(new Paragraph(" ")); DefaultTableModel model = (DefaultTableModel) povertyJTable.getModel(); int numRows = model.getRowCount(); int numColum = model.getColumnCount(); int i, j = 0; for (i = 0; i < numRows; i++) { Paragraph info = new Paragraph("Network Name is " + model.getValueAt(i, 0), helveticaNormal); Paragraph sectionContent3 = new Paragraph( "Average Income of A Person is $" + model.getValueAt(i, 2), helveticaNormal); info.add(sectionContent3); Paragraph sectionContent1 = new Paragraph("Crime Rate is " + model.getValueAt(i, 6) + "%", helveticaNormal); info.add(sectionContent1); Paragraph sectionContent2 = new Paragraph("Poverty Rate is " + model.getValueAt(i, 4) + "%", helveticaNormal); info.add(sectionContent2); Paragraph sectionContent4 = new Paragraph( "Percentage of People Having FireArms " + model.getValueAt(i, 3) + "%", helveticaNormal); info.add(sectionContent4); document.add(info); Paragraph space = new Paragraph(" ", helveticaNormal); document.add(space); } //document.add(table); document.close(); writer.close(); JOptionPane.showMessageDialog(povertyJTable, "Please visit Downloads folder to view your report"); } catch (Exception e) { JOptionPane.showMessageDialog(povertyJTable, e); } }
From source file:maltcms.ui.fileHandles.csv.CSV2JFCLoader.java
private DefaultTableModel sortByRows(DefaultTableModel dtm, int[] permutation) { Object[][] modelByRows = new Object[dtm.getRowCount()][dtm.getColumnCount()]; for (int i = 0; i < dtm.getRowCount(); i++) { modelByRows[i] = new Object[dtm.getColumnCount()]; for (int j = 0; j < dtm.getColumnCount(); j++) { Object o = dtm.getValueAt(permutation[i], j); //if(o instanceof Double) { modelByRows[i][j] = o;/*from ww w.j a va 2 s. c om*/ //} } } Object[] names = new Object[dtm.getRowCount()]; for (int i = 0; i < dtm.getRowCount(); i++) { names[i] = dtm.getColumnName(permutation[i]); } Logger.getLogger(getClass().getName()).log(Level.INFO, "Table model has {0} rows and {1} columns with {2} labels", new Object[] { modelByRows.length, modelByRows[0].length, names.length }); return new DefaultTableModel(modelByRows, names); }
From source file:maltcms.ui.fileHandles.csv.CSV2JFCLoader.java
private DefaultTableModel sortByColumns(DefaultTableModel dtm, int[] permutation) { Object[][] modelByRows = new Object[dtm.getRowCount()][dtm.getColumnCount()]; for (int i = 0; i < dtm.getRowCount(); i++) { modelByRows[i] = new Object[dtm.getColumnCount()]; for (int j = 0; j < dtm.getColumnCount(); j++) { Object o = dtm.getValueAt(i, permutation[j]); //if(o instanceof Double) { modelByRows[i][j] = o;//from www .j a v a2s. co m //} } } Object[] names = new Object[dtm.getRowCount()]; for (int i = 0; i < dtm.getRowCount(); i++) { names[i] = dtm.getColumnName(permutation[i]); } Logger.getLogger(getClass().getName()).log(Level.INFO, "Table model has {0} rows and {1} columns with {2} labels", new Object[] { modelByRows.length, modelByRows[0].length, names.length }); return new DefaultTableModel(modelByRows, names); }
From source file:com.stanley.captioner.MainFrame.java
private void addButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_addButtonActionPerformed {//GEN-HEADEREND:event_addButtonActionPerformed JFileChooser fileChooser = new JFileChooser(); fileChooser.setMultiSelectionEnabled(true); FileNameExtensionFilter filter = new FileNameExtensionFilter("MP4 VIDEOS", "mp4", "mpeg"); fileChooser.setFileFilter(filter);/*from w w w.j av a 2s. c o m*/ if (lastAddDirectory != null) { fileChooser.setCurrentDirectory(lastAddDirectory); } int returnValue = fileChooser.showOpenDialog(this); if (returnValue == JFileChooser.APPROVE_OPTION) { lastAddDirectory = fileChooser.getCurrentDirectory(); DefaultTableModel model = (DefaultTableModel) videoTable.getModel(); File files[] = fileChooser.getSelectedFiles(); for (File file : files) { boolean alreadyExists = false; for (int i = model.getRowCount() - 1; i >= 0; i--) { String path = (String) model.getValueAt(i, 0); if (file.getAbsolutePath().equals(path)) { alreadyExists = true; } } if (!alreadyExists) { model.addRow(getVideoInfo(file)); } } } }
From source file:Import.pnl_import_vcf.java
public Object[] getMapPair(DefaultTableModel model) { ArrayList<String> list1 = new ArrayList<>(); ArrayList<String> list2 = new ArrayList<>(); for (int i = 0; i < model.getRowCount(); i++) { list1.add(model.getValueAt(i, 0).toString()); list2.add(model.getValueAt(i, 1).toString()); }//from w w w . j ava2 s . com String[] array1 = list1.toArray(new String[list1.size()]); String[] array2 = list2.toArray(new String[list2.size()]); Object[] o = { array1, array2 }; return o; }