List of usage examples for javax.swing.table DefaultTableModel DefaultTableModel
public DefaultTableModel()
DefaultTableModel
which is a table of zero columns and zero rows. From source file:localnetworkdrive.HomePage.java
private void RefbutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RefbutActionPerformed // To fetch latest data on Remote files from tracker and populate the gui containers //Fetch tracker ip trackerip = constants.Constants.serverIp + ":3000"; uploadfile.setVisible(false);// w w w.j av a 2s . c o m jScrollPane2.setVisible(true); filelist.setVisible(true); //Initialize tracker interface fetchfiles f = new fetchfiles(); //Create image icons for display ImageIcon jv = new ImageIcon(HomePage.class.getResource("java.png")); ImageIcon py = new ImageIcon(HomePage.class.getResource("python.png")); ImageIcon mp = new ImageIcon(HomePage.class.getResource("mp4.png")); ImageIcon def = new ImageIcon(HomePage.class.getResource("def.png")); ImageIcon pdf = new ImageIcon(HomePage.class.getResource("pdf.png")); //Carry out the fetch operation try { jsonresp = f.getHTML("http://" + trackerip + "/files/get/"); if (jsonresp.equals("")) { JOptionPane.showMessageDialog(null, "Oops. Looks like the Server and I aren't connected."); return; } //Convert data into a convenient file format json = new JSONArray(jsonresp); //Create a data model for the table display DefaultTableModel model = new DefaultTableModel() { @Override public Class getColumnClass(int column) { return getValueAt(0, column).getClass(); }; }; //Add initial columns model.addColumn("Icon"); model.addColumn("FileName"); model.addColumn("Remote Location"); //Check if data isnt empty if (json.length() > 0) downloadbut.setEnabled(true); //Iterate through the data fetched and populate the table display for (int i = 0; i < json.length(); i++) { String switcher = new pathtranslator().decode(json.getJSONObject(i).getString("absolutepath")); switch (switcher.split("[.]")[switcher.split("[.]").length - 1]) { case "py": model.addRow(new Object[] { py, switcher, json.getJSONObject(i).getString("ip") }); break; case "java": model.addRow(new Object[] { jv, switcher, json.getJSONObject(i).getString("ip") }); break; case "mp4": model.addRow(new Object[] { mp, switcher, json.getJSONObject(i).getString("ip") }); break; case "pdf": model.addRow(new Object[] { pdf, switcher, json.getJSONObject(i).getString("ip") }); break; default: model.addRow(new Object[] { def, switcher, json.getJSONObject(i).getString("ip") }); break; } } //Set the table display with updated data filelist.setModel(model); } catch (HeadlessException | JSONException e) { JOptionPane.showMessageDialog(null, e.getMessage()); } }
From source file:dataviewer.DataViewer.java
private void btn_removeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_removeActionPerformed String name = "./db/" + cb_table.getSelectedItem().toString() + ".db"; if (new File(name).exists()) { int dialogResult = JOptionPane .showConfirmDialog(null, "Selected file [" + cb_table.getSelectedItem().toString() + "] will be removed and not recoverable.", "Are you sure?", JOptionPane.YES_NO_OPTION); if (dialogResult == JOptionPane.YES_OPTION) { (new File(name)).delete(); cb_table.removeItem(cb_table.getSelectedItem()); cb_table.setSelectedItem(null); tp_sql.setText(""); tb_columns.setModel(new DefaultTableModel()); }//from w ww . j a v a 2 s . c o m } }
From source file:com.smanempat.controller.ControllerEvaluation.java
private double[][] evaluationModel(JTable tableResult, JTable tableConfMatrix, JLabel totalAccuracy, JTable tableTahunTesting, JTable tableDataSetTesting, String[] knnValue, int i, int[] tempK, JPanel panelChart) throws SQLException { int actIPA = 0; int actIPS = 0; int trueIPA = 0; int falseIPA = 0; int trueIPS = 0; int falseIPS = 0; double recIPA; double recIPS; double preIPA; double preIPS; double accuracy; DefaultTableModel tableModelRes = new DefaultTableModel(); tableModelRes = (DefaultTableModel) tableResult.getModel(); String[] tempJurusan = getJurusanTest(tableTahunTesting, tableDataSetTesting); 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); }//from w w w . ja v a2 s. co m /*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; } } } /*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][tempK.length]; tempEval[0][i] = accuracy; tempEval[1][i] = recIPA; tempEval[2][i] = preIPA; /*Set Nilai TF, TN, FP, FN ke Tabel Confusion Matrix*/ tableConfMatrix.setValueAt("Actual IPA", 0, 0); tableConfMatrix.setValueAt("Actual IPS", 1, 0); tableConfMatrix.setValueAt("Class Precision", 2, 0); tableConfMatrix.setValueAt(trueIPA, 0, 1); tableConfMatrix.setValueAt(falseIPS, 0, 2); tableConfMatrix.setValueAt(falseIPA, 1, 1); tableConfMatrix.setValueAt(trueIPS, 1, 2); /*Set Nilai Recall, Precision, dan Accuracy ke Tabel Confusion Matrix*/ if (Double.isNaN(preIPA)) { tableConfMatrix.setValueAt("NaN" + " %", 2, 1); } else { tableConfMatrix.setValueAt(df.format(preIPA * 100) + " %", 2, 1); } if (Double.isNaN(preIPS)) { tableConfMatrix.setValueAt("NaN" + " %", 2, 2); } else { tableConfMatrix.setValueAt(df.format(preIPS * 100) + " %", 2, 2); } if (Double.isNaN(recIPA)) { tableConfMatrix.setValueAt("NaN" + " %", 0, 3); } else { tableConfMatrix.setValueAt(df.format(recIPA * 100) + " %", 0, 3); } if (Double.isNaN(recIPS)) { tableConfMatrix.setValueAt("NaN" + " %", 1, 3); } else { tableConfMatrix.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) + " %"); } tableModelRes.setRowCount(0); return tempEval; }
From source file:localnetworkdrive.HomePage.java
private void Refbut1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Refbut1ActionPerformed // To fetch latest data on Videos from tracker and populate the gui containers //Fetch tracker ip trackerip = constants.Constants.serverIp + ":3000"; uploadfile.setVisible(false);/*from w w w . j av a 2 s . c o m*/ jScrollPane2.setVisible(true); filelist.setVisible(true); //Initialize tracker interface fetchfiles f = new fetchfiles(); //Create image icons for display ImageIcon mp = new ImageIcon(HomePage.class.getResource("mp4.png")); //Carry out the fetch operation try { jsonresp = f.getHTML("http://" + trackerip + "/files/get/"); if (jsonresp.equals("")) { JOptionPane.showMessageDialog(null, "Oops. Looks like the Server and I aren't connected."); return; } //Convert data into a convenient file format json = new JSONArray(jsonresp); //Create a data model for the table display DefaultTableModel model = new DefaultTableModel() { @Override public Class getColumnClass(int column) { return getValueAt(0, column).getClass(); }; }; //Add initial columns model.addColumn("Icon"); model.addColumn("FileName"); model.addColumn("Remote Location"); //Check if data isnt empty if (json.length() > 0) downloadbut1.setEnabled(true); //Iterate through the data fetched and populate the table display for (int i = 0; i < json.length(); i++) { String switcher = new pathtranslator().decode(json.getJSONObject(i).getString("absolutepath")); switch (switcher.split("[.]")[switcher.split("[.]").length - 1]) { case "mp4": model.addRow(new Object[] { mp, switcher, json.getJSONObject(i).getString("ip") }); break; } } //Set the table display with updated data filelist1.setModel(model); } catch (HeadlessException | JSONException e) { JOptionPane.showMessageDialog(null, e.getMessage()); } }
From source file:localnetworkdrive.HomePage.java
private void Refbut2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Refbut2ActionPerformed // To fetch latest data on Screen Mirroring from tracker and populate the gui containers trackerip = constants.Constants.serverIp + ":3000"; //Initialize tracker interface fetchfiles f = new fetchfiles(); //Fetch latest data available for stream from tracker try {/*from w w w.jav a 2s .c o m*/ jsonresp = f.getHTML("http://" + trackerip + "/device/get"); if (jsonresp.equals("")) { JOptionPane.showMessageDialog(null, "Oops. Looks like the Server and I aren't connected."); return; } else startstream.setEnabled(true); //Convert data into a convenient format json = new JSONArray(jsonresp); //Create a data model for the table display DefaultTableModel model = new DefaultTableModel() { @Override public Class getColumnClass(int column) { return getValueAt(0, column).getClass(); }; }; //Populate initial columns on table display model.addColumn("IP Address"); model.addColumn("Computer ID"); //Check if data isnt empty if (json.length() > 0) downloadbut1.setEnabled(true); //Iterate through data to populate the table display for (int i = 0; i < json.length(); i++) { model.addRow(new Object[] { json.getJSONObject(i).getString("ip"), json.getJSONObject(i).getString("hash") }); } mirrorlist.setModel(model); } catch (HeadlessException | JSONException e) { JOptionPane.showMessageDialog(null, e.getMessage()); } }
From source file:Forms.FrmPrincipal.java
private void mostrarPesos(ArrayList<ArrayList<double[]>> w, int[] capas) { int max = 0;//from ww w .j a v a 2 s . co m for (int capa = 0; capa < capas.length; capa++) { if (capas[capa] >= max) { max = capas[capa]; } } DefaultTableModel modelo = new DefaultTableModel(); tblPesos.setModel(modelo); for (int capa = 0; capa < w.size(); capa++) { modelo.addColumn("Capa " + (capa + 1)); } Object[] object = new Object[4]; object[0] = "1"; object[1] = "2"; object[2] = "3"; object[3] = "4"; modelo.addRow(object); }
From source file:gui.Trabajadores.java
public void cargaBaja() { try {/*from w w w.j a va 2 s . c o m*/ Database con = new Database(); DefaultTableModel modelo = new DefaultTableModel(); this.tablaBajas.setModel(modelo); Connection conn = con.conectar(); String sentencia = "select Num_Empleado,Fecha_Baja,Costo_Finiquito, Indemnizacion, Prima_Antiguedad, Gratificacion, Total_Pagado_Separacion, Motivo_Baja, Volver_Contratar, Pendiente from bajas_temp;"; PreparedStatement pst = conn.prepareStatement(sentencia); rs = pst.executeQuery(); ResultSetMetaData rsMd = rs.getMetaData(); //La cantidad de columnas que tiene la consulta int cantidadColumnas = rsMd.getColumnCount(); //Establecer como cabezeras el nombre de las colimnas for (int i = 1; i <= cantidadColumnas; i++) { modelo.addColumn(rsMd.getColumnLabel(i)); } //Creando las filas para el JTable while (rs.next()) { Object[] fila = new Object[cantidadColumnas]; for (int i = 0; i < cantidadColumnas; i++) { fila[i] = rs.getObject(i + 1); } modelo.addRow(fila); } con.CerrarConexion(); } catch (Exception ioe) { ioe.printStackTrace(); } }
From source file:com.dvd.ui.SearchDVD.java
private void searchActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_searchActionPerformed errorTag.setVisible(false);//from w ww . jav a 2 s.c o m searchTable.setModel(new DefaultTableModel()); String searchTerm = keyword.getText().toLowerCase(); String ratingTerm = rating.getSelectedItem().toString(); String yearTerm = year.getSelectedItem().toString(); String definitionTerm = definition.getSelectedItem().toString(); boolean isResultFound = false; DefaultTableModel model = new DefaultTableModel(); model.setColumnIdentifiers( new String[] { "Code", "Title", "Year", "Rating ", "Definition", "Actors", "Book" }); if (searchTerm != null && !searchTerm.isEmpty()) { for (Dvd dvd_item : searchDVDList) { if (dvd_item.getTitle().toLowerCase().contains(searchTerm)) { model.addRow(new String[] { String.valueOf(dvd_item.getCode()), dvd_item.getTitle(), String.valueOf(dvd_item.getYear()), String.valueOf(dvd_item.getRating()), dvd_item.getDefiniiton(), dvd_item.getActors() }); } } isResultFound = true; if (isResultFound) { searchTable.setVisible(true); searchTable.setModel(model); } else { errorTag.setVisible(true); searchTable.setModel(new DefaultTableModel()); // errorTag.setText("No Result Found"); } } else { if (!ratingTerm.equals("Any")) { for (Dvd dvd_item : searchDVDList) { if (dvd_item.getRating() == Integer.parseInt(ratingTerm)) { model.addRow(new String[] { String.valueOf(dvd_item.getCode()), dvd_item.getTitle(), String.valueOf(dvd_item.getYear()), String.valueOf(dvd_item.getRating()), dvd_item.getDefiniiton(), dvd_item.getActors() }); } } isResultFound = true; if (isResultFound) { searchTable.setVisible(true); searchTable.setModel(model); } else { errorTag.setVisible(true); searchTable.setModel(new DefaultTableModel()); errorTag.setText("No Result Found"); } } else if (!yearTerm.equals("Any")) { for (Dvd dvd_item : searchDVDList) { if (dvd_item.getYear().equals(yearTerm)) { model.addRow(new String[] { String.valueOf(dvd_item.getCode()), dvd_item.getTitle(), String.valueOf(dvd_item.getYear()), String.valueOf(dvd_item.getRating()), dvd_item.getDefiniiton(), dvd_item.getActors() }); } } isResultFound = true; if (isResultFound) { searchTable.setVisible(true); searchTable.setModel(model); } else { errorTag.setVisible(true); searchTable.setModel(new DefaultTableModel()); errorTag.setText("No Result Found"); } } else if (!definitionTerm.equals("Any")) { for (Dvd dvd_item : searchDVDList) { if (dvd_item.getDefiniiton().equals(definitionTerm)) { model.addRow(new String[] { String.valueOf(dvd_item.getCode()), dvd_item.getTitle(), String.valueOf(dvd_item.getYear()), String.valueOf(dvd_item.getRating()), dvd_item.getDefiniiton(), dvd_item.getActors() }); } } isResultFound = true; if (isResultFound) { searchTable.setVisible(true); searchTable.setModel(model); } else { errorTag.setVisible(true); searchTable.setModel(new DefaultTableModel()); errorTag.setText("No Result Found"); } } else { errorTag.setText("Please enter more specific search criteria"); errorTag.setVisible(true); } // errorTag.setText("No Result Found"); } }
From source file:frames.MainGUI.java
public void LoadFeeDataToJTable(JTable t, File file) { try {// w w w. j a va 2s.com CSVParser parser = CSVParser.parse(file, Charset.forName("UTF-8"), CSVFormat.DEFAULT); //t.setModel(tm); DefaultTableModel model = new DefaultTableModel(); //model.setRowCount(0); for (CSVRecord c : parser) { if (c.getRecordNumber() == 1) { model.addColumn(c.get(datatype.GlobalVariable.TYPE)); model.addColumn(c.get(datatype.GlobalVariable.AMOUNT)); model.addColumn(c.get(datatype.GlobalVariable.PAID_BY)); model.addColumn(c.get(datatype.GlobalVariable.PAYER)); t.setModel(model); model = (DefaultTableModel) t.getModel(); continue; } model.addRow( new Object[] { c.get(datatype.GlobalVariable.TYPE), c.get(datatype.GlobalVariable.AMOUNT), c.get(datatype.GlobalVariable.PAID_BY), c.get(datatype.GlobalVariable.PAYER) }); } } catch (Exception e) { System.out.println(e); } }
From source file:gui.Trabajadores.java
public void cargaNoSin() { try {/*from ww w . j a v a 2 s . c om*/ Database con = new Database(); DefaultTableModel modelo = new DefaultTableModel(); this.tablaNoSin.setModel(modelo); Connection conn = con.conectar(); String sentencia = "SELECT d_sexo, count(d_sexo) from icave.fact_empleado where q_activo= 'SI' GROUP By d_sexo;"; PreparedStatement pst = conn.prepareStatement(sentencia); rs = pst.executeQuery(); ResultSetMetaData rsMd = rs.getMetaData(); //La cantidad de columnas que tiene la consulta int cantidadColumnas = rsMd.getColumnCount(); //Establecer como cabezeras el nombre de las colimnas for (int i = 1; i <= cantidadColumnas; i++) { modelo.addColumn(rsMd.getColumnLabel(i)); } //Creando las filas para el JTable while (rs.next()) { Object[] fila = new Object[cantidadColumnas]; for (int i = 0; i < cantidadColumnas; i++) { fila[i] = rs.getObject(i + 1); } modelo.addRow(fila); } con.CerrarConexion(); } catch (Exception ioe) { ioe.printStackTrace(); } }