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:gui.Trabajadores.java
public void cargaEdad() { try {/*from w w w .j av a 2s .co m*/ Database con = new Database(); DefaultTableModel modelo = new DefaultTableModel(); this.edad.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:gdt.jgui.entity.query.JQueryPanel.java
private void clearHeader() { int response = JOptionPane.showConfirmDialog(this, "Clear header ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { try {//from ww w. j a v a 2 s .c om Entigrator entigrator = console.getEntigrator(entihome$); Sack query = entigrator.getEntityAtKey(entityKey$); query.removeElement("header.element"); query.removeElement("header.item"); query.removeElement("exclude"); entigrator.save(query); DefaultTableModel model = new DefaultTableModel(); table.setModel(model); } catch (Exception e) { LOGGER.severe(e.toString()); } } }
From source file:gui.Trabajadores.java
public void cargaTurnoSin() { try {//from ww w . j a va2s. c om Database con = new Database(); DefaultTableModel modelo = new DefaultTableModel(); this.turnosin.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:gdt.jgui.entity.query.JQueryPanel.java
private void removeColumn() { String itemName$ = (String) itemNameComboBox.getSelectedItem(); if ("label".equals(itemName$)) return;/* w w w . j a v a 2s .c o m*/ int response = JOptionPane.showConfirmDialog(this, "Remove column '" + itemName$ + "' ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { try { Entigrator entigrator = console.getEntigrator(entihome$); Sack query = entigrator.getEntityAtKey(entityKey$); Core[] ca = query.elementGet("header.item"); for (Core c : ca) { if (itemName$.equals(c.value)) { query.removeElementItem("header.element", c.name); query.removeElementItem("header.item", c.name); } } entigrator.save(query); DefaultTableModel model = new DefaultTableModel(); table.setModel(model); showHeader(); showContent(); } catch (Exception e) { LOGGER.severe(e.toString()); } } }
From source file:gui.Trabajadores.java
public void cargaturnosControl() { try {//from www . jav a2s. c o m Database con = new Database(); DefaultTableModel modelo = new DefaultTableModel(); this.turnoCont.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 transpose(DefaultTableModel model) { try {/* ww w .java 2s . co m*/ if (model.getColumnCount() == 0) { return; } DefaultTableModel new_model = new DefaultTableModel(); // if not transposed if (!model.getColumnName(0).equals("_field_") && transpose == true) { new_model.addColumn("_field_"); for (int r = 1; r <= model.getRowCount(); ++r) { new_model.addColumn("_col_" + r); } long n = 1; for (int c = 0; c < model.getColumnCount(); ++c) { Object[] s = new Object[new_model.getColumnCount()]; String colname = model.getColumnName(c); int l = 0; s[l++] = colname; for (int r = 0; r < model.getRowCount(); ++r) { s[r + l] = model.getValueAt(r, c); } new_model.addRow(s); } } if (model.getColumnName(0).equals("_field_") && transpose == false) { // if transposed for (int r = 0; r < model.getRowCount(); ++r) { new_model.addColumn(model.getValueAt(r, 0)); } List<Integer> colIdx = new ArrayList(); for (int c = 0; c < model.getColumnCount(); ++c) { if (!model.getColumnName(c).equals("_field_")) { colIdx.add(c); } } for (int c = 0; c < colIdx.size(); ++c) { Object[] s = new Object[new_model.getColumnCount()]; for (int r = 0; r < model.getRowCount(); ++r) { s[r] = model.getValueAt(r, colIdx.get(c)); } new_model.addRow(s); } } renderData(new_model); } catch (Exception e) { txt_count.setText(e.getMessage()); } }
From source file:edu.ku.brc.af.ui.forms.persist.ViewLoader.java
/** * Di// w w w . j a va2 s.c o m */ public static void displayFieldVerInfo() { if (verifyDlg != null) { verifyDlg.setVisible(false); verifyDlg.dispose(); verifyDlg = null; } System.err.println("------------- " + (instance.fldVerTableModel != null ? instance.fldVerTableModel.getRowCount() : "null")); if (instance.fldVerTableModel != null && instance.fldVerTableModel.getRowCount() > 0) { JLabel lbl = UIHelper.createLabel( "<html><i>(Some of fields are special buttons or labal names. Review them to make sure you have not <br>mis-named any of the fields you are working with.)"); final JTable table = new JTable(instance.fldVerTableModel); UIHelper.calcColumnWidths(table); CellConstraints cc = new CellConstraints(); JScrollPane sp = new JScrollPane(table, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "f:p:g,4px,p")); pb.add(sp, cc.xy(1, 1)); pb.add(lbl, cc.xy(1, 3)); pb.setDefaultDialogBorder(); verifyDlg = new CustomFrame( "Field Names on Form, but not in Database : " + instance.fldVerTableModel.getRowCount(), CustomFrame.OK_BTN, pb.getPanel()) { @Override protected void okButtonPressed() { super.okButtonPressed(); table.setModel(new DefaultTableModel()); dispose(); verifyDlg = null; } }; verifyDlg.setOkLabel(getResourceString("CLOSE")); verifyDlg.createUI(); verifyDlg.setVisible(true); } }
From source file:com.farouk.projectapp.FirstGUI.java
private void UpdatejTable2() { DefaultTableModel modelPortfolio = new DefaultTableModel(); total = new BigDecimal(0); modelPortfolio.setColumnIdentifiers(new String[] { "Name", "Symbol", "Stock Price ()", "Bid Price", "Ask Price", "Quantity Bought", "Price Paid" }); for (Company com : SQLConnect.getPortfolioCompanies(userID)) { modelPortfolio//w w w .j a v a2 s . c o m .addRow(new String[] { com.getName(), com.getSymbol(), String.valueOf(com.getStockPrice().doubleValue()), String.valueOf(com.getBidPrice().doubleValue()), String.valueOf(com.getAskPrice().doubleValue()), Integer.toString(com.getNumberOwned()), String.valueOf((com.getStockPrice() .multiply(new BigDecimal(Integer.toString(com.getNumberOwned()))) .doubleValue())) }); String disturbed = Integer.toString(com.getNumberOwned()); BigDecimal aa = new BigDecimal(disturbed); total = total.add(com.getStockPrice().multiply(aa)); } jLabel10.setText("Total is : " + String.valueOf(total.doubleValue()) + ""); jTable2.setModel(modelPortfolio); }
From source file:com.farouk.projectapp.FirstGUI.java
private void UpdatejTable3(Company com) { DefaultTableModel modelCompany = new DefaultTableModel(); modelCompany.setColumnIdentifiers(new String[] { "Name", "Symbol", "Stock Price ()", "Bid Price", "Ask Price", "Quantity Bought" }); modelCompany.addRow(new String[] { com.getName(), com.getSymbol(), String.valueOf(com.getStockPrice().doubleValue()), String.valueOf(com.getBidPrice().doubleValue()), String.valueOf(com.getAskPrice().doubleValue()), Integer.toString(com.getNumberOwned()) }); jTable3.setModel(modelCompany);// ww w. j av a2 s . com }
From source file:com.SE.myPlayer.MusicPlayerGUI.java
public void tableReferesh(JTable songData_Table, String tableName, String columName) { int emptyResultSet = 0; try {// www . j a v a 2s. c o m con = db.getCon(); stmt = con.createStatement(); ResultSet rs; switch (tableName) { case "library": rs = stmt.executeQuery("select * from library order by " + columName + ""); break; case "playlist": rs = stmt.executeQuery("select * from library order by " + columName + ""); break; default: rs = stmt.executeQuery( "Select library.id_songs, library.song_location, library.song_name, library.song_album, library.song_artist, library.genre, library.year, library.time, library.comment from playlist INNER JOIN library ON library.id_songs = playlist.id_songs AND playlist.playlist_name = '" + tableName + "' order by " + columName + ""); break; } DefaultTableModel myModel = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { return false; } }; String[] songsColumnsName = { "Location", "Name", "Album", "Artist", "Genre", "Year", "Time", "Comment" }; myModel.setColumnIdentifiers(songsColumnsName); ResultSetMetaData rsmd = rs.getMetaData(); int colNumbers = rsmd.getColumnCount(); Object[] objects = new Object[colNumbers]; while (rs.next()) { emptyResultSet = 1; for (int i = 0; i < colNumbers - 1; i++) { objects[i] = rs.getObject(i + 2); } myModel.addRow(objects); } if (emptyResultSet == 0) { myModel.addRow(objects); } songData_Table.setModel(myModel); rs = stmt.executeQuery("select col_name from col_name where col_status = 0"); while (rs.next()) { songData_Table.removeColumn(songData_Table.getColumn(rs.getString(1))); } songData_Table.getTableHeader().removeMouseListener(ma); songData_Table.getTableHeader().addMouseListener(ma); songData_Table.setDragEnabled(true); songData_Table.setDropTarget(new DropTarget() { @Override public synchronized void drop(DropTargetDropEvent dtde) { dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); Transferable t = dtde.getTransferable(); try { if (dtde.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { Object fileList = t.getTransferData(DataFlavor.javaFileListFlavor); String files = fileList.toString(); finalString = convertFileString(files); if (dropControl == 0 && lastOpen.equals("library")) { songAddDB(finalString); } else if (dropControl == 0 && !lastOpen.equals("library")) { songAddPlaylistFromLibrary(lastOpen, finalString); getSongTable(lastOpen); } else { songAddPlaylistFromLibrary(tableName, finalString); } } else if (dtde.isDataFlavorSupported(DataFlavor.stringFlavor)) { Object fileList = t.getTransferData(DataFlavor.stringFlavor); String fileListString = fileList.toString(); fileListString = Arrays.toString(fileListString.split("\\n")); String[] splitLocations = fileListString.split(",\\s"); for (int i = 0; i < splitLocations.length; i++) { if (i == 0) { splitLocations[i] = splitLocations[i].substring(1, splitLocations[i].indexOf(".mp3") + 4); } else { splitLocations[i] = splitLocations[i].substring(0, splitLocations[i].indexOf(".mp3") + 4); } } for (int i = 0; i < splitLocations.length; i++) { splitLocations[i] = sd.getLocations(splitLocations[i]); } finalString = Arrays.asList(splitLocations); if (dropControl == 0 && lastOpen.equals("library")) { songAddDB(finalString); } else if (dropControl == 0 && !lastOpen.equals("library")) { songAddPlaylistFromLibrary(lastOpen, finalString); getSongTable(lastOpen); } else { songAddPlaylistFromLibrary(tableName, finalString); } } } catch (UnsupportedFlavorException | IOException | InvalidDataException | UnsupportedTagException ex) { System.out.println("Error in second drop flavour............" + ex); } } }); if (con != null) { stmt.close(); con.close(); } } catch (SQLException e) { System.out.println("Error in Stmt " + e); } }