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:dataviewer.DataViewer.java
private void read_data() { t[THREAD.read.ordinal()].stop();/* w w w . j a v a 2 s.co m*/ t[THREAD.read.ordinal()] = new Thread(new Runnable() { @Override public void run() { //do stuff try { if (!selected_file.equals("")) { cb_table.setEnabled(false); btn_execute.setEnabled(false); tp_sql.setEnabled(false); ck_export.setEnabled(false); btn_remove.setEnabled(false); tb_data.setModel(new DefaultTableModel()); txt_count.setText("Please wait while profiling data ..."); table = selected_file.replaceAll(getExtension(selected_file), "") .replaceAll("[^a-zA-Z0-9]+", ""); DB db = new DB("./db/" + table + ".db"); db.initialize(); Timing timer = new Timing(); InputStream _in = new BufferedInputStream( new FileInputStream(cur_path + File.separator + selected_file)); byte[] c = new byte[1024]; int j = 0; int count = 0; while ((j = _in.read(c)) != -1) { for (int i = 0; i < j; ++i) { if (c[i] == '\n') { count++; } } } _in.close(); if (header) { count--; } CSVReader in = new CSVReader(new FileReader(cur_path + File.separator + selected_file), '\n'); String[] line = null; long _n_ = 0; boolean first = true; while ((line = in.readNext()) != null) { if (first) { first = false; List<String> cols = new ArrayList(); cols.add("_N_"); String[] s = line[0].split(delimiter); if (header) { for (String h : s) { cols.add(h); } } else { for (int i = 1; i <= s.length; ++i) { cols.add("field_" + i); } } db.createTable(table, cols.toArray(new String[cols.size()])); db.insertBegin(table); if (header) { continue; } } _n_++; StringBuilder s = new StringBuilder(); s.append(_n_).append(StringEscapeUtils.unescapeJava(delimiter)).append(line[0]); db.insertInto(s.toString().split(delimiter)); if (_n_ == N) { db.force_insert(); view("SELECT * FROM " + table + " WHERE _N_ <= " + N + ";"); } if (_n_ % 100000 == 0) { txt_count.setText("Reading " + selected_file + ": " + Math.floor(_n_ * 1.0 / count * 100) + "% completed."); } } in.close(); db.insertFinish(); db.create_index(table, "_N_", true, true); db.close(); if (_n_ < N) { view("SELECT * FROM " + table + ";"); } cb_table.setEnabled(true); btn_execute.setEnabled(true); tp_sql.setEnabled(true); ck_export.setEnabled(true); btn_remove.setEnabled(true); txt_count.setText("Read " + String.valueOf(_n_) + " many lines and showed top " + Math.min(N, _n_) + ". Took " + timer.getSec() + "s."); } tr_files.grabFocus(); } catch (Exception e) { txt_count.setText(e.getMessage()); } } }); t[THREAD.read.ordinal()].start(); }
From source file:frames.MainGUI.java
public void LoadRentToJtable(JTable t, File file) { try {/*from ww w . j a v a 2s . co m*/ 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("??"); model.addColumn(""); model.addColumn("?"); model.addColumn("?"); model.addColumn(""); model.addColumn(""); t.setModel(model); model = (DefaultTableModel) t.getModel(); continue; } model.addRow(new Object[] { c.get(0), c.get(1), c.get(2), c.get(3), c.get(4), c.get(5) }); } } catch (Exception e) { System.out.println(e); } }
From source file:gui.Trabajadores.java
public void cargaSin() { try {/*from w w w . j a va 2 s . c o m*/ Database con = new Database(); DefaultTableModel modelo = new DefaultTableModel(); this.tablaSin.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:gui.Trabajadores.java
public void cargaControladores() { try {/*w ww .ja v a2 s . com*/ Database con = new Database(); DefaultTableModel modelo = new DefaultTableModel(); this.tablaControladores.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 getDvdBtnActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_getDvdBtnActionPerformed String dvdCodeStr = dvdCodeTxt.getText(); errorLabelReserve.setVisible(false); copyTable.setVisible(false);/*from www .j av a2 s . c o m*/ copyTable.setModel(new DefaultTableModel()); boolean isMatched = false; DefaultTableModel model = new DefaultTableModel(); model.setColumnIdentifiers(new String[] { "Copy Number", "ISLE Number", "Shelf Number", "is Available " }); if (dvdCodeStr != null && !dvdCodeStr.isEmpty()) { int dvdCodeInt = 0; try { dvdCodeInt = Integer.parseInt(dvdCodeStr); // Get DVD Service for (Dvd dvd : searchDVDList) { if (dvd.getCode() == dvdCodeInt) { isMatched = true; jLabelDVDCode.setText(String.valueOf(dvd.getCode())); jLabelDVDCode1.setText(String.valueOf(dvd.getCode())); jLabelDVDTitle.setText(dvd.getTitle()); jLabelDVDTitle1.setText(dvd.getTitle()); jLabelYear.setText(String.valueOf(dvd.getYear())); jLabelImdb.setText(String.valueOf(dvd.getRating())); jLabelActors.setText(dvd.getActors()); jLabelFormat.setText(dvd.getDefiniiton()); // Get Copies from DVD code - Service DVDRepository dVDRepository = new DVDRepository(); try { if (isServiceOn) { searchCopyDVDList = new ArrayList<DvdCopy>(); searchCopyDVDList = dVDRepository.getCopyDVDList(dvdCodeInt); } else { com.dvd.hibernate.repo.DVDRepository repository = new com.dvd.hibernate.repo.DVDRepository(); searchCopyDVDList = new ArrayList<DvdCopy>(); List<DVDCopyDao> s = repository.getCopyDVDList(dvdCodeInt); if (s != null) { for (DVDCopyDao dvdCopyDao : s) { searchCopyDVDList.add(new DvdCopy(dvdCopyDao.getIsleNumber(), String.valueOf(dvdCopyDao.getCopyNumber()), dvdCopyDao.getShelfNumber(), dvd, dvdCopyDao.isAvailable())); } } } } catch (Exception ex) { Logger.getLogger(SearchDVD.class.getName()).log(Level.SEVERE, null, ex); } for (DvdCopy copy : searchCopyDVDList) { model.addRow(new String[] { copy.getCopyNumber(), copy.getIsleNumber(), copy.getShelfNumber(), String.valueOf(copy.isIsAvailable()) }); } jLabelCopies.setText(String.valueOf(searchCopyDVDList.size())); copyTable.setVisible(true); copyTable.setModel(model); } } if (!isMatched) { errorLabelReserve.setVisible(true); errorLabelReserve.setText("No DVD match"); } } catch (Exception e) { errorLabelReserve.setText(""); errorLabelReserve.setVisible(true); errorLabelReserve.setText("Please enter a valid DVD Code"); resetData(); } } else { resetData(); errorLabelReserve.setVisible(true); errorLabelReserve.setText("Please enter a valid DVD Code"); } }
From source file:gui.Trabajadores.java
public void cargaDistribucion() { try {//w w w .j a v a2 s. c om Database con = new Database(); DefaultTableModel modelo = new DefaultTableModel(); this.tablaDistri.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.smanempat.view.ViewClassification.java
private void tampilKeTabel(String[] finalClass, int rowCountData) { DefaultTableModel tableModelResult = new DefaultTableModel(); tableModelResult = (DefaultTableModel) tableResult.getModel(); int jumlahSiswaIPA = 0; int jumlahSiswaIPS = 0; for (int i = 0; i < rowCountData; i++) { if (finalClass[i].equals("IPA")) { jumlahSiswaIPA = jumlahSiswaIPA + 1; } else if (finalClass[i].equalsIgnoreCase("IPS")) { jumlahSiswaIPS = jumlahSiswaIPS + 1; }//from ww w .j a v a 2 s .c o m String nis = tablePreview.getValueAt(i, 0).toString(); String nama = tablePreview.getValueAt(i, 1).toString(); String jenKel = tablePreview.getValueAt(i, 2).toString(); String nilaiUN = tablePreview.getValueAt(i, 3).toString(); String ptBindo = tablePreview.getValueAt(i, 4).toString(); String ptMtk = tablePreview.getValueAt(i, 5).toString(); String ptBing = tablePreview.getValueAt(i, 6).toString(); String ptIpa = tablePreview.getValueAt(i, 7).toString(); String minat = tablePreview.getValueAt(i, 8).toString(); String jurusan = finalClass[i]; Object[] resultData = { nis, nama, jenKel, nilaiUN, ptBindo, ptMtk, ptBing, ptIpa, minat, jurusan }; tableModelResult.addRow(resultData); } jTabbedPane1.setSelectedIndex(1); labelKeterangan.setText("Hasil Klasifikasi Penjurusan Siswa Pada Tahun Ajaran " + jYearChooser1.getYear() + "/" + jYearChooser2.getYear() + ", dengan kriteria manual adalah sebagai berikut "); labelSiswaIPA.setText(jumlahSiswaIPA + ""); labelSiswaIPS.setText(jumlahSiswaIPS + ""); System.out.println("Jumlah IPA " + jumlahSiswaIPA); System.out.println("Jumlah IPS " + jumlahSiswaIPS); }
From source file:gui.Trabajadores.java
public void cargaSalario() { try {// ww w . j a v a 2s . c om Database con = new Database(); DefaultTableModel modelo = new DefaultTableModel(); this.salario.setModel(modelo); Connection conn = con.conectar(); String sentencia = ""; 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:gui.Trabajadores.java
public void cargaAntiguedad() { try {/*from w w w. j ava2s . co m*/ Database con = new Database(); DefaultTableModel modelo = new DefaultTableModel(); this.antiguedad.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:dataviewer.DataViewer.java
private void view(String _sql) { final String sql = _sql; // check pivot t[THREAD.view.ordinal()].stop();// w w w . j a va 2 s .com t[THREAD.view.ordinal()] = new Thread(new Runnable() { @Override public void run() { try { Timing timer = new Timing(); boolean alive = t[THREAD.read.ordinal()].isAlive(); if (!alive) { txt_count.setText("Running query ... "); } DB db = new DB("./db/" + table + ".db"); db.open(); ResultSet results = db.execute(sql); String csv = ""; CSVWriter out = null; boolean asked = false; if (export && ck_export.isEnabled()) { csv = JOptionPane.showInputDialog(new JFrame(""), "Please enter the name of the file without extension.", "Export File Name", JOptionPane.PLAIN_MESSAGE); if (csv == null) { csv = ""; } if (!csv.equals("")) { out = new CSVWriter(new FileWriter("./output/" + csv + ".txt"), '\n', CSVWriter.NO_QUOTE_CHARACTER, CSVWriter.NO_ESCAPE_CHARACTER); } } String _delimiter = StringEscapeUtils.unescapeJava(delimiter); StringBuilder sb = new StringBuilder(); List<String> cols = new ArrayList(); for (int i = 0; i < results.getMetaData().getColumnCount(); ++i) { String name = results.getMetaData().getColumnName(i + 1); cols.add(name); sb.append(name).append(_delimiter); } sb.setLength(sb.length() - 1); DefaultTableModel model = new DefaultTableModel(); for (int i = 0; i < cols.size(); ++i) { model.addColumn(cols.get(i)); } if (!csv.equals("")) { out.writeNext(sb.toString()); } String[] vals; long count = 0; boolean is_model_render = false; while (results.next()) { count++; vals = new String[cols.size()]; sb = new StringBuilder(); for (int i = 0; i < cols.size(); ++i) { vals[i] = results.getString(cols.get(i)); sb.append(vals[i]).append(_delimiter); } sb.setLength(sb.length() - 1); if (!csv.equals("")) { out.writeNext(sb.toString()); } if (asked == false && is_model_render == false && count > N) { if (JOptionPane.showConfirmDialog(null, "Number of rows are more than " + N + ". Stop?", "", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { renderData(model); is_model_render = true; } asked = true; } if (is_model_render == false) { model.addRow(vals); } } db.close(); if (is_model_render == false) { if (transpose) { tb_data.setModel(model); transpose((DefaultTableModel) tb_data.getModel()); } else { renderData(model); } } if (!csv.equals("")) { out.close(); txt_count.setText(count + " records are queried from " + table + " and exported to /output/" + csv + ".txt. Took " + timer.getSec() + "s."); } else if (!alive) { if (is_model_render) { txt_count.setText(count + " records are queried from " + table + " but stopped at " + N + ". Took " + timer.getSec() + "s."); } else { txt_count.setText(count + " records are queried from " + table + ". Took " + timer.getSec() + "s."); } } } catch (Exception e) { txt_count.setText(e.getMessage()); } } }); t[THREAD.view.ordinal()].start(); }