List of usage examples for javax.swing JTable getRowCount
@BeanProperty(bound = false) public int getRowCount()
JTable
, given unlimited space. From source file:computer_store.GUI.java
/** * Takes a JTable and a ResultSet as parameters and populates the JTable with the supplied ResultSet * @param table//w w w .j a va 2s.c om * @param rs */ private void fillTable(javax.swing.JTable table, java.sql.ResultSet rs) { try { //To remove previously added rows while (table.getRowCount() > 0) { ((javax.swing.table.DefaultTableModel) table.getModel()).removeRow(0); } int columns = rs.getMetaData().getColumnCount(); Object[] ids = new Object[columns]; while (rs.next()) { Object[] row = new Object[columns]; for (int i = 1; i <= columns; i++) { row[i - 1] = rs.getObject(i); } ((javax.swing.table.DefaultTableModel) table.getModel()).insertRow(rs.getRow() - 1, row); } for (int i = 1; i <= columns; i++) { ids[i - 1] = rs.getMetaData().getColumnName(i); } ((javax.swing.table.DefaultTableModel) table.getModel()).setColumnIdentifiers(ids); rs.close(); } catch (Exception e) { System.out.print(e); } }
From source file:computer_store.GUI.java
private void fillCompTable(javax.swing.JTable table, java.sql.ResultSet rs) { try {//from w w w .j a v a 2 s . c om //To remove previously added rows while (table.getRowCount() > 0) { ((javax.swing.table.DefaultTableModel) table.getModel()).removeRow(0); } int columns = rs.getMetaData().getColumnCount(); int rows = 0; java.util.ArrayList<String> helper = new java.util.ArrayList(); //Adding column titles Object[] ids = new Object[columns]; for (int i = 1; i <= columns; i++) { ids[i - 1] = rs.getMetaData().getColumnName(i); } ((javax.swing.table.DefaultTableModel) table.getModel()).setColumnIdentifiers(ids); //Adding rows from ResultSet to table model. while (rs.next()) { helper.add(rs.getString("name")); rows++; Object[] row = new Object[columns]; for (int i = 1; i <= columns; i++) { row[i - 1] = rs.getObject(i); } ((javax.swing.table.DefaultTableModel) table.getModel()).insertRow(rs.getRow() - 1, row); } //Adding new column with restock numbers Object[] restock = new Object[rows]; for (int i = 0; i < restock.length; i++) { restock[i] = handler.getCompRestock(helper.get(i)); } ((javax.swing.table.DefaultTableModel) table.getModel()).addColumn("# to Restock", restock); //Adding selling prices Object[] sellPrice = new Object[rows]; for (int i = 0; i < sellPrice.length; i++) { sellPrice[i] = ((int) jTable1.getValueAt(i, 1)) * 1.3; } ((javax.swing.table.DefaultTableModel) table.getModel()).addColumn("Selling price", sellPrice); rs.close(); } catch (Exception e) { System.out.print(e); } }
From source file:computer_store.GUI.java
private void fillSysTable(javax.swing.JTable table, java.sql.ResultSet rs) { try {/*ww w . jav a 2s .c o m*/ //To remove previously added rows while (table.getRowCount() > 0) { ((javax.swing.table.DefaultTableModel) table.getModel()).removeRow(0); } int columns = rs.getMetaData().getColumnCount(); int rows = 0; //Adding column headers Object[] ids = new Object[columns]; for (int i = 1; i <= columns; i++) { ids[i - 1] = rs.getMetaData().getColumnName(i); } ((javax.swing.table.DefaultTableModel) table.getModel()).setColumnIdentifiers(ids); java.util.ArrayList<String> systems = new java.util.ArrayList(); //Adding rows from ResultSet while (rs.next()) { systems.add(rs.getString(1)); Object[] row = new Object[columns]; for (int i = 1; i <= columns; i++) { row[i - 1] = rs.getObject(i); } ((javax.swing.table.DefaultTableModel) table.getModel()).insertRow(rs.getRow() - 1, row); rows++; } //Adding new column with prices Object[] prices = new Object[rows]; for (int i = 0; i < prices.length; i++) { prices[i] = handler.getSystemPrice(systems.get(i)); } ((javax.swing.table.DefaultTableModel) table.getModel()).addColumn("Price", prices); //Adding new column with selling prices Object[] sellPrices = new Object[rows]; for (int i = 0; i < sellPrices.length; i++) { sellPrices[i] = handler.getSystemSellPrice(systems.get(i)); } ((javax.swing.table.DefaultTableModel) table.getModel()).addColumn("Selling price", sellPrices); //Adding new column with current stock Object[] inStock = new Object[rows]; for (int i = 0; i < prices.length; i++) { inStock[i] = handler.systemsInStock(systems.get(i)); } ((javax.swing.table.DefaultTableModel) table.getModel()).addColumn("In stock", inStock); rs.close(); } catch (Exception e) { System.out.print(e); } }
From source file:edu.ucla.stat.SOCR.chart.demo.PowerTransformXYScatterChart.java
protected void setTable(XYDataset ds) { convertor.Y2Table(raw_x, raw_y, transformed_x, transformed_y, row_count); JTable tempDataTable = convertor.getTable(); resetTableRows(tempDataTable.getRowCount() + 1); resetTableColumns(tempDataTable.getColumnCount()); for (int i = 0; i < tempDataTable.getColumnCount(); i++) { columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i)); // System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i)); }/* w ww . j a v a 2 s .c om*/ columnModel = dataTable.getColumnModel(); dataTable.setTableHeader(new EditableHeader(columnModel)); for (int i = 0; i < tempDataTable.getRowCount(); i++) for (int j = 0; j < tempDataTable.getColumnCount(); j++) { dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j); } dataPanel.removeAll(); JScrollPane dt = new JScrollPane(dataTable); dataPanel.add(dt); dt.setRowHeaderView(headerTable); dataTable.setGridColor(Color.gray); dataTable.setShowGrid(true); dataTable.doLayout(); // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003 try { dataTable.setDragEnabled(true); } catch (Exception e) { } dataPanel.validate(); // don't bring graph to the front if (tabbedPanelContainer.getTitleAt(tabbedPanelContainer.getSelectedIndex()) != ALL) { // tabbedPanelContainer.setSelectedIndex(tabbedPanelContainer.indexOfComponent(graphPanel)); } else { dataPanel2.removeAll(); dataPanel2.add(new JLabel(" ")); dataPanel2.add(new JLabel("Data")); JScrollPane dt2 = new JScrollPane(dataTable); dt2.setPreferredSize(new Dimension(CHART_SIZE_X / 3, CHART_SIZE_Y * 3 / 8)); dt2.setRowHeaderView(headerTable); dataPanel2.add(dt2); JScrollPane st = new JScrollPane(summaryPanel); st.setPreferredSize(new Dimension(CHART_SIZE_X / 3, CHART_SIZE_Y / 6)); dataPanel2.add(st); st.validate(); dataPanel2.add(new JLabel(" ")); dataPanel2.add(new JLabel("Mapping")); mapPanel.setPreferredSize(new Dimension(CHART_SIZE_X / 3, CHART_SIZE_Y / 2)); dataPanel2.add(mapPanel); dataPanel2.validate(); } }
From source file:edu.ucla.stat.SOCR.chart.SuperCategoryChart_Stat_Raw.java
/** * reset dataTable to default (demo data), and refesh chart *//*from ww w . j a va2 s. c om*/ public void resetExample() { dataset = createDataset(true); JFreeChart chart = createChart(dataset); chartPanel = new ChartPanel(chart, false); setChart(); hasExample = true; convertor.valueList2Table(values_storage, SERIES_COUNT, CATEGORY_COUNT); JTable tempDataTable = convertor.getTable(); // resetTable(); resetTableRows(tempDataTable.getRowCount() + 1); resetTableColumns(tempDataTable.getColumnCount() + 1); for (int i = 0; i < tempDataTable.getColumnCount(); i++) { columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i)); // System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i)); } columnModel = dataTable.getColumnModel(); dataTable.setTableHeader(new EditableHeader(columnModel)); for (int i = 0; i < tempDataTable.getRowCount(); i++) for (int j = 0; j < tempDataTable.getColumnCount(); j++) { dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j); } dataPanel.removeAll(); dataPanel.add(new JScrollPane(dataTable)); dataTable.setGridColor(Color.gray); dataTable.setShowGrid(true); dataTable.doLayout(); // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003 try { dataTable.setDragEnabled(true); } catch (Exception e) { } dataPanel.validate(); // do the mapping addButtonDependent(); int columnCount = dataset.getColumnCount(); for (int i = 0; i < columnCount; i++) addButtonIndependent(); updateStatus(url); }
From source file:edu.ucla.stat.SOCR.chart.SuperXYZChart.java
/** * reset dataTable to default (demo data), and refesh chart *//*from w w w. ja v a 2 s. c o m*/ public void resetExample() { reset_Slider(); XYZDataset dataset = createDataset(true); JFreeChart chart = createChart(dataset); chartPanel = new ChartPanel(chart, false); setChart(); hasExample = true; convertor.dataset2Table(dataset); JTable tempDataTable = convertor.getTable(); // resetTable(); resetTableRows(tempDataTable.getRowCount() + 1); resetTableColumns(tempDataTable.getColumnCount()); for (int i = 0; i < tempDataTable.getColumnCount(); i++) { columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i)); // System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i)); } columnModel = dataTable.getColumnModel(); dataTable.setTableHeader(new EditableHeader(columnModel)); for (int i = 0; i < tempDataTable.getRowCount(); i++) for (int j = 0; j < tempDataTable.getColumnCount(); j++) { dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j); } dataPanel.removeAll(); dataPanel.add(new JScrollPane(dataTable)); dataTable.setGridColor(Color.gray); dataTable.setShowGrid(true); dataTable.doLayout(); // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003 try { dataTable.setDragEnabled(true); } catch (Exception e) { } dataPanel.validate(); // do the mapping int seriesCount = dataset.getSeriesCount(); for (int i = 0; i < seriesCount; i++) { addButtonIndependent(); addButtonDependent(); addButtonDependent(); } //updateStatus(url); }
From source file:edu.ucla.stat.SOCR.chart.SuperXYChart_QQ.java
/** * reset dataTable to default (demo data), and refesh chart *///w w w .j ava2 s . c om public void resetExample() { XYDataset dataset = createDataset(true); JFreeChart chart = createChart(dataset); chartPanel = new ChartPanel(chart, false); setChart(); hasExample = true; convertor.Y2Table(raw_y, row_count); //convertor.dataset2Table(dataset); JTable tempDataTable = convertor.getTable(); resetTableRows(tempDataTable.getRowCount() + 1); resetTableColumns(tempDataTable.getColumnCount()); for (int i = 0; i < tempDataTable.getColumnCount(); i++) { columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i)); // System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i)); } columnModel = dataTable.getColumnModel(); dataTable.setTableHeader(new EditableHeader(columnModel)); for (int i = 0; i < tempDataTable.getRowCount(); i++) for (int j = 0; j < tempDataTable.getColumnCount(); j++) { dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j); } dataPanel.removeAll(); dataPanel.add(new JScrollPane(dataTable)); dataTable.setGridColor(Color.gray); dataTable.setShowGrid(true); dataTable.doLayout(); // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003 try { dataTable.setDragEnabled(true); } catch (Exception e) { } dataPanel.validate(); // do the mapping setMapping(); updateStatus(url); }
From source file:com.sec.ose.osi.ui.frm.main.identification.codematch.table.JTableInfoForCMFolder.java
synchronized public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JComponent comp = (JComponent) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);/*from ww w. j a v a2s .c o m*/ if (value == null) { comp.setToolTipText(null); return comp; } comp.setToolTipText(String.valueOf(value)); if (row >= table.getRowCount()) { log.debug("row > table.getRowCount()"); return comp; } switch (column) { case TableModelForCMFolder.COL_COMPONENT_NAME: case TableModelForCMFolder.COL_LICENSE_NAME: setHorizontalAlignment(SwingConstants.LEFT); break; case TableModelForCMFolder.COL_VERSION_NAME: case TableModelForCMFolder.COL_IDENTIFIED: case TableModelForCMFolder.COL_STATUS: case TableModelForCMFolder.COL_PENDING: setHorizontalAlignment(SwingConstants.CENTER); break; } int pendingHits = 0; int identifiedHits = 0; if (table.getValueAt(row, TableModelForCMFolder.COL_PENDING) != null) { pendingHits = Tools .transStringToInteger(table.getValueAt(row, TableModelForCMFolder.COL_PENDING).toString()); } if (table.getValueAt(row, TableModelForCMFolder.COL_IDENTIFIED) != null) { identifiedHits = Tools .transStringToInteger(table.getValueAt(row, TableModelForCMFolder.COL_IDENTIFIED).toString()); } if (identifiedHits > 0 && pendingHits == 0) { comp.setFont(new Font("Arial", Font.BOLD, 12)); comp.setForeground(NORMAL_COLOR); } else if (identifiedHits == 0 && pendingHits == 0) { comp.setForeground(GRAY_COLOR); } else { comp.setForeground(NORMAL_COLOR); } return comp; }
From source file:edu.ucla.stat.SOCR.chart.SuperPowerChart.java
protected void setTable(XYDataset ds) { convertor.Power2Table(ds);/*from w w w . j a v a 2 s.com*/ //convertor.dataset2Table(dataset); JTable tempDataTable = convertor.getTable(); resetTableRows(tempDataTable.getRowCount() + 1); resetTableColumns(tempDataTable.getColumnCount()); for (int i = 0; i < tempDataTable.getColumnCount(); i++) { columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i)); // System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i)); } columnModel = dataTable.getColumnModel(); dataTable.setTableHeader(new EditableHeader(columnModel)); for (int i = 0; i < tempDataTable.getRowCount(); i++) for (int j = 0; j < tempDataTable.getColumnCount(); j++) { dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j); } dataPanel.removeAll(); dataPanel.add(new JScrollPane(dataTable)); dataTable.setGridColor(Color.gray); dataTable.setShowGrid(true); dataTable.doLayout(); // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003 try { dataTable.setDragEnabled(true); } catch (Exception e) { } dataPanel.validate(); // don't bring graph to the front if (tabbedPanelContainer.getTitleAt(tabbedPanelContainer.getSelectedIndex()) != ALL) { // tabbedPanelContainer.setSelectedIndex(tabbedPanelContainer.indexOfComponent(graphPanel)); } else { dataPanel2.removeAll(); dataPanel2.add(new JLabel(" ")); dataPanel2.add(new JLabel("Data")); JScrollPane dt = new JScrollPane(dataTable); dt.setPreferredSize(new Dimension(CHART_SIZE_X / 3, CHART_SIZE_Y * 3 / 8)); dataPanel2.add(dt); JScrollPane st = new JScrollPane(summaryPanel); st.setPreferredSize(new Dimension(CHART_SIZE_X / 3, CHART_SIZE_Y / 6)); dataPanel2.add(st); st.validate(); dataPanel2.add(new JLabel(" ")); dataPanel2.add(new JLabel("Mapping")); mapPanel.setPreferredSize(new Dimension(CHART_SIZE_X / 3, CHART_SIZE_Y / 2)); dataPanel2.add(mapPanel); dataPanel2.validate(); } }
From source file:com.smanempat.controller.ControllerClassification.java
public void convertToExcel(JTable tableResult, File fileToSave) throws FileNotFoundException, IOException { XSSFWorkbook workBook = new XSSFWorkbook(); XSSFSheet sheet = workBook.createSheet(); XSSFRow row;// w ww. j ava 2s . c om int rowCountData = tableResult.getRowCount(); Map<Integer, Object[]> data = new HashMap<Integer, Object[]>(); data.put(1, new Object[] { "NIS", "NAMA", "JK", "UN", "PT BINDO", "PT MTK", "PT BING", "PT IPA", "MINAT", "JURUSAN" }); for (int i = 0; i < rowCountData; i++) { // System.out.println(tableResult.getValueAt(i, 1)); data.put((i + 2), new Object[] { tableResult.getValueAt(i, 0), tableResult.getValueAt(i, 1), tableResult.getValueAt(i, 2), tableResult.getValueAt(i, 3), tableResult.getValueAt(i, 4), tableResult.getValueAt(i, 5), tableResult.getValueAt(i, 6), tableResult.getValueAt(i, 7), tableResult.getValueAt(i, 8), tableResult.getValueAt(i, 9) }); } //System.out.println("KeySet " + data.keySet()); Set<Integer> keyID = data.keySet(); int rowID = 0; for (Integer key : keyID) { row = sheet.createRow(rowID); Object[] tempData = data.get(key); rowID++; int cellID = 0; for (Object obj : tempData) { Cell cell = row.createCell(cellID); cell.setCellValue(obj.toString()); cellID++; } } FileOutputStream out = new FileOutputStream(fileToSave); workBook.write(out); out.close(); System.out.println(fileToSave + " Berhasil disimpan"); }