List of usage examples for javax.swing JTable JTable
public JTable(final Object[][] rowData, final Object[] columnNames)
JTable
to display the values in the two dimensional array, rowData
, with column names, columnNames
. From source file:SwingDnDTest.java
public static JTable table() { Object[][] cells = { { "Mercury", 2440.0, 0, false, Color.YELLOW }, { "Venus", 6052.0, 0, false, Color.YELLOW }, { "Earth", 6378.0, 1, false, Color.BLUE }, { "Mars", 3397.0, 2, false, Color.RED }, { "Jupiter", 71492.0, 16, true, Color.ORANGE }, { "Saturn", 60268.0, 18, true, Color.ORANGE }, { "Uranus", 25559.0, 17, true, Color.BLUE }, { "Neptune", 24766.0, 8, true, Color.BLUE }, { "Pluto", 1137.0, 1, false, Color.BLACK } }; String[] columnNames = { "Planet", "Radius", "Moons", "Gaseous", "Color" }; return new JTable(cells, columnNames); }
From source file:Visuals.RingChart.java
public JPanel addAVCharts() { JPanel thisPanel = new JPanel(); thisPanel.setLayout(new BorderLayout()); int tempCriticalCount = 0, tempUpdatedCount = 0; String[][] criticalList = new String[critical][4]; String[][] updatedList = new String[low][4]; for (int i = 0; i < riskCount; i++) { if (risks[i][2].equals("Critical")) { criticalList[tempCriticalCount][0] = risks[i][0]; criticalList[tempCriticalCount][1] = risks[i][1]; criticalList[tempCriticalCount][3] = risks[i][3]; tempCriticalCount++;/*from w w w. j a v a 2 s . c o m*/ } if (risks[i][2].equals("Low")) { updatedList[tempUpdatedCount][0] = risks[i][0]; updatedList[tempUpdatedCount][1] = risks[i][1]; tempUpdatedCount++; } } JTable criticalTable = new JTable(criticalList, criticalColumns); JTable updatedTable = new JTable(updatedList, updatedColumns); TableColumn tcol = criticalTable.getColumnModel().getColumn(2); criticalTable.removeColumn(tcol); TableColumn tcol2 = updatedTable.getColumnModel().getColumn(2); updatedTable.removeColumn(tcol2); criticalTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); updatedTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); criticalTable.setEnabled(false); updatedTable.setEnabled(false); int width = 0; for (int i = 0; i < 3; i++) { for (int row = 0; row < criticalTable.getRowCount(); row++) { TableCellRenderer renderer = criticalTable.getCellRenderer(row, i); Component comp = criticalTable.prepareRenderer(renderer, row, i); width = Math.max(comp.getPreferredSize().width, width); } criticalTable.getColumnModel().getColumn(i).setPreferredWidth(width); width = 0; } for (int i = 0; i < 2; i++) { for (int row = 0; row < updatedTable.getRowCount(); row++) { TableCellRenderer renderer = updatedTable.getCellRenderer(row, i); Component comp = updatedTable.prepareRenderer(renderer, row, i); width = Math.max(comp.getPreferredSize().width, width); } updatedTable.getColumnModel().getColumn(i).setPreferredWidth(width); width = 0; } criticalTable.setShowHorizontalLines(true); criticalTable.setRowHeight(40); updatedTable.setShowHorizontalLines(true); updatedTable.setRowHeight(40); JScrollPane criticalTableScrollPane = new JScrollPane(criticalTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); JScrollPane updatedTableScrollPane = new JScrollPane(updatedTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); Dimension d = criticalTable.getPreferredSize(); criticalTableScrollPane.setPreferredSize( new Dimension((d.width - 400), (criticalTable.getRowHeight() + 1) * (tempCriticalCount + 1))); Dimension d2 = updatedTable.getPreferredSize(); updatedTableScrollPane.setPreferredSize( new Dimension((d.width - 400), (updatedTable.getRowHeight() + 1) * (tempUpdatedCount + 1))); Font titleFonts = new Font("Calibri", Font.BOLD, 30); JLabel criticalLabel = new JLabel(" Critical "); criticalLabel.setFont(titleFonts); criticalLabel.setForeground(new Color(230, 27, 27)); JPanel leftPanel = new JPanel(); leftPanel.setLayout(new BorderLayout()); leftPanel.add(criticalLabel, BorderLayout.WEST); leftPanel.add(criticalTableScrollPane, BorderLayout.CENTER); JLabel updatedLabel = new JLabel(" Updated "); updatedLabel.setFont(titleFonts); updatedLabel.setForeground(new Color(47, 196, 6)); JPanel rightPanel = new JPanel(); rightPanel.setLayout(new BorderLayout()); rightPanel.add(updatedLabel, BorderLayout.WEST); rightPanel.add(updatedTableScrollPane, BorderLayout.CENTER); if (tempCriticalCount != 0) thisPanel.add(leftPanel, BorderLayout.NORTH); if (tempUpdatedCount != 0) thisPanel.add(rightPanel, BorderLayout.SOUTH); return thisPanel; }
From source file:Visuals.BarChart.java
public JPanel addCharts() { ChartPanel barPanel = drawBarChart(); barPanel.setDomainZoomable(true);//from ww w . ja va 2 s.c o m JPanel thisBarPanel = new JPanel(); thisBarPanel.setLayout(new BorderLayout()); String[][] finalRisks = new String[riskCount][4]; for (int i = 0; i < riskCount; i++) { finalRisks[i][0] = risks[i][0]; finalRisks[i][1] = risks[i][1]; finalRisks[i][2] = risks[i][2]; finalRisks[i][3] = risks[i][3]; } JTable table = new JTable(finalRisks, columns); //table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); TableRowSorter<TableModel> sorter = new TableRowSorter<>(table.getModel()); table.setRowSorter(sorter); List<RowSorter.SortKey> sortKeys = new ArrayList<>(); int columnIndexToSort = 2; sortKeys.add(new RowSorter.SortKey(columnIndexToSort, SortOrder.ASCENDING)); sorter.setSortKeys(sortKeys); sorter.sort(); TableColumn tcol = table.getColumnModel().getColumn(2); table.removeColumn(tcol); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.getColumnModel().getColumn(1).setPreferredWidth(600); table.getColumnModel().getColumn(2).setPreferredWidth(600); table.setShowHorizontalLines(true); table.setRowHeight(40); table.setEnabled(false); JScrollPane tableScrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); Dimension d = table.getPreferredSize(); tableScrollPane .setPreferredSize(new Dimension((d.width - 400), (table.getRowHeight() + 1) * (riskCount + 1))); JLabel right = new JLabel( " "); thisBarPanel.add(right, BorderLayout.EAST); thisBarPanel.add(barPanel, BorderLayout.CENTER); thisBarPanel.add(tableScrollPane, BorderLayout.SOUTH); return thisBarPanel; }
From source file:teambootje.A2.java
public A2() { initComponents();/*from w w w .j a va 2 s.co m*/ setLocationRelativeTo(null); setLayout(new BorderLayout()); //Create and set up the window. setTitle("SS Rotterdam Analyse || Analyse 2"); ImageIcon icon = new ImageIcon("img/bootje.jpg"); setIconImage(icon.getImage()); // back BTN JButton back = new JButton("Back"); add(back, BorderLayout.NORTH); back.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); // panel en Label JPanel ana = new JPanel(); add(ana, BorderLayout.CENTER); //tabel String sql = "SELECT Datum, COUNT(*) AS Aantal FROM posts GROUP BY Datum"; List<Object[]> list = new ArrayList<Object[]>(); ResultSet rs = null; try { rs = db.runSql(sql); while (rs.next()) { String datum = rs.getString("Datum"); int aantal = rs.getInt("Aantal"); String[] row = new String[rs.getMetaData().getColumnCount()]; for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { row[i - 1] = rs.getString(i); } list.add(row); //chart JButton chart = new JButton("Chart"); add(chart, BorderLayout.SOUTH); chart.addActionListener(new ActionListener() { String dat = datum; int a1 = aantal; @Override public void actionPerformed(ActionEvent e) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue(dat, a1); pieDataset.setValue("2015-04-06", new Integer(5)); pieDataset.setValue("2015-04-05", new Integer(5)); pieDataset.setValue("2015-04-04", new Integer(14)); pieDataset.setValue("2015-04-03", new Integer(4)); pieDataset.setValue("2015-04-02", new Integer(1)); pieDataset.setValue("2015-04-01", new Integer(32)); pieDataset.setValue("2015-03-31", new Integer(32)); pieDataset.setValue("2015-03-30", new Integer(9)); pieDataset.setValue("2015-03-29", new Integer(4)); pieDataset.setValue("2015-03-28", new Integer(1)); pieDataset.setValue("2015-03-27", new Integer(3)); pieDataset.setValue("2015-03-26", new Integer(6)); pieDataset.setValue("2015-03-25", new Integer(1)); pieDataset.setValue("2015-03-24", new Integer(1)); pieDataset.setValue("2015-03-23", new Integer(1)); pieDataset.setValue("2015-03-22", new Integer(1)); pieDataset.setValue("2015-03-21", new Integer(1)); pieDataset.setValue("2015-03-20", new Integer(1)); pieDataset.setValue("2015-03-19", new Integer(1)); pieDataset.setValue("2015-03-18", new Integer(2)); pieDataset.setValue("2015-03-17", new Integer(1)); JFreeChart chart = ChartFactory.createPieChart3D("Aantal Posts per datum", pieDataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame pie = new ChartFrame("Aantal Posts per datum", chart); pie.setVisible(true); pie.setSize(500, 500); pie.setLocationRelativeTo(null); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); } } catch (SQLException e) { JOptionPane.showMessageDialog(null, e); } Object[][] array = new Object[list.size()][]; Object columnNames[] = { "Datum", "Aantal" }; list.toArray(array); JTable table = new JTable(array, columnNames); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(400, 400)); ana.add(scroll); }
From source file:org.encog.workbench.dialogs.validate.ResultValidationChart.java
private void drawTable(Vector<Vector<String>> tableData, Vector<String> tableHeaders) { JTable table = new JTable(tableData, tableHeaders) { private static final long serialVersionUID = 8364655578079933961L; public boolean isCellEditable(int rowIndex, int vColIndex) { return false; }/* ww w .j a v a2 s . co m*/ }; table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); tabs.addTab("Data", new JScrollPane(table)); }
From source file:net.adamjak.thomas.graph.application.run.TestRunner.java
private void save(Map<String, Object> results, boolean rawData) { SnarkTestTypes testType = (SnarkTestTypes) results.get("testType"); if (this.outputFile.getName().split("\\.")[this.outputFile.getName().split("\\.").length - 1].toLowerCase() .equals("ods")) { String[] columnNames;// w w w . j a va 2s . c o m Object[][] data; if (testType == SnarkTestTypes.ALL_ALGORITHMS) { GraphTestResult[][][] graphTestResult = (GraphTestResult[][][]) results.get("resultsData"); columnNames = String.valueOf("Algorithm,Graph ID,Avarage time,Standard deviation,Minimum,Maximum") .split(","); data = new Object[graphTestResult[0].length][6]; for (int cls = 0; cls < graphTestResult[0][0].length; cls++) { Class<?> c = (Class<?>) graphTestResult[0][0][cls].getValue("algorithmClass"); for (int graph = 0; graph < graphTestResult[0].length; graph++) { SummaryStatistics summaryStatistics = new SummaryStatistics(); for (int run = 0; run < graphTestResult.length; run++) { summaryStatistics .addValue((double) graphTestResult[run][graph][cls].getValue("timeInSeconds")); } data[graph][0] = c.getSimpleName(); data[graph][1] = graph; data[graph][2] = summaryStatistics.getMean(); data[graph][3] = summaryStatistics.getStandardDeviation(); data[graph][4] = summaryStatistics.getMin(); data[graph][5] = summaryStatistics.getMax(); } } } else if (testType == SnarkTestTypes.ONE_ALGORITHM_START_IN_EVERY_VERTEX) { GraphTestResult[][][] graphTestResult = (GraphTestResult[][][]) results.get("resultsData"); columnNames = String .valueOf("Graph ID,Start vertex,Avarage time,Standard deviation,Minimum,Maximum") .split(","); data = new Object[graphTestResult[0].length][6]; for (int vid = 0; vid < graphTestResult[0][0].length; vid++) { for (int graph = 0; graph < graphTestResult[0].length; graph++) { SummaryStatistics summaryStatistics = new SummaryStatistics(); for (int run = 0; run < graphTestResult.length; run++) { summaryStatistics .addValue((double) graphTestResult[run][graph][vid].getValue("timeInSeconds")); } data[graph][0] = graph; data[graph][1] = vid; data[graph][2] = summaryStatistics.getMean(); data[graph][3] = summaryStatistics.getStandardDeviation(); data[graph][4] = summaryStatistics.getMin(); data[graph][5] = summaryStatistics.getMax(); } } } else { GraphTestResult[][] graphTestResult = (GraphTestResult[][]) results.get("resultsData"); columnNames = String.valueOf("Graph ID,Avarage time,Standard deviation,Minimum,Maximum").split(","); data = new Object[graphTestResult[0].length][5]; for (int graph = 0; graph < graphTestResult[0].length; graph++) { SummaryStatistics summaryStatistics = new SummaryStatistics(); for (int run = 0; run < graphTestResult.length; run++) { summaryStatistics.addValue((double) graphTestResult[run][graph].getValue("timeInSeconds")); } data[graph][0] = graph; data[graph][1] = summaryStatistics.getMean(); data[graph][2] = summaryStatistics.getStandardDeviation(); data[graph][3] = summaryStatistics.getMin(); data[graph][4] = summaryStatistics.getMax(); } } try { SpreadSheet.createEmpty(new JTable(data, columnNames).getModel()).saveAs(outputFile); } catch (IOException e) { e.printStackTrace(); } if (rawData == true) { if (testType == SnarkTestTypes.ALL_ALGORITHMS) { GraphTestResult[][][] graphTestResult = (GraphTestResult[][][]) results.get("resultsData"); columnNames = String.valueOf("Class,Run,Graph,Time").split(","); data = new Object[graphTestResult.length * graphTestResult[0].length * graphTestResult[0][0].length][4]; int row = 0; for (int i = 0; i < graphTestResult.length; i++) { for (int j = 0; j < graphTestResult[i].length; j++) { for (int k = 0; k < graphTestResult[i][j].length; k++) { data[row][0] = graphTestResult[i][j][k].getValue("algorithmClass"); data[row][1] = i; data[row][2] = j; data[row][3] = graphTestResult[i][j][k].getValue("time"); row++; } } } } else if (testType == SnarkTestTypes.ONE_ALGORITHM_START_IN_EVERY_VERTEX) { GraphTestResult[][][] graphTestResult = (GraphTestResult[][][]) results.get("resultsData"); columnNames = String.valueOf("Run,Graph,Vertex,Time").split(","); data = new Object[graphTestResult.length * graphTestResult[0].length * graphTestResult[0][0].length][4]; int row = 0; for (int i = 0; i < graphTestResult.length; i++) { for (int j = 0; j < graphTestResult[i].length; j++) { for (int k = 0; k < graphTestResult[i][j].length; k++) { data[row][0] = i; data[row][1] = j; data[row][2] = k; data[row][3] = graphTestResult[i][j][k].getValue("time"); row++; } } } } else if (testType == SnarkTestTypes.ALGORITHM_COMPARATION) { GraphTestResult[][] graphTestResult = (GraphTestResult[][]) results.get("resultsData"); columnNames = String.valueOf("Run,Graph,Time,Class").split(","); data = new Object[graphTestResult.length * graphTestResult[0].length][4]; int row = 0; for (int i = 0; i < graphTestResult.length; i++) { for (int j = 0; j < graphTestResult[i].length; j++) { data[row][0] = i; data[row][1] = j; data[row][2] = graphTestResult[i][j].getValue("time"); data[row][3] = ((Class<?>) graphTestResult[i][j] .getValue(GraphTestResult.SNARK_TESTER_CLASS_KEY)).getSimpleName(); row++; } } } else { GraphTestResult[][] graphTestResult = (GraphTestResult[][]) results.get("resultsData"); columnNames = String.valueOf("Run,Graph,Time").split(","); data = new Object[graphTestResult.length * graphTestResult[0].length][3]; int row = 0; for (int i = 0; i < graphTestResult.length; i++) { for (int j = 0; j < graphTestResult[i].length; j++) { data[row][0] = i; data[row][1] = j; data[row][2] = graphTestResult[i][j].getValue("time"); row++; } } } try { SpreadSheet.createEmpty(new JTable(data, columnNames).getModel()).saveAs(outputFile); } catch (IOException e) { e.printStackTrace(); } } } else { StringBuilder sbData = new StringBuilder(); if (testType == SnarkTestTypes.ALL_ALGORITHMS) { GraphTestResult[][][] graphTestResult = (GraphTestResult[][][]) results.get("resultsData"); sbData.append(",,All data,,,,,Data without extremes,,,,,\n"); sbData.append( "Graph ID,Graph ID,Avarage time,Standard deviation,Minimum,Maximum,Confidence Interval,Avarage time,Standard deviation,Minimum,Maximum,Confidence Interval\n"); for (int cls = 0; cls < graphTestResult[0][0].length; cls++) { Class<?> c = (Class<?>) graphTestResult[0][0][cls].getValue("algorithmClass"); for (int graph = 0; graph < graphTestResult[0].length; graph++) { DescriptiveStatistics descriptiveStatistics = new DescriptiveStatistics(); for (int run = 0; run < graphTestResult.length; run++) { descriptiveStatistics .addValue((double) graphTestResult[run][graph][cls].getValue("timeInSeconds")); } DescriptiveStatistics descriptiveStatisticsWithoutExtremes = StatisticsUtils .statisticsWithoutExtremes(descriptiveStatistics, StatisticsUtils.GrubbsLevel.L005); sbData.append(c.getSimpleName()); sbData.append(","); sbData.append(graph); sbData.append(","); sbData.append(descriptiveStatistics.getMean()); sbData.append(","); sbData.append(descriptiveStatistics.getStandardDeviation()); sbData.append(","); sbData.append(descriptiveStatistics.getMin()); sbData.append(","); sbData.append(descriptiveStatistics.getMax()); sbData.append(","); sbData.append(StatisticsUtils.getConfidenceInterval(descriptiveStatistics, StatisticsUtils.NormCritical.U0050)); sbData.append(","); sbData.append(descriptiveStatisticsWithoutExtremes.getMean()); sbData.append(","); sbData.append(descriptiveStatisticsWithoutExtremes.getStandardDeviation()); sbData.append(","); sbData.append(descriptiveStatisticsWithoutExtremes.getMin()); sbData.append(","); sbData.append(descriptiveStatisticsWithoutExtremes.getMax()); sbData.append(","); sbData.append(StatisticsUtils.getConfidenceInterval(descriptiveStatisticsWithoutExtremes, StatisticsUtils.NormCritical.U0050)); sbData.append("\n"); } } } else if (testType == SnarkTestTypes.ONE_ALGORITHM_START_IN_EVERY_VERTEX) { GraphTestResult[][][] graphTestResult = (GraphTestResult[][][]) results.get("resultsData"); sbData.append(",,All data,,,,,Data without extremes,,,,,\n"); sbData.append( "Graph ID,Start vertex,Avarage time,Standard deviation,Minimum,Maximum,Confidence Interval,Avarage time,Standard deviation,Minimum,Maximum,Confidence Interval\n"); for (int vid = 0; vid < graphTestResult[0][0].length; vid++) { for (int graph = 0; graph < graphTestResult[0].length; graph++) { DescriptiveStatistics descriptiveStatistics = new DescriptiveStatistics(); for (int run = 0; run < graphTestResult.length; run++) { descriptiveStatistics .addValue((double) graphTestResult[run][graph][vid].getValue("timeInSeconds")); } DescriptiveStatistics descriptiveStatisticsWithoutExtremes = StatisticsUtils .statisticsWithoutExtremes(descriptiveStatistics, StatisticsUtils.GrubbsLevel.L005); sbData.append(graph); sbData.append(","); sbData.append(vid); sbData.append(","); sbData.append(descriptiveStatistics.getMean()); sbData.append(","); sbData.append(descriptiveStatistics.getStandardDeviation()); sbData.append(","); sbData.append(descriptiveStatistics.getMin()); sbData.append(","); sbData.append(descriptiveStatistics.getMax()); sbData.append(","); sbData.append(StatisticsUtils.getConfidenceInterval(descriptiveStatistics, StatisticsUtils.NormCritical.U0050)); sbData.append(","); sbData.append(descriptiveStatisticsWithoutExtremes.getMean()); sbData.append(","); sbData.append(descriptiveStatisticsWithoutExtremes.getStandardDeviation()); sbData.append(","); sbData.append(descriptiveStatisticsWithoutExtremes.getMin()); sbData.append(","); sbData.append(descriptiveStatisticsWithoutExtremes.getMax()); sbData.append(","); sbData.append(StatisticsUtils.getConfidenceInterval(descriptiveStatisticsWithoutExtremes, StatisticsUtils.NormCritical.U0050)); sbData.append("\n"); } } } else { GraphTestResult[][] graphTestResult = (GraphTestResult[][]) results.get("resultsData"); sbData.append(",All data,,,,,Data without extremes,,,,,\n"); sbData.append( "Graph ID,Avarage time,Standard deviation,Minimum,Maximum,Confidence Interval,Avarage time,Standard deviation,Minimum,Maximum,Confidence Interval\n"); for (int graph = 0; graph < graphTestResult[0].length; graph++) { DescriptiveStatistics descriptiveStatistics = new DescriptiveStatistics(); for (int run = 0; run < graphTestResult.length; run++) { descriptiveStatistics .addValue((double) graphTestResult[run][graph].getValue("timeInSeconds")); } DescriptiveStatistics descriptiveStatisticsWithoutExtremes = StatisticsUtils .statisticsWithoutExtremes(descriptiveStatistics, StatisticsUtils.GrubbsLevel.L005); sbData.append(graph); sbData.append(","); sbData.append(descriptiveStatistics.getMean()); sbData.append(","); sbData.append(descriptiveStatistics.getStandardDeviation()); sbData.append(","); sbData.append(descriptiveStatistics.getMin()); sbData.append(","); sbData.append(descriptiveStatistics.getMax()); sbData.append(","); sbData.append(StatisticsUtils.getConfidenceInterval(descriptiveStatistics, StatisticsUtils.NormCritical.U0050)); sbData.append(","); sbData.append(descriptiveStatisticsWithoutExtremes.getMean()); sbData.append(","); sbData.append(descriptiveStatisticsWithoutExtremes.getStandardDeviation()); sbData.append(","); sbData.append(descriptiveStatisticsWithoutExtremes.getMin()); sbData.append(","); sbData.append(descriptiveStatisticsWithoutExtremes.getMax()); sbData.append(","); sbData.append(StatisticsUtils.getConfidenceInterval(descriptiveStatisticsWithoutExtremes, StatisticsUtils.NormCritical.U0050)); sbData.append("\n"); } } this.saveStringIntoFile(this.outputFile, sbData.toString()); if (rawData == true) { StringBuilder sbRawData = new StringBuilder(); if (testType == SnarkTestTypes.ALL_ALGORITHMS) { GraphTestResult[][][] graphTestResult = (GraphTestResult[][][]) results.get("resultsData"); sbRawData.append("Class,Run,Graph,Time\n"); for (int i = 0; i < graphTestResult.length; i++) { for (int j = 0; j < graphTestResult[i].length; j++) { for (int k = 0; k < graphTestResult[i][j].length; k++) { sbRawData.append(graphTestResult[i][j][k].getValue("algorithmClass")); sbRawData.append(","); sbRawData.append(i); sbRawData.append(","); sbRawData.append(j); sbRawData.append(","); sbRawData.append(graphTestResult[i][j][k].getValue("time")); sbRawData.append("\n"); } } } } else if (testType == SnarkTestTypes.ONE_ALGORITHM_START_IN_EVERY_VERTEX) { GraphTestResult[][][] graphTestResult = (GraphTestResult[][][]) results.get("resultsData"); sbRawData.append("Run,Graph,Vertex,Time\n"); for (int i = 0; i < graphTestResult.length; i++) { for (int j = 0; j < graphTestResult[i].length; j++) { for (int k = 0; k < graphTestResult[i][j].length; k++) { sbRawData.append(i); sbRawData.append(","); sbRawData.append(j); sbRawData.append(","); sbRawData.append(k); sbRawData.append(","); sbRawData.append(graphTestResult[i][j][k].getValue("time")); sbRawData.append("\n"); } } } } else if (testType == SnarkTestTypes.ALGORITHM_COMPARATION) { GraphTestResult[][] graphTestResult = (GraphTestResult[][]) results.get("resultsData"); sbRawData.append("Run,Graph,Time,Class\n"); for (int i = 0; i < graphTestResult.length; i++) { for (int j = 0; j < graphTestResult[i].length; j++) { sbRawData.append(i); sbRawData.append(","); sbRawData.append(j); sbRawData.append(","); sbRawData.append(graphTestResult[i][j].getValue("time")); sbRawData.append(","); sbRawData.append(((Class<?>) graphTestResult[i][j] .getValue(GraphTestResult.SNARK_TESTER_CLASS_KEY)).getSimpleName()); sbRawData.append("\n"); } } } else { GraphTestResult[][] graphTestResult = (GraphTestResult[][]) results.get("resultsData"); sbRawData.append("Run,Graph,Time\n"); for (int i = 0; i < graphTestResult.length; i++) { for (int j = 0; j < graphTestResult[i].length; j++) { sbRawData.append(i); sbRawData.append(","); sbRawData.append(j); sbRawData.append(","); sbRawData.append(graphTestResult[i][j].getValue("time")); sbRawData.append("\n"); } } } this.saveStringIntoFile(new File(this.outputFile.getParent(), "raw_" + this.outputFile.getName()), sbRawData.toString()); } } }
From source file:org.jdal.swing.PageableTable.java
/** * Initalize component after properties set. Normally called by context va init-method */// w ww . java 2 s. co m public void init() { okIcon = FormUtils.getIcon(okIcon, "/images/16x16/dialog-ok.png"); cancelIcon = FormUtils.getIcon(cancelIcon, "/images/16x16/dialog-cancel.png"); visibilityMenuIcon = FormUtils.getIcon(visibilityMenuIcon, "/images/16x16/view-choose.png"); userMenuIcon = FormUtils.getIcon(userMenuIcon, "/images/table/16x16/users.png"); if (tableModel == null) { tableModel = new ListTableModel(); } setLayout(layout); // Server side sorter sorter = new ModelRowSorter<ListTableModel>(tableModel); sorter.addRowSorterListener(this); // configure paginator if (showPaginator) { if (paginatorView == null) { paginatorView = new PaginatorView(); paginatorView.init(); } paginatorView.setPaginator(page); page.addPaginatorListener(this); add(paginatorView.getPanel(), BorderLayout.SOUTH); } else { page.setPageSize(Integer.MAX_VALUE); } createColumnDescriptos(); table = new JTable(tableModel, tableModel.getTableColumnModel()); table.setAutoCreateRowSorter(false); table.setRowSorter(sorter); table.setRowHeight(22); table.addMouseListener(new TableListener()); tableScrollPane = new JScrollPane(table); this.setBackground(Color.WHITE); add(tableScrollPane, BorderLayout.CENTER); if (showMenu) createMenu(); page.setPageableDataSource(dataSource); // goto first page page.firstPage(); // restore table state restoreState(); }
From source file:teambootje.A9.java
/** * Creates new form A9/*from ww w . j a v a 2s .c om*/ */ public A9() { initComponents(); setLocationRelativeTo(null); setLayout(new BorderLayout()); //Create and set up the window. setTitle("SS Rotterdam Analyse || Analyse 9"); ImageIcon icon = new ImageIcon("img/bootje.jpg"); setIconImage(icon.getImage()); // back BTN JButton back = new JButton("Back"); add(back, BorderLayout.NORTH); back.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dispose(); // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); // panel en Label JPanel ana = new JPanel(); add(ana, BorderLayout.CENTER); //tabel String sql = "SELECT persoon.Name, COUNT(post) AS Aantal FROM persoon, posts WHERE persoon.AID = posts.AID GROUP BY persoon.Name"; List<Object[]> list = new ArrayList<Object[]>(); ResultSet rs = null; try { rs = db.runSql(sql); while (rs.next()) { String name = rs.getString("persoon.Name"); int amount = rs.getInt("Aantal"); String[] row = new String[rs.getMetaData().getColumnCount()]; for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) { row[i - 1] = rs.getString(i); } list.add(row); //chart JButton chart = new JButton("Chart"); add(chart, BorderLayout.SOUTH); chart.addActionListener(new ActionListener() { String n1 = name; int a1 = amount; @Override public void actionPerformed(ActionEvent e) { DefaultPieDataset pieDataset = new DefaultPieDataset(); pieDataset.setValue(n1, a1); pieDataset.setValue("WestCordHotels", new Integer(1)); pieDataset.setValue("Voetbalr", new Integer(2)); pieDataset.setValue("VeraBauman", new Integer(1)); pieDataset.setValue("TonWesselink", new Integer(2)); pieDataset.setValue("Stoomschip Rotterdam", new Integer(25)); pieDataset.setValue("shirleys86", new Integer(2)); pieDataset.setValue("SevereWeather_N", new Integer(2)); pieDataset.setValue("SalvatoreOrtisi", new Integer(4)); pieDataset.setValue("RuudvEck", new Integer(2)); pieDataset.setValue("RuudvandenBos", new Integer(1)); pieDataset.setValue("Roffa85", new Integer(1)); pieDataset.setValue("RichardPh0t0", new Integer(2)); pieDataset.setValue("RebekkaKadijk", new Integer(2)); pieDataset.setValue("ray_rademaker", new Integer(6)); pieDataset.setValue("PoushNL", new Integer(1)); pieDataset.setValue("popupsquare", new Integer(2)); pieDataset.setValue("Plan_78", new Integer(3)); pieDataset.setValue("Petrahoogenboom", new Integer(1)); pieDataset.setValue("PatriciaBenard", new Integer(2)); pieDataset.setValue("OVKatendrecht", new Integer(2)); pieDataset.setValue("OdileHemmen", new Integer(2)); pieDataset.setValue("NLMaritiem", new Integer(2)); pieDataset.setValue("Nellyvdvlies", new Integer(1)); pieDataset.setValue("meerkatting", new Integer(2)); pieDataset.setValue("MeerkatsNow", new Integer(2)); pieDataset.setValue("marygoossens1", new Integer(1)); pieDataset.setValue("MarjoleinNagel", new Integer(1)); pieDataset.setValue("MaaikeMaasdijk", new Integer(1)); pieDataset.setValue("KidsErOpUit", new Integer(2)); pieDataset.setValue("Katendrechtnr1", new Integer(25)); pieDataset.setValue("jpsoree", new Integer(2)); pieDataset.setValue("JolandaBolscher", new Integer(2)); pieDataset.setValue("jes4life", new Integer(1)); pieDataset.setValue("JaccoScheer", new Integer(1)); pieDataset.setValue("GwNpop", new Integer(2)); pieDataset.setValue("Gerarddegraaff", new Integer(1)); pieDataset.setValue("FR12Patrick", new Integer(3)); pieDataset.setValue("FlorentinaNow", new Integer(1)); pieDataset.setValue("FIVBWorldChamps", new Integer(2)); pieDataset.setValue("FIVBVolleyball", new Integer(2)); pieDataset.setValue("FeestdjNik", new Integer(1)); pieDataset.setValue("ensanne", new Integer(1)); pieDataset.setValue("elsekramer", new Integer(1)); pieDataset.setValue("EelcoBeijl", new Integer(1)); pieDataset.setValue("EdwindeKoning1", new Integer(2)); pieDataset.setValue("DMiddelman", new Integer(3)); pieDataset.setValue("de_rotterdam", new Integer(2)); pieDataset.setValue("CvanAdrighem", new Integer(2)); pieDataset.setValue("carolinedejager", new Integer(1)); pieDataset.setValue("CaatVanEnst", new Integer(1)); pieDataset.setValue("BotlekBusiness", new Integer(2)); pieDataset.setValue("AnneWallisDeVri", new Integer(2)); pieDataset.setValue("010byday", new Integer(4)); JFreeChart chart = ChartFactory.createPieChart3D("Aantal posts per personen", pieDataset, true, true, true); PiePlot3D p = (PiePlot3D) chart.getPlot(); //p.setForegroundAlpha(TOP_ALIGNMENT); ChartFrame pie = new ChartFrame("Aantal posts per personen", chart); pie.setVisible(true); pie.setSize(500, 500); pie.setLocationRelativeTo(null); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }); } } catch (SQLException e) { JOptionPane.showMessageDialog(null, e); } Object[][] array = new Object[list.size()][]; Object columnNames[] = { "Naam", "Aantal" }; list.toArray(array); JTable table = new JTable(array, columnNames); JScrollPane scroll = new JScrollPane(table); scroll.setPreferredSize(new Dimension(400, 400)); ana.add(scroll); }
From source file:Data.java
private JTable getTbleData(Statement stmt) throws SQLException, ClassNotFoundException { ResultSet rs;/*from ww w .j av a 2 s .c o m*/ String sql = "SELECT pro_name, pro_description, COUNT(sto_uid) - (SUM(sto_inout) * 2) AS NbProduit FROM t_produit, t_stock WHERE t_produit.id_produit = t_stock.id_produit GROUP BY t_produit.id_produit"; rs = stmt.executeQuery(sql); rs.last(); Object rowData[][] = new Object[rs.getRow()][3]; rs.beforeFirst(); while (rs.next()) { rowData[rs.getRow() - 1][0] = rs.getString(1); rowData[rs.getRow() - 1][1] = rs.getString(2); rowData[rs.getRow() - 1][2] = rs.getInt(3); } sql = "SELECT tmp_temperature, tmp_humidity FROM t_temphum ORDER BY tmp_date DESC LIMIT 1"; rs = stmt.executeQuery(sql); rs.first(); if (tempUnit == "C") { tempRealTime.setText("Temprature : " + rs.getDouble(1) + "" + tempUnit); } else { tempRealTime.setText("Temprature : " + celsiusToFahrenheit(rs.getString(1)) + "" + tempUnit); } humRealTime.setText("Humidit : " + rs.getDouble(2) + "%"); lastTemp = rs.getDouble(1); lastHum = rs.getDouble(2); Object columnNames[] = { "Poduit", "Description", "Quantit" }; JTable table = new JTable(rowData, columnNames); return table; }