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:la2launcher.MainFrame.java
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed DefaultTableModel model = (DefaultTableModel) jTable2.getModel(); for (int i = 0; i < model.getRowCount(); i++) { model.setValueAt(true, i, 1); }//from w ww . j av a 2 s. co m }
From source file:la2launcher.MainFrame.java
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed DefaultTableModel model = (DefaultTableModel) jTable2.getModel(); for (int i = 0; i < model.getRowCount(); i++) { model.setValueAt(false, i, 1); }//from www . jav a 2 s .com }
From source file:lob.VisualisationGUI.java
public void clearTable(final JTable table) { DefaultTableModel dm = (DefaultTableModel) table.getModel(); for (int i = 0; i < dm.getRowCount(); i++) { for (int j = 0; j < dm.getColumnCount(); j++) { dm.setValueAt("", i, j); }/* ww w . j a va 2 s . co m*/ } }
From source file:front.TestTable.java
public TestTable(Controller cont, int[][] response, float[] vec, float rango, int cantIntervalos) { controller = cont;//from w w w. jav a 2 s. com contador = response.length; initComponents(); DecimalFormat in = new DecimalFormat("0.00"); DecimalFormat aleat = new DecimalFormat("0.0000"); DecimalFormat c = new DecimalFormat("0.000"); int contador = 0; int frecEsp = (int) vec.length / cantIntervalos; double rangoM; float[][] matrizIntervalos = new float[cantIntervalos][2]; double[] estadisticoParcial = new double[cantIntervalos]; DefaultTableModel tm = (DefaultTableModel) table.getModel(); for (int i = 0; i < response.length; i++) { if (i == 0) { rangoM = rango; tm.addRow(new Object[] { "0.00 - " + in.format(rangoM), i, response[i][1], frecEsp, c.format(estadisticoPrueba(response, frecEsp, i)) }); contador++; matrizIntervalos[0][0] = 0; matrizIntervalos[0][1] = (float) rangoM; } else { if (contador == 1) { tm.addRow(new Object[] { in.format(rango) + " - " + in.format(rango + rango), i, response[i][1], frecEsp, c.format(estadisticoPrueba(response, frecEsp, i)) }); matrizIntervalos[i][0] = rango; matrizIntervalos[i][1] = (float) rango + rango; contador++; } else { tm.addRow(new Object[] { in.format(rango * contador) + " - " + in.format((rango * contador) + rango), i, response[i][1], frecEsp, c.format(estadisticoPrueba(response, frecEsp, i)) }); matrizIntervalos[i][0] = rango * contador; matrizIntervalos[i][1] = (rango * contador) + rango; contador++; } } } if (frecEsp < 5) { DefaultTableModel tm2 = (DefaultTableModel) tablaFe.getModel(); double estadisticoTotal = 0; int frecEspAcumulada = 0; int frecObsAcumulada = 0; int inicio = 0; float a = 0; for (int i = 0; i < tm.getRowCount(); i++) { frecEspAcumulada += (int) tm.getValueAt(i, 2); frecObsAcumulada += (int) tm.getValueAt(i, 1); if (frecEspAcumulada >= 5) { estadisticoParcial[i] += estadisticoPrueba2(frecObsAcumulada, (int) frecEspAcumulada); tm2.addRow(new Object[] { in.format(matrizIntervalos[inicio][0]) + " - " + in.format(matrizIntervalos[i][1]), (int) frecObsAcumulada, frecEspAcumulada, c.format(estadisticoParcial[i]) }); a = matrizIntervalos[inicio][0]; inicio = i + 1; frecEspAcumulada = 0; frecObsAcumulada = 0; } else { if (i == tm.getRowCount() - 1) { int filaAUnir = tm2.getRowCount() - 1; //actualizo intervalo tm2.setValueAt(in.format(a) + " - " + in.format(matrizIntervalos[i][1]), filaAUnir, 0); //frec observada tm2.setValueAt(frecObsAcumulada + (int) tm2.getValueAt(filaAUnir, 1), filaAUnir, 1); //frec esperada tm2.setValueAt(frecEspAcumulada + (int) tm2.getValueAt(filaAUnir, 2), filaAUnir, 2); int frecObsUltima = (int) tm2.getValueAt(filaAUnir, 1); int frecEspUltima = (int) tm2.getValueAt(filaAUnir, 2); estadisticoParcial[i - 1] = estadisticoPrueba2(frecObsUltima, frecEspUltima); tm2.setValueAt(estadisticoParcial[i - 1], filaAUnir, 3); break; } } } for (int i = 0; i < estadisticoParcial.length; i++) { estadisticoTotal += estadisticoParcial[i]; } txt_gradosNuevo.setText("" + gradosLibertad(tm2.getRowCount())); txt_estadisticoNuevo.setText("" + c.format(estadisticoTotal)); } //para mostrar los valores generados String acum = ""; for (int i = 0; i < vec.length; i++) { acum += "Valor " + (i + 1) + ": " + aleat.format(vec[i]) + ".\n"; } txt_valoresGenerados.setText(acum); //para el calculo de mi estadistico de prueba total txt_estadistico.setText("" + c.format(estadisticoPruebaTotal(response, frecEsp))); txt_grados.setText("" + gradosLibertad(cantIntervalos)); valoresGenerados = vec; this.cantIntervalos = cantIntervalos; agregarHistograma(); }
From source file:org.agmip.ui.afsirs.frames.SWFrame.java
private void waterholdcapacityBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_waterholdcapacityBoxActionPerformed // TODO add your handling code here: if (isInitializing) return;// w w w . j a v a2 s . c o m int whc = waterholdcapacityBox.getSelectedIndex(); boolean isFileLocationSelected = jRadioButtonSavedLocation.isSelected(); boolean isFileSelected = jRadioFile.isSelected(); boolean isKeyboardEnabled = jRadioKeyboard.isSelected(); if (isFileSelected) waterHoldSelectedItemIndex[0] = whc; else if (isFileLocationSelected) waterHoldSelectedItemIndex[1] = whc; else waterHoldSelectedItemIndex[2] = whc; DefaultTableModel model = (DefaultTableModel) soilTable.getModel(); for (int i = 0; i < NL; i++) { if (whc == 0) { WC[i] = WCL[i]; } else if (whc == 2) { WC[i] = WCU[i]; } else { WC[i] = 0.5 * (WCL[i] + WCU[i]); WC[i] = Math.floor(WC[i] * 1000) / 1000; } model.setValueAt(WC[i], i, 2); } }
From source file:org.fhcrc.cpl.viewer.quant.gui.ProteinQuantSummaryFrame.java
License:asdf
/** * Find all the peptides contributing to the ratio for the FIRST OCCURRENCE of a * protein in the pepXML file, find all quantitative events for those peptides in the * pepXML file, and show them//from w w w . j a v a 2 s. co m * @param pepXmlFile * @param proteins */ public void displayData(File pepXmlFile, File protXmlFile, List<ProtXmlReader.Protein> proteins) { _log.debug("displayData 1***"); this.protXmlFile = protXmlFile; this.pepXmlFile = pepXmlFile; Collections.sort(proteins, new Comparator<ProtXmlReader.Protein>() { public int compare(ProtXmlReader.Protein o1, ProtXmlReader.Protein o2) { return o1.getProteinName().compareTo(o2.getProteinName()); } }); DefaultTableModel proteinRatiosTableModel = new DefaultTableModel(0, 4) { //all cells uneditable public boolean isCellEditable(int row, int column) { return false; } public Class getColumnClass(int columnIndex) { switch (columnIndex) { case 0: return String.class; case 1: return Float.class; case 2: case 3: return Integer.class; } return String.class; } }; proteinRatiosTable.setModel(proteinRatiosTableModel); proteinRatiosTable.getColumnModel().getColumn(0).setHeaderValue("Protein"); proteinRatiosTable.getColumnModel().getColumn(1).setHeaderValue("Ratio"); proteinRatiosTable.getColumnModel().getColumn(2).setHeaderValue("Quant Peptides"); proteinRatiosTable.getColumnModel().getColumn(3).setHeaderValue("Events"); _log.debug("displayData getting protein info"); this.proteinNames = new ArrayList<String>(); List<ProtXmlReader.QuantitationRatio> quantRatios = new ArrayList<ProtXmlReader.QuantitationRatio>(); proteinRatiosTableModel.setRowCount(proteins.size()); for (int i = 0; i < proteins.size(); i++) { String proteinName = proteins.get(i).getProteinName(); ProtXmlReader.QuantitationRatio quantRatio = proteins.get(i).getQuantitationRatio(); quantRatios.add(quantRatio); proteinNames.add(proteinName); //careful -- the 3rd column values are populated below proteinRatiosTableModel.setValueAt(proteinName, i, 0); proteinRatiosTableModel.setValueAt(Rounder.round(quantRatio.getRatioMean(), 2), i, 1); } if (proteinNames.size() == 1) eventsTable.hideProteinColumn(); if (proteinGenesMap == null) eventsTable.hideGeneColumn(); else { eventsTable.setProteinGenesMap(proteinGenesMap); } TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(proteinRatiosTableModel); proteinRatiosTable.setRowSorter(sorter); contentPanel.updateUI(); _log.debug("displayData getting quant events"); quantEvents = new ArrayList<QuantEvent>(); Map<String, Set<String>> peptideProteinsQuantMap = new HashMap<String, Set<String>>(); for (int i = 0; i < proteins.size(); i++) { for (String peptide : quantRatios.get(i).getPeptides()) { Set<String> proteinsThisPep = peptideProteinsQuantMap.get(peptide); if (proteinsThisPep == null) { proteinsThisPep = new HashSet<String>(); peptideProteinsQuantMap.put(peptide, proteinsThisPep); } proteinsThisPep.add(proteins.get(i).getProteinName()); } } _log.debug("peptideProteinsQuantMap has " + peptideProteinsQuantMap.size() + " peptides."); System.err.println("Contains the one? " + peptideProteinsQuantMap.containsKey("QCPYCLLYK")); proteinEventsMap = new HashMap<String, List<QuantEvent>>(); Map<String, Set<String>> proteinPeptidesMap = new HashMap<String, Set<String>>(); try { PepXMLFeatureFileHandler.PepXMLFeatureSetIterator fsi = new PepXMLFeatureFileHandler.PepXMLFeatureSetIterator( pepXmlFile); int numFractions = 0; setMessage("Loading all pepXML fractions..."); _log.debug("Loading all pepXML fractions..."); while (fsi.hasNext()) { boolean thisFracHasEvents = false; FeatureSet featureSet = fsi.next(); setMessage("Checking fraction " + MS2ExtraInfoDef.getFeatureSetBaseName(featureSet)); _log.debug("Checking fraction " + MS2ExtraInfoDef.getFeatureSetBaseName(featureSet)); String featureSetBaseName = MS2ExtraInfoDef.getFeatureSetBaseName(featureSet); //check all features to see if they're in our list of peptides. If so, add to quantEvents for (Feature feature : featureSet.getFeatures()) { String peptide = MS2ExtraInfoDef.getFirstPeptide(feature); if (peptideProteinsQuantMap.containsKey(peptide) && IsotopicLabelExtraInfoDef.hasRatio(feature)) { thisFracHasEvents = true; //pick up the labeled residue from the first feature // if (labeledResidue == null) // { // AnalyzeICAT.IsotopicLabel label = IsotopicLabelExtraInfoDef.getLabel(feature); // if (label != null) // { // labeledResidue = "" + label.getResidue(); // labelMassDiff = label.getHeavy() - label.getLight(); // _log.debug("Found label: " + labeledResidue + ", " + labelMassDiff); // } // } QuantEvent quantEvent = new QuantEvent(feature, featureSetBaseName); quantEvent.setProtein(new ArrayList<String>(peptideProteinsQuantMap.get(peptide)).get(0)); quantEvents.add(quantEvent); for (String protein : peptideProteinsQuantMap.get(peptide)) { Set<String> peptidesThisProtein = proteinPeptidesMap.get(protein); if (peptidesThisProtein == null) { peptidesThisProtein = new HashSet<String>(); proteinPeptidesMap.put(protein, peptidesThisProtein); } peptidesThisProtein.add(quantEvent.getPeptide()); List<QuantEvent> eventsThisProtein = proteinEventsMap.get(protein); if (eventsThisProtein == null) { eventsThisProtein = new ArrayList<QuantEvent>(); proteinEventsMap.put(protein, eventsThisProtein); } eventsThisProtein.add(quantEvent); } } } if (thisFracHasEvents) numFractions++; } _log.debug("Processed all pepXML fractions "); for (int i = 0; i < proteins.size(); i++) { String protein = proteinNames.get(i); if (proteinPeptidesMap.get(proteinNames.get(i)) != null) proteinRatiosTableModel.setValueAt(proteinPeptidesMap.get(protein).size(), i, 2); if (proteinEventsMap.get(proteinNames.get(i)) != null) proteinRatiosTableModel.setValueAt(proteinEventsMap.get(protein).size(), i, 3); } if (numFractions < 2) { setMessage("Loaded all quantitation events from 1 fraction"); _log.debug("Loaded all quantitation events from 1 fraction"); } else { setMessage("Loaded all quantitation events from " + numFractions + " separate fractions"); _log.debug("Loaded all quantitation events from " + numFractions + " separate fractions"); } // if (labeledResidue == null) // infoMessage("WARNING: unable to determine modification used for quantitation. " + // "Cannot collapse light and heavy states or perform assessment."); // else // { // labelType = QuantitationUtilities.inferLabelType(labeledResidue, labelMassDiff); // } } catch (Exception e) { //check if the file has a .pep.xml extension, in case someone put the wrong file in if (pepXmlFile.getName().toLowerCase().endsWith("pep.xml")) errorMessage("Failed to load features from pepXML file: " + e.getMessage(), e); else { infoMessage("Failed to load pepXML file " + pepXmlFile.getName() + ". Extension is not .pep.xml... did you specify the wrong file?"); e.printStackTrace(System.err); } return; } _log.debug("Done loading quant events. Events: " + quantEvents.size()); if (quantEvents.isEmpty()) { throw new RuntimeException("No quantitation events found!"); } //sort by peptide, then fraction, then charge, then modifications Collections.sort(quantEvents, new QuantEvent.ProteinPeptideFractionChargeModificationsRatioAscComparator()); _log.debug("About to display events..."); displayEvents(); if (quantRatios.size() == 1) { eventsTable.setLogRatioHeaderRatio(quantRatios.get(0).getRatioMean()); } _log.debug("About to update extreme ratio GUI..."); updateExtremeRatioGUI(); }
From source file:com.smanempat.controller.ControllerEvaluation.java
private double[][] evaluationModel(JTable tableResult, JTable tableConfMatrix, JLabel totalAccuracy, JTable tableTahunTesting, JTable tableDataSetTesting, String[] knnValue, int nilaiK, JPanel panelChart) throws SQLException { int actIPA = 0; int actIPS = 0; int trueIPA = 0; int falseIPA = 0; int trueIPS = 0; int falseIPS = 0; int classIPA = 0; int classIPS = 0; double recIPA; double recIPS; double preIPA; double preIPS; double accuracy; DefaultTableModel tableModelConf = (DefaultTableModel) tableConfMatrix.getModel(); DefaultTableModel tableModelRes = (DefaultTableModel) tableResult.getModel(); String[] tempJurusan = getJurusanTest(tableTahunTesting, tableDataSetTesting); if (tableModelRes.getRowCount() != 0) { tableModelRes.setRowCount(0);//www. ja v a 2 s .c o m } for (int j = 0; j < tableDataSetTesting.getRowCount(); j++) { String nis = tableDataSetTesting.getValueAt(j, 0).toString(); String jurusan = tempJurusan[j]; String classified = knnValue[j]; Object[] tableContent = { nis, jurusan, classified }; tableModelRes.addRow(tableContent); tableResult.setModel(tableModelRes); } /*Hitung Jumlah Data Actual IPA dan IPS*/ for (int j = 0; j < tempJurusan.length; j++) { if (tempJurusan[j].equals("IPA")) { actIPA = actIPA + 1; } else if (tempJurusan[j].equals("IPS")) { actIPS = actIPS + 1; } } /*Hitung Jumlah Data Classified IPA dan IPS*/ for (int j = 0; j < knnValue.length; j++) { if (tableResult.getValueAt(j, 1).equals("IPA")) { if (tableResult.getValueAt(j, 1).equals(tableResult.getValueAt(j, 2))) { trueIPA = trueIPA + 1; } else { falseIPS = falseIPS + 1; } } else if (tableResult.getValueAt(j, 1).equals("IPS")) { if (tableResult.getValueAt(j, 1).equals(tableResult.getValueAt(j, 2))) { trueIPS = trueIPS + 1; } else { falseIPA = falseIPA + 1; } } } // System.out.println("trueIPA =" + trueIPA); // System.out.println("falseIPA =" + falseIPA); // System.out.println("falseIPS =" + falseIPS); // System.out.println("trueIPS =" + trueIPS); /*Hitung Nilai Recall, Precision, dan Accuracy*/ preIPA = (double) trueIPA / (trueIPA + falseIPA); preIPS = (double) trueIPS / (trueIPS + falseIPS); recIPA = (double) trueIPA / (trueIPA + falseIPS); recIPS = (double) trueIPS / (trueIPS + falseIPA); accuracy = (double) (trueIPA + trueIPS) / (trueIPA + trueIPS + falseIPA + falseIPS); /*Tampung Nilai Recall, Precision, dan Accuracy*/ double[][] tempEval = new double[3][1]; tempEval[0][0] = accuracy; tempEval[1][0] = recIPA; tempEval[2][0] = preIPA; /*Set Nilai TF, TN, FP, FN ke Tabel Confusion Matrix*/ tableModelConf.setValueAt("Actual IPA", 0, 0); tableModelConf.setValueAt("Actual IPS", 1, 0); tableModelConf.setValueAt("Class Precision", 2, 0); tableModelConf.setValueAt(trueIPA, 0, 1); tableModelConf.setValueAt(falseIPS, 0, 2); tableModelConf.setValueAt(falseIPA, 1, 1); tableModelConf.setValueAt(trueIPS, 1, 2); /*Set Nilai Recall, Precision, dan Accuracy ke Tabel Confusion Matrix*/ if (Double.isNaN(preIPA)) { tableModelConf.setValueAt("NaN" + " %", 2, 1); } else { tableModelConf.setValueAt(df.format(preIPA * 100) + " %", 2, 1); } if (Double.isNaN(preIPS)) { tableModelConf.setValueAt("NaN" + " %", 2, 2); } else { tableModelConf.setValueAt(df.format(preIPS * 100) + " %", 2, 2); } if (Double.isNaN(recIPA)) { tableModelConf.setValueAt("NaN" + " %", 0, 3); } else { tableModelConf.setValueAt(df.format(recIPA * 100) + " %", 0, 3); } if (Double.isNaN(recIPS)) { tableModelConf.setValueAt("NaN" + " %", 1, 3); } else { tableModelConf.setValueAt(df.format(recIPS * 100) + " %", 1, 3); } if (Double.isNaN(accuracy)) { totalAccuracy.setText("Overall Accuracy is " + "NaN" + " %"); } else { totalAccuracy.setText("Overall Accuracy is " + df.format(accuracy * 100) + " %"); } // System.out.println("Recall IPA = " + recIPA); // System.out.println("Recall IPA =" + recIPS); // System.out.println("Precision IPA = " + preIPA); // System.out.println("Precision IPS = " + preIPS); // System.out.println("Overall Accuracy = " + accuracy); return tempEval; }
From source file:stainingestimation.StainingEstimation.java
/** * Writes an entry into the staining estimation parameter table. * @param fscores The parameters to be written. *//*from w w w .j av a 2 s . c o m*/ void writePrecisionRecallTable(double[][][] fscores) { if (fscores != null) { DefaultTableModel tm = ((DefaultTableModel) jXTable1.getModel()); tm.setRowCount(0); int i = 0; for (double[][] d1 : fscores) { for (double[] d2 : d1) { tm.setRowCount(++i); for (int j = 0; j < jXTable1.getModel().getColumnCount(); j++) { if (((DefaultTableModel) jXTable1.getModel()).getColumnClass(j) == Double.class) { tm.setValueAt(d2[j], i - 1, j); } else if (((DefaultTableModel) jXTable1.getModel()).getColumnClass(j) == Integer.class) { tm.setValueAt((int) d2[j], i - 1, j); } else { if (jXTable1.getModel().getColumnName(j).equalsIgnoreCase("staining")) { tm.setValueAt(jComboBox1.getModel().getElementAt(Math.round((float) d2[j])), i - 1, j); } else { tm.setValueAt(Double.toString(d2[j]), i - 1, j); } } } } } jXTable1.doLayout(); jXTable1.packAll(); jXTable1.packTable(0); jButton11.setEnabled(jXTable1.getRowCount() > 0); } }
From source file:semaforo.Semaforo.java
public synchronized void updateTableWeek(JTable TableWeek, int index, int tamano) { Settings settings = Controller.getSettings(); // TableWeek.getColumnModel().getColumn(0).setPreferredWidth(120); // TableWeek.getColumnModel().getColumn(9).setPreferredWidth(120); // CustomRenderer cr = new CustomRenderer(TableWeek.getDefaultRenderer(Object.class), Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY); // TableWeek.setDefaultRenderer(Object.class, cr); DefaultTableModel model = (DefaultTableModel) TableWeek.getModel(); DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(3);//from w w w .j ava2 s . co m int num = Math.min(settings.getTickers().size(), model.getRowCount()); if (TableWeek.getModel().getRowCount() > 0) { num = Math.min(settings.getTickers().size(), TableWeek.getModel().getRowCount()); } for (int i = 0; i < num; i++) { for (int m = 0; m < TableTicker.getModel().getRowCount(); m++) { if (TableTicker != null && TableTicker.getModel() != null) { if (TableTicker.getModel().getValueAt(m, 0) != null) { if (TableTicker.getModel().getValueAt(m, 0) .equals(settings.getTickers().get(i).getName())) { model.setValueAt(String.format("%.2f", settings.getTickers().get(i).getMinValue(index)), m, 0); model.setValueAt(String.format("%.2f", settings.getTickers().get(i).getMaxValue(index)), m, tamano); //TODO: Parametrizar // JOptionPane.showMessageDialog(null,index+"", "", JOptionPane.ERROR_MESSAGE); if (index == 13) { DDBB.updateTicker(TableTicker.getModel().getValueAt(m, 0).toString(), String.format("%.2f", settings.getTickers().get(i).getMinValue(index)), String.format("%.2f", settings.getTickers().get(i).getMaxValue(index))); } } } } } } }
From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java
private void editChangeAttacks(int pDirection) { int idx = jideTabbedPane1.getSelectedIndex(); if (idx == 1) { int[] rows = jVictimTable.getSelectedRows(); if (rows == null || rows.length == 0) { showInfo("Keine Ziele ausgewhlt"); return; }//from w w w. j a v a 2s.c o m DefaultTableModel victimModel = (DefaultTableModel) jVictimTable.getModel(); for (int r : rows) { int row = jVictimTable.convertRowIndexToModel(r); int amount = (Integer) victimModel.getValueAt(row, jVictimTable.convertColumnIndexToModel(3)); if (pDirection != 0) { amount += pDirection; } else { try { amount = (Integer) jMaxAttacksPerVillage.getValue(); } catch (ClassCastException cce) { amount = 1; } } if (amount > 0) { victimModel.setValueAt(amount, row, jVictimTable.convertColumnIndexToModel(3)); } } String message = "Angriffe fr " + ((rows.length == 1) ? " ein Ziel" : rows.length + " Ziele ") + " angepasst"; showSuccess(message); updateInfo(); } else { //invalid tab showInfo("Diese Funktion ist nur fr Ziele verfgbar"); } }