List of usage examples for javax.swing.table DefaultTableModel setValueAt
public void setValueAt(Object aValue, int row, int column)
column
and row
. From source file:dbseer.gui.panel.DBSeerLiveMonitorPanel.java
public synchronized void updateTransactionNames() { if (DBSeerGUI.liveDataset.getTransactionTypes().size() == 0) { return;/*from w ww. j av a 2s. c o m*/ } for (int i = 0; i < transactionRenameButtons.size(); ++i) { String newName = DBSeerGUI.liveDataset.getTransactionTypes().get(i).getName(); newName = newName.trim(); transactionLabels.get(i).setText(newName); transactionNames.set(i, newName); DefaultTableModel model = (DefaultTableModel) monitorTable.getModel(); model.setValueAt(String.format("Current TPS of '%s' transactions", newName), 2 + (i * ROW_PER_TX_TYPE), 0); model.setValueAt(String.format("Current average latency of '%s' transactions", newName), 2 + (i * ROW_PER_TX_TYPE) + 1, 0); throughputCollection.getSeries(i).setKey(newName); latencyCollection.getSeries(i).setKey(newName); return; } }
From source file:gui.Grafico.java
/** * * @param expresion/*from ww w .j av a2s . c om*/ * @param minX * @param maxX * <p/> * @throws CaracterIlegal */ public void graficar(String expresion, double minX, double maxX) throws CaracterIlegal { String nombreVariable = ""; String[] rpn = Procesador.convertirRPN(expresion); for (String item : rpn) { if (Procesador.esVariable(item)) { if (nombreVariable.isEmpty()) { nombreVariable = item; } else if (!item.equals(nombreVariable)) { throw new CaracterIlegal(expresion, 0); } } } double[] valoresX = new double[1001]; double[] valoresY = new double[1001]; double iteradorDoubleX = minX; double pasoDouble = (maxX - minX) / 1000.0; for (int i = 0; i < valoresX.length; i++) { valoresX[i] = iteradorDoubleX; try { valoresY[i] = evaluarValor(Arrays.copyOf(rpn, rpn.length), nombreVariable, valoresX[i]); } catch (Exception e) { valoresY[i] = Double.NaN; } iteradorDoubleX += pasoDouble; } double pasoDoubleError = pasoDouble / 2; for (int i = 0; i < valoresY.length; i++) { if (valoresY[i] == Double.NaN) { double izquierdo = evaluarValor(Arrays.copyOf(rpn, rpn.length), nombreVariable, valoresX[i] - pasoDoubleError); double derecho = evaluarValor(Arrays.copyOf(rpn, rpn.length), nombreVariable, valoresX[i] + pasoDoubleError); valoresY[i] = (izquierdo - derecho) / 2; } } // System.out.println(Arrays.toString(valoresX)); // System.out.println(Arrays.toString(valoresY)); DefaultTableModel modeloTablaDefecto = (DefaultTableModel) jTable1.getModel(); if (ultimoNombre.length() > 0) { set.removeSeries(nombres.get(ultimoNombre)); modeloTablaDefecto.setValueAt(false, modeloTablaDefecto.getRowCount() - 1, 0); } double[][] valores = new double[][] { valoresX, valoresY }; String funcion = generarNombre() + "(" + nombreVariable + ") = " + Procesador.evaluarRPN(Procesador.convertirRPN(expresion)).toString(); set.addSeries(funcion, valores); nombres.put(ultimoNombre, funcion); funciones.put(funcion, valores); modeloTablaDefecto.addRow(new Object[] { true, funcion }); jPanel2.repaint(); setVisible(true); }
From source file:dbseer.gui.panel.DBSeerLiveMonitorPanel.java
@Override public synchronized void actionPerformed(ActionEvent event) { for (int i = 0; i < transactionRenameButtons.size(); ++i) { if (event.getSource() == transactionRenameButtons.get(i)) { String newName = (String) JOptionPane.showInputDialog(this, "Enter the new name for this transaction type", "New Dataset", JOptionPane.PLAIN_MESSAGE, null, null, transactionNames.get(i)); if (newName == null || newName.trim().isEmpty()) { return; } else { newName = newName.trim(); transactionNames.set(i, newName); transactionLabels.get(i).setText(newName); DefaultTableModel model = (DefaultTableModel) monitorTable.getModel(); model.setValueAt(String.format("Current TPS of '%s' transactions", transactionNames.get(i)), 2 + (i * ROW_PER_TX_TYPE), 0); model.setValueAt(//from w w w . j av a 2 s .co m String.format("Current average latency of '%s' transactions", transactionNames.get(i)), 2 + (i * ROW_PER_TX_TYPE) + 1, 0); // TimeSeriesCollection collection = (TimeSeriesCollection) throughputChartPanel.getChart().getXYPlot().getDataset(); throughputCollection.getSeries(i).setKey(newName); latencyCollection.getSeries(i).setKey(newName); // if (DBSeerGUI.currentDataset != null) // { // DBSeerGUI.currentDataset.setTransactionTypeName(i, newName); // } for (DBSeerDataSet dataset : DBSeerGUI.liveDatasets) { dataset.setTransactionTypeName(i, newName); } return; } } } for (int i = 0; i < transactionViewSampleButtons.size(); ++i) { if (event.getSource() == transactionViewSampleButtons.get(i)) { final int type = i; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { DBSeerShowTransactionExampleFrame sampleFrame = new DBSeerShowTransactionExampleFrame(type); sampleFrame.pack(); sampleFrame.setLocationRelativeTo(DBSeerGUI.mainFrame); sampleFrame.setVisible(true); } }); } } for (int i = 0; i < transactionEnableDisableButtons.size(); ++i) { if (event.getSource() == transactionEnableDisableButtons.get(i)) { final XYItemRenderer throughputRenderer = throughputChartPanel.getChart().getXYPlot().getRenderer(); final XYItemRenderer latencyRenderer = latencyChartPanel.getChart().getXYPlot().getRenderer(); final int type = i; final JButton button = transactionEnableDisableButtons.get(i); final DBSeerDataSet dataset = DBSeerGUI.liveDataset; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (button.getText() == "Disable") { dataset.disableTransaction(type); throughputRenderer.setSeriesVisible(type, false); latencyRenderer.setSeriesVisible(type, false); button.setText("Enable"); } else if (button.getText() == "Enable") { dataset.enableTransaction(type); throughputRenderer.setSeriesVisible(type, true); latencyRenderer.setSeriesVisible(type, true); button.setText("Disable"); } } }); } } for (int i = 0; i < transactionDeleteButtons.size(); ++i) { if (event.getSource() == transactionDeleteButtons.get(i)) { synchronized (LiveMonitorInfo.LOCK) { try { DBSeerGUI.middlewareSocket.removeTransactionType(i); } catch (IOException e) { DBSeerExceptionHandler.handleException(e); } throughputCollection.removeSeries(i); latencyCollection.removeSeries(i); DefaultTableModel model = (DefaultTableModel) monitorTable.getModel(); int newTxSize = transactionNames.size() - 1; for (int j = 0; j < transactionNames.size(); ++j) { model.setValueAt(String.format("Current TPS of '%s' transactions", transactionNames.get(j)), 2 + (j * ROW_PER_TX_TYPE), 0); model.setValueAt(String.format("Current average latency of '%s' transactions", transactionNames.get(j)), 2 + (j * ROW_PER_TX_TYPE) + 1, 0); model.setValueAt("", 2 + (j * ROW_PER_TX_TYPE), 1); model.setValueAt("", 2 + (j * ROW_PER_TX_TYPE) + 1, 1); } model.setValueAt("", 2 + (newTxSize * ROW_PER_TX_TYPE), 0); model.setValueAt("", 2 + (newTxSize * ROW_PER_TX_TYPE), 1); model.setValueAt("", 2 + (newTxSize * ROW_PER_TX_TYPE) + 1, 0); model.setValueAt("", 2 + (newTxSize * ROW_PER_TX_TYPE) + 1, 1); final JPanel panel = transactionTypesPanel; final JLabel label = transactionLabels.remove(i); final JButton renameButton = transactionRenameButtons.remove(i); final JButton exampleButton = transactionViewSampleButtons.remove(i); final JButton deleteButton = transactionDeleteButtons.remove(i); transactionNames.remove(i); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { panel.remove(label); panel.remove(renameButton); panel.remove(exampleButton); panel.remove(deleteButton); panel.revalidate(); panel.repaint(); } }); } break; } } }
From source file:dbseer.gui.panel.DBSeerLiveMonitorPanel.java
public synchronized void setCurrentAverageLatency(long time, int index, double latency) { synchronized (LiveMonitorInfo.LOCK) { DefaultTableModel model = (DefaultTableModel) monitorTable.getModel(); if (model.getRowCount() <= 2 + (index * ROW_PER_TX_TYPE + 1)) { model.addRow(new Object[] { "", "" }); }// w ww. ja v a2 s . c om model.setValueAt(String.format("%.1f", latency), 2 + (index * ROW_PER_TX_TYPE) + 1, 1); if (numTransactionType < index + 1) { String newName = "Type " + (index + 1); transactionNames.add(newName); numTransactionType = index + 1; JLabel newLabel = new JLabel(newName); JButton renameButton = new JButton("Rename"); JButton viewSampleButton = new JButton("View Examples"); // JButton enableDisableButton; // if (DBSeerGUI.liveDataset.isTransactionEnabled(index)) // { // enableDisableButton = new JButton("Disable"); // } // else // { // enableDisableButton = new JButton("Enable"); // } renameButton.addActionListener(this); viewSampleButton.addActionListener(this); // enableDisableButton.addActionListener(this); transactionTypesPanel.add(newLabel); transactionTypesPanel.add(renameButton); transactionTypesPanel.add(viewSampleButton); // transactionTypesPanel.add(enableDisableButton); transactionLabels.add(newLabel); transactionRenameButtons.add(renameButton); transactionViewSampleButtons.add(viewSampleButton); // transactionEnableDisableButtons.add(enableDisableButton); throughputCollection.addSeries(new TimeSeries(newName, Millisecond.class)); latencyCollection.addSeries(new TimeSeries(newName, Millisecond.class)); this.revalidate(); this.repaint(); } model.setValueAt( String.format("Current average latency of '%s' transactions", transactionNames.get(index)), 2 + (index * ROW_PER_TX_TYPE) + 1, 0); if (index < latencyCollection.getSeriesCount()) { TimeSeries series = latencyCollection.getSeries(index); // series.add(new Millisecond(), latency); series.addOrUpdate(new Millisecond(new Date(time * 1000)), latency); } } }
From source file:dbseer.gui.panel.DBSeerLiveMonitorPanel.java
public synchronized void setCurrentTPS(long time, int index, double tps) { synchronized (LiveMonitorInfo.LOCK) { DefaultTableModel model = (DefaultTableModel) monitorTable.getModel(); if (model.getRowCount() <= 2 + (index * ROW_PER_TX_TYPE)) { model.addRow(new Object[] { "", "" }); }// ww w . j a va2 s . c o m model.setValueAt(String.format("%.1f", tps), 2 + (index * ROW_PER_TX_TYPE), 1); if (numTransactionType < index + 1) { String newName = "Type " + (index + 1); transactionNames.add(newName); numTransactionType = index + 1; JLabel newLabel = new JLabel(newName); JButton renameButton = new JButton("Rename"); JButton viewSampleButton = new JButton("View Examples"); // JButton enableDisableButton; // if (DBSeerGUI.liveDataset.isTransactionEnabled(index)) // { // enableDisableButton = new JButton("Disable"); // } // else // { // enableDisableButton = new JButton("Enable"); // } renameButton.addActionListener(this); viewSampleButton.addActionListener(this); // enableDisableButton.addActionListener(this); transactionTypesPanel.add(newLabel); transactionTypesPanel.add(renameButton); transactionTypesPanel.add(viewSampleButton); // transactionTypesPanel.add(enableDisableButton); transactionLabels.add(newLabel); transactionRenameButtons.add(renameButton); transactionViewSampleButtons.add(viewSampleButton); // transactionEnableDisableButtons.add(enableDisableButton); for (DBSeerDataSet dataset : DBSeerGUI.liveDatasets) { dataset.addTransactionType("Type " + numTransactionType); } // TimeSeriesCollection newThroughputCollection = new TimeSeriesCollection(new TimeSeries(newName, Millisecond.class)); // TimeSeriesCollection collection = (TimeSeriesCollection) throughputChartPanel.getChart().getXYPlot().getDataset(); throughputCollection.addSeries(new TimeSeries(newName, Millisecond.class)); latencyCollection.addSeries(new TimeSeries(newName, Millisecond.class)); // throughputChartPanel.getChart().getXYPlot().setDataset(index, newThroughputCollection); this.revalidate(); this.repaint(); } model.setValueAt(String.format("Current TPS of '%s' transactions", transactionNames.get(index)), 2 + (index * ROW_PER_TX_TYPE), 0); // TimeSeriesCollection collection = (TimeSeriesCollection) throughputChartPanel.getChart().getXYPlot().getDataset(); if (index < throughputCollection.getSeriesCount()) { TimeSeries series = throughputCollection.getSeries(index); // series.add(new Millisecond(), tps); series.addOrUpdate(new Millisecond(new Date(time * 1000)), tps); } } }
From source file:edu.ucla.stat.SOCR.motionchart.MotionMouseListener.java
protected JPanel getItemPanel(final JDialog dialog, XYItemEntity item, ChartMouseEvent event) { MotionDataSet dataset = (MotionDataSet) event.getChart().getXYPlot().getDataset(); MotionTableModel model = dataset.getTableModel(); DefaultTableModel tModel = new DefaultTableModel(2, 0); ArrayList<String> rowIds = new ArrayList<String>(); Integer row = model.getKeyMap().get(dataset.getSeriesKey(item.getSeriesIndex())).get(item.getItem()); rowIds.add(row + ":"); int columnCount = model.getColumnCount(); for (int c = 0; c < columnCount; c++) { tModel.addColumn(model.getColumnName(c)); tModel.setValueAt(model.getValueAt(row, c), 0, c); }//from w ww. j av a2 s . c o m rowIds.add("Mappings:"); Object category = dataset.getCategory(item.getSeriesIndex(), item.getItem()); if (category != null) { tModel.setValueAt(category, 1, model.getCategoryMapping()); } Object key = dataset.getSeriesKey(item.getSeriesIndex()); if (key != null) { tModel.setValueAt(key, 1, model.getKeyMapping()); } Object x = dataset.getX(item.getSeriesIndex(), item.getItem()); if (x != null) { tModel.setValueAt(x, 1, model.getXAxisMapping()); } Object y = dataset.getY(item.getSeriesIndex(), item.getItem()); if (y != null) { tModel.setValueAt(y, 1, model.getYAxisMapping()); } Object size = dataset.getSize(item.getSeriesIndex(), item.getItem()); if (size != null) { tModel.setValueAt(size, 1, model.getSizeMapping()); } Color color = dataset.getColor(item.getSeriesIndex(), item.getItem()); if (color != null) { //String colorText = "RGB(" + color.getRed() + "," + color.getGreen() + "," + color.getBlue() + ")"; tModel.setValueAt(color, 1, model.getColorMapping()); } return getPanel(dialog, tModel, rowIds); }
From source file:Main.java
public Main() { DefaultTableModel model = new DefaultTableModel(0, 5) { @Override/* w w w .ja va2 s . co m*/ public boolean isCellEditable(int row, int column) { return false; } }; JTable table = new JTable(model); for (int i = 0; i < 20; i++) { model.addRow(new String[] { i + ".1", i + ".2", i + ".3", i + ".4", i + ".5", }); } add(table, BorderLayout.CENTER); table.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { System.out.println("pressed"); char key = e.getKeyChar(); int selectedColumn = table.getSelectedColumn(); for (int i = 0; i < model.getRowCount(); i++) { String value = (String) model.getValueAt(i, selectedColumn); model.setValueAt(value + key, i, selectedColumn); } } }); }
From source file:edu.ucla.stat.SOCR.motionchart.MotionMouseListener.java
protected JPanel getSeriesPanel(final JDialog dialog, ChartMouseEvent event) { MotionDataSet dataset = (MotionDataSet) event.getChart().getXYPlot().getDataset(); MotionBubbleRenderer renderer = (MotionBubbleRenderer) event.getChart().getXYPlot().getRenderer(); MotionTableModel model = dataset.getTableModel(); DefaultTableModel tModel = new DefaultTableModel(); ArrayList<Integer> visibleSeries = renderer.getVisibleSeries(); ArrayList<String> rowIds = new ArrayList<String>(); int columnCount = model.getColumnCount(); int r = 0;/* ww w.jav a 2s .c om*/ for (int c = 0; c < columnCount; c++) { tModel.addColumn(model.getColumnName(c)); } Iterator<Integer> itr = visibleSeries.iterator(); while (itr.hasNext()) { ArrayList<Integer> rows = model.getKeyMap().get(dataset.getSeriesKey(itr.next())); Iterator<Integer> rItr = rows.iterator(); while (rItr.hasNext()) { int row = rItr.next(); tModel.addRow(new Object[0]); rowIds.add(new String(row + ":")); for (int c = 0; c < columnCount; c++) { tModel.setValueAt(model.getValueAt(row, c), r, c); } r++; } } return getPanel(dialog, tModel, rowIds); }
From source file:view.caja.Despacho.java
public void quitarFila() { if (tbCarrito.getRowCount() != 0) { if (fila >= 0) { contador--;/*w w w . j a va 2s.com*/ DefaultTableModel defModel = (DefaultTableModel) tbCarrito.getModel(); //System.out.println(Double.parseDouble(tbCarrito.getValueAt(fila,2).toString())); //System.out.println(Integer.parseInt(tbCarrito.getValueAt(fila,4).toString())); double valProdSelected = Double.parseDouble(tbCarrito.getValueAt(fila, 2).toString()) * Integer.parseInt(tbCarrito.getValueAt(fila, 4).toString()); aCobrar = aCobrar - valProdSelected; jlblACobrarMostrar.setText(Double.toString(aCobrar)); jlblCantMostrar.setText(Integer.toString(contador)); defModel.removeRow(fila); fila = -1; for (int indexTable = tbCarrito.getRowCount() - 1; indexTable >= 0; indexTable--) { defModel.setValueAt(indexTable + 1, indexTable, 0); } System.out.println(aCobrar); btQuitar.setEnabled(false); if (tbCarrito.getRowCount() == 0) { btRemoveAll.setEnabled(false); } } } else { btQuitar.setEnabled(false); System.out.println("nada que quitar"); } }
From source file:UserInterface.Supplier.SalesOverviewJPanel.java
public void populateTable() { DefaultTableModel dtm = (DefaultTableModel) performanceJTable.getModel(); dtm.setRowCount(0);/*ww w. j a va 2 s. c om*/ Object[] obj = new Object[3]; ArrayList<String> temp = new ArrayList<>(); for (Order o : moc.getMoc()) { if (o.getSupplier().getCompanyName().equals(s.getCompanyName())) { for (OrderItem oi : o.getListOfItemsOrdered()) { if (!temp.contains(oi.getProduct().getTypeOfDevice())) { obj[0] = oi.getProduct().getTypeOfDevice(); obj[1] = oi.getQuantity(); obj[2] = oi.getProduct().getCost() * oi.getQuantity(); dtm.addRow(obj); temp.add(oi.getProduct().getTypeOfDevice()); } else if (temp.contains(oi.getProduct().getTypeOfDevice())) { for (int i = 0; i < dtm.getRowCount(); i++) { String prodname = (String) dtm.getValueAt(i, 0); if (prodname.equals(oi.getProduct().getTypeOfDevice())) { int q = (int) dtm.getValueAt(i, 1) + oi.getQuantity(); int sale = q * oi.getProduct().getCost(); dtm.setValueAt(q, i, 1); dtm.setValueAt(sale, i, 2); } } } } } } }