List of usage examples for javax.swing.table DefaultTableModel getColumnCount
public int getColumnCount()
From source file:com.mirth.connect.client.ui.components.MirthTable.java
private JPopupMenu getColumnMenu() { JPopupMenu columnMenu = new JPopupMenu(); DefaultTableModel model = (DefaultTableModel) getModel(); for (int i = 0; i < model.getColumnCount(); i++) { final String columnName = model.getColumnName(i); // Get the column object by name. Using an index may not return the column object if the column is hidden TableColumnExt column = getColumnExt(columnName); // Create the menu item final JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(columnName); // Show or hide the checkbox menuItem.setSelected(column.isVisible()); menuItem.addActionListener(new ActionListener() { @Override/*from www .j ava 2s . co m*/ public void actionPerformed(ActionEvent evt) { TableColumnExt column = getColumnExt(menuItem.getText()); // Determine whether to show or hide the selected column boolean enable = !column.isVisible(); // Do not hide a column if it is the last remaining visible column if (enable || getColumnCount() > 1) { column.setVisible(enable); saveColumnOrder(); } } }); columnMenu.add(menuItem); } columnMenu.addSeparator(); JMenuItem menuItem = new JMenuItem("Restore Default"); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { restoreDefaultColumnPreferences(); } }); columnMenu.add(menuItem); return columnMenu; }
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 w w . ja va 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
@Override public void run() { CSV2TableLoader tl = new CSV2TableLoader(this.ph, this.is); DefaultTableModel dtm; try {/*from w w w .j ava2 s .c o m*/ dtm = tl.call(); if (this.mode == CHART.XY) { XYSeriesCollection cd = new XYSeriesCollection(); for (int j = 0; j < dtm.getColumnCount(); j++) { XYSeries xys = new XYSeries(dtm.getColumnName(j)); for (int i = 0; i < dtm.getRowCount(); i++) { Object o = dtm.getValueAt(i, j); try { double d = Double.parseDouble(o.toString()); xys.add(i, d); Logger.getLogger(getClass().getName()).log(Level.INFO, "Adding {0} {1} {2}", new Object[] { i, d, dtm.getColumnName(j) }); } catch (Exception e) { } } cd.addSeries(xys); } XYLineAndShapeRenderer d = new XYLineAndShapeRenderer(true, false); XYPlot xyp = new XYPlot(cd, new NumberAxis("category"), new NumberAxis("value"), d); JFreeChart jfc = new JFreeChart(this.title, xyp); jtc.setChart(jfc); Logger.getLogger(getClass().getName()).info("creating chart done"); } else if (this.mode == CHART.MATRIX) { DefaultXYZDataset cd = new DefaultXYZDataset(); Logger.getLogger(getClass().getName()).log(Level.INFO, "Name of column 0: {0}", dtm.getColumnName(0)); if (dtm.getColumnName(0).isEmpty()) { Logger.getLogger(getClass().getName()).info("Removing column 0"); dtm = removeColumn(dtm, 0); } if (dtm.getColumnName(dtm.getColumnCount() - 1).equalsIgnoreCase("filename")) { dtm = removeColumn(dtm, dtm.getColumnCount() - 1); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < dtm.getRowCount(); i++) { for (int j = 0; j < dtm.getColumnCount(); j++) { sb.append(dtm.getValueAt(i, j) + " "); } sb.append("\n"); } Logger.getLogger(getClass().getName()).log(Level.INFO, "Table before sorting: {0}", sb.toString()); // dtm = sort(dtm); StringBuilder sb2 = new StringBuilder(); for (int i = 0; i < dtm.getRowCount(); i++) { for (int j = 0; j < dtm.getColumnCount(); j++) { sb2.append(dtm.getValueAt(i, j) + " "); } sb2.append("\n"); } Logger.getLogger(getClass().getName()).log(Level.INFO, "Table after sorting: {0}", sb2.toString()); int rows = dtm.getRowCount(); int columns = dtm.getColumnCount(); Logger.getLogger(getClass().getName()).log(Level.INFO, "Storing {0} * {1} elements, {2} total!", new Object[] { columns, rows, rows * columns }); double[][] data = new double[3][(columns * rows)]; ArrayDouble.D1 dt = new ArrayDouble.D1((columns) * rows); double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; EvalTools.eqI(rows, columns, this); int k = 0; for (int i = 0; i < dtm.getRowCount(); i++) { for (int j = 0; j < dtm.getColumnCount(); j++) { Object o = dtm.getValueAt(i, j); try { double d = Double.parseDouble(o.toString()); if (d < min) { min = d; } if (d > max) { max = d; } data[0][k] = (double) i; data[1][k] = (double) j; data[2][k] = d; dt.set(k, d); k++; //System.out.println("Adding "+i+" "+d+" "+dtm.getColumnName(j)); } catch (Exception e) { } } //cd.addSeries(xys); } cd.addSeries(this.title, data); XYBlockRenderer xyb = new XYBlockRenderer(); GradientPaintScale ps = new GradientPaintScale(ImageTools.createSampleTable(256), min, max, ImageTools .rampToColorArray(new ColorRampReader().readColorRamp("res/colorRamps/bcgyr.csv"))); xyb.setPaintScale(ps); final String[] colnames = new String[dtm.getColumnCount()]; for (int i = 0; i < colnames.length; i++) { colnames[i] = dtm.getColumnName(i); } NumberAxis na1 = new SymbolAxis("category", colnames); na1.setVerticalTickLabels(false); NumberAxis na2 = new SymbolAxis("category", colnames); na1.setVerticalTickLabels(true); XYPlot xyp = new XYPlot(cd, na1, na2, xyb); xyb.setSeriesToolTipGenerator(0, new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset xyd, int i, int i1) { return "[" + colnames[xyd.getX(i, i1).intValue()] + ":" + colnames[xyd.getY(i, i1).intValue()] + "] = " + ((XYZDataset) xyd).getZValue(i, i1) + ""; } }); JFreeChart jfc = new JFreeChart(this.title, xyp); NumberAxis values = new NumberAxis("value"); values.setAutoRange(false); values.setRangeWithMargins(min, max); PaintScaleLegend psl = new PaintScaleLegend(ps, values); psl.setBackgroundPaint(jfc.getBackgroundPaint()); jfc.addSubtitle(psl); psl.setStripWidth(50); psl.setPadding(20, 20, 20, 20); psl.setHeight(200); psl.setPosition(RectangleEdge.RIGHT); jtc.setChart(jfc); } } catch (Exception ex) { Exceptions.printStackTrace(ex); } ph.finish(); }
From source file:Estadistica.VEstadistica.java
public void graficar(boolean isConcurrente, ArrayList<PaginasWeb> sitiosWeb, ArrayList<EstadisticaPalabra> tiemposPalabras, ArrayList<Resultado> resultados) { DefaultCategoryDataset barChartDatos = new DefaultCategoryDataset();// grafico de secuencial for (PaginasWeb paginas : sitiosWeb) { barChartDatos.setValue(paginas.getIncidencias(), "Sitios", paginas.getListaResultados().get(0).getTitulo()); }//w w w .java2s . com //generar los datos de las tablas DefaultTableModel modeloTablaIncidencias; if (isConcurrente == false) { modeloTablaIncidencias = (DefaultTableModel) tablaIncidenciaSec.getModel(); } else { modeloTablaIncidencias = (DefaultTableModel) tablaIncidenciaSConc.getModel(); } Object[] fila = new Object[modeloTablaIncidencias.getColumnCount()]; int cont = 0; for (EstadisticaPalabra palabra : tiemposPalabras) { fila[0] = palabra.getPalabra(); fila[1] = palabra.getTiempo(); modeloTablaIncidencias.addRow(fila); cont++; System.out.println(palabra.getPalabra()); } System.out.println(cont); // Grafico // titulo-titulo arriba JFreeChart grafico = ChartFactory.createBarChart3D("Incidencias por sitio", "Sitios", "Numero de Incidencias", barChartDatos, PlotOrientation.HORIZONTAL, false, true, false); // CategoryPlot barChartCP = grafico.getCategoryPlot(); barChartCP.setRangeGridlinePaint(Color.cyan); ChartPanel barPanel = new ChartPanel(grafico); if (isConcurrente == true) { lienzoConc.removeAll(); lienzoConc.add(barPanel, BorderLayout.CENTER); lienzoConc.validate(); } if (isConcurrente == false) { lienzoSec.removeAll(); lienzoSec.add(barPanel, BorderLayout.CENTER); lienzoSec.validate(); } }
From source file:frames.MainGUI.java
public String getTableRow(JTable j, int row) { DefaultTableModel model = (DefaultTableModel) j.getModel(); int count = model.getColumnCount(); String s = ""; for (int i = 0; i < count; i++) { s += model.getValueAt(row, i) + ","; }// w w w.ja v a2 s . c om s += "\n"; return s; }
From source file:area.math.nm.ui.GUIInterpolationJPanel.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed javax.swing.table.DefaultTableModel dtm = (javax.swing.table.DefaultTableModel) jTable1.getModel(); int nRow = dtm.getRowCount(), nCol = dtm.getColumnCount(); double[][] tableData = new double[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] = Double.parseDouble((String) dtm.getValueAt(i, j)); System.out.println(i + " " + j + " " + tableData[i][j]); } else tableData[i][j] = -100000; }/* w ww. ja v a 2s. c o m*/ int size = 0; for (int i = 0; i < 10; i++) { if (tableData[i][1] == -100000 || tableData[i][0] == -100000) break; else size++; } double[] x = new double[size]; double[] y = new double[size]; for (int i = 0; i < size; i++) { x[i] = tableData[i][0]; y[i] = tableData[i][1]; } String option = (String) jComboBox1.getSelectedItem(); Interpolation ip = new Interpolation(); double input = Double.parseDouble(jTextField1.getText()); switch (option) { case "SplineInterpolator": String result = ip.splineInterpolation(x, y, input); JOptionPane.showMessageDialog(null, result); break; default: break; } }
From source file:frames.MainGUI.java
public void writeReport() { for (int i = 0; i < REPORT_FILES.length; i++) { try {// w w w . j a v a2 s. c o m // FileWriter fw = new FileWriter(REPORT_FILES[i]); // File f = new File(REPORT_FILES[i]); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(REPORT_FILES[i]), "UTF-8")); // BufferedWriter writer = new BufferedWriter(fw); DefaultTableModel model = (DefaultTableModel) REPORT_TABLES[i].getModel(); String s = ""; for (int k = 0; k < model.getColumnCount(); k++) { s += model.getColumnName(k) + ","; } s += "\n"; int rows = model.getRowCount(); for (int j = 0; j < rows; j++) { s += this.getTableRow(REPORT_TABLES[i], j); } writer.write(s); writer.close(); } catch (Exception ex) { } } }
From source file:edu.ku.brc.specify.plugins.sgr.SGRResultsDisplay.java
private JTable createTable(DefaultTableModel resultsTableModel, final List<List<Color>> rowColors) { JTable table = new JTable(resultsTableModel) { public Component prepareRenderer(TableCellRenderer renderer, int rowIndex, int colIndex) { Component c = super.prepareRenderer(renderer, rowIndex, colIndex); final Color bgColor = isCellSelected(rowIndex, colIndex) ? getSelectionBackground() : rowColors.get(rowIndex).get(colIndex); c.setBackground(bgColor);//w w w.ja va 2s .co m return c; } }; DefaultTableCellRenderer tcr = getTableCellRenderer();//model.getRowInfoList()); for (int i = 0; i < resultsTableModel.getColumnCount(); i++) { if (resultsTableModel.getColumnClass(i) != Boolean.class) { table.setDefaultRenderer(resultsTableModel.getColumnClass(i), tcr); } } table.setCellSelectionEnabled(true); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); UIHelper.makeTableHeadersCentered(table, false); table.setDefaultRenderer(String.class, new BiColorTableCellRenderer(false)); table.setRowHeight(ROW_HEIGHT); autoResizeColWidth(table, resultsTableModel); return table; }
From source file:com.view.PortfolioManagerWindow.java
private void PMSendOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PMSendOrderActionPerformed DefaultTableModel dtm = (DefaultTableModel) PMSendOrderTable.getModel(); int nRow = dtm.getRowCount(); long currUID = 0; int nCol = dtm.getColumnCount(); Object[][] tableData = new Object[nRow][nCol]; List<SingleOrder> parsedOrders = new ArrayList(); String selectedTrader = String.valueOf(PMSelectTraderOptions.getSelectedItem()); for (int t = 0; t < traderListForBox.size(); t++) { if (traderListForBox.get(t).getUsername().equals(selectedTrader)) { currUID = traderListForBox.get(t).getU_id(); System.out.println("OUR TRADER WE ASSIGN TO IS: " + selectedTrader + " HIS ID IS: " + currUID); }/*from w w w.j a v a 2 s . co m*/ } boolean thereAreOrders = false; boolean ignoreRowFlag = false; for (int i = 0; i < nRow; i++) { for (int j = 0; j < nCol; j++) { tableData[i][j] = dtm.getValueAt(i, j); } System.out.println("Retrieved all table data"); boolean trigg = true; for (int k = 0; k < nCol; k++) { if (tableData[i][k] != null) { ignoreRowFlag = false; } else { ignoreRowFlag = true; System.out.println("IGNORING EMPTY ROW"); } } //double check symbol is not null if (ignoreRowFlag == false) { if (tableData[i][2] == null) { trigg = false; } else if (tableData[i][2].toString().trim().equals("")) { showMessageDialog(null, "Please enter non-empty Symbol."); trigg = false; } else if (!(tableData[i][2].toString().trim() .equals(tableData[i][2].toString().trim().toUpperCase()))) { showMessageDialog(null, "Please enter the Symbol in all capital letters."); trigg = false; } if (tableData[i][0] != null && tableData[i][1] != null && tableData[i][2] != null && tableData[i][3] != null && tableData[i][4] != null && tableData[i][5] != null) { if (tableData[i][0] != null) { long portIDC = (long) tableData[i][0]; if (portIDC < 0) { showMessageDialog(null, "You have entered a negative portfolio ID value. Please fix this value before submitting the order."); trigg = false; } } if (tableData[i][3] != null) { int quantityC = (int) tableData[i][3]; if (quantityC < 0) { showMessageDialog(null, "You have entered a negative quantity value. Please fix this value before submitting the order."); trigg = false; } } if (tableData[i][5] != null) { String orderType = (String) tableData[i][5]; switch (orderType) { case "Market": if ((tableData[i][6] != null && tableData[i][7] != null) || (tableData[i][6] != null && tableData[i][7] == null) || (tableData[i][6] == null && tableData[i][7] != null)) { showMessageDialog(null, "A market order should have neither a stop price nor a limit price."); trigg = false; } break; case "Limit": if ((tableData[i][6] != null && tableData[i][7] == null) || (tableData[i][6] != null && tableData[i][7] != null) || (tableData[i][6] == null && tableData[i][7] == null)) { showMessageDialog(null, "A limit order should have a limit price and no stop price."); trigg = false; } break; case "Stop": if ((tableData[i][6] == null && tableData[i][7] != null) || (tableData[i][6] != null && tableData[i][7] != null) || (tableData[i][6] == null && tableData[i][7] == null)) { showMessageDialog(null, "A stop order should have a stop price and no limit price."); trigg = false; } break; case "Stop Limit": if ((tableData[i][6] == null && tableData[i][7] == null) || (tableData[i][6] != null && tableData[i][7] == null) || (tableData[i][6] == null && tableData[i][7] != null)) { showMessageDialog(null, "A Stop Limit order should have both a stop price and a limit price."); trigg = false; } break; default: showMessageDialog(null, "Something messed up in cases for order type."); } } if (tableData[i][6] != null) { double stopC = (double) tableData[i][6]; if (stopC < 0) { showMessageDialog(null, "You have entered a negative stop price value. Please fix this value before submitting the order."); trigg = false; } } if (tableData[i][7] != null) { double limitC = (double) tableData[i][7]; if (limitC < 0) { showMessageDialog(null, "You have entered a negative limit price value. Please fix this value before submitting the order."); trigg = false; } } if (trigg == true) { thereAreOrders = true; SingleOrder o = new SingleOrder(tableData[i]); parsedOrders.add(o); } } else { String a, b, c, d, e, f; if (tableData[i][0] == null) { a = "Portfolio ID"; } else { a = ""; } if (tableData[i][1] == null) { b = "Stock Exchange"; } else { b = ""; } if (tableData[i][2] == null || tableData[i][2].toString().trim().equals("")) { c = "Symbol"; } else { c = ""; } if (tableData[i][3] == null) { d = "Quantity"; } else { d = ""; } if (tableData[i][4] == null) { e = "Action"; } else { e = ""; } if (tableData[i][5] == null) { f = "Order Type"; } else { f = ""; } showMessageDialog(null, "You need to fill in the necessary fields before sending the order:\n" + a + "\n" + b + "\n" + c + "\n" + d + "\n" + e + "\n" + f); } } } if (thereAreOrders) { showMessageDialog(null, "You have successfully sent your trades."); dtm.setRowCount(0); dtm.addRow(new Object[] { null, null, null, null, null, null, null, null, null }); Order toSend = new Order(selectedTrader, parsedOrders); toSend.setAssignedTo(currUID); Long currID = CMAIN.reportUser().getU_id(); String currUname = CMAIN.reportUser().getUsername(); toSend.setPmId(currID); toSend.setPmUsername(currUname); ControllerPMCreatedOrders.handleOrder(toSend); } }
From source file:dataviewer.DataViewer.java
private void transpose(DefaultTableModel model) { try {// w w w . j a va2s . c o m if (model.getColumnCount() == 0) { return; } DefaultTableModel new_model = new DefaultTableModel(); // if not transposed if (!model.getColumnName(0).equals("_field_") && transpose == true) { new_model.addColumn("_field_"); for (int r = 1; r <= model.getRowCount(); ++r) { new_model.addColumn("_col_" + r); } long n = 1; for (int c = 0; c < model.getColumnCount(); ++c) { Object[] s = new Object[new_model.getColumnCount()]; String colname = model.getColumnName(c); int l = 0; s[l++] = colname; for (int r = 0; r < model.getRowCount(); ++r) { s[r + l] = model.getValueAt(r, c); } new_model.addRow(s); } } if (model.getColumnName(0).equals("_field_") && transpose == false) { // if transposed for (int r = 0; r < model.getRowCount(); ++r) { new_model.addColumn(model.getValueAt(r, 0)); } List<Integer> colIdx = new ArrayList(); for (int c = 0; c < model.getColumnCount(); ++c) { if (!model.getColumnName(c).equals("_field_")) { colIdx.add(c); } } for (int c = 0; c < colIdx.size(); ++c) { Object[] s = new Object[new_model.getColumnCount()]; for (int r = 0; r < model.getRowCount(); ++r) { s[r] = model.getValueAt(r, colIdx.get(c)); } new_model.addRow(s); } } renderData(new_model); } catch (Exception e) { txt_count.setText(e.getMessage()); } }