List of usage examples for javax.swing.table DefaultTableModel getRowCount
public int getRowCount()
From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java
/** * Add target villages externally (see DSWorkbenchMainFrame) * * @param pVillages/* www .j a va 2s. c o m*/ */ public void fireAddTargetsEvent(List<Village> pVillages) { DefaultTableModel victimModel = (DefaultTableModel) jVictimTable.getModel(); for (Village v : pVillages) { if (v != null) { boolean contains = false; for (int row = 0; row < victimModel.getRowCount(); row++) { if (victimModel.getValueAt(row, 1).equals(v)) { contains = true; break; } } if (!contains) { int maxAttacks = 1; try { maxAttacks = (Integer) jMaxAttacksPerVillage.getValue(); } catch (Exception e) { maxAttacks = 1; } if (v != null) { victimModel.addRow( new Object[] { v.getTribe(), v, jMarkTargetAsFake.isSelected(), maxAttacks, 0 }); } } } } updateInfo(); ((DefaultTableModel) jVictimTable.getModel()).fireTableDataChanged(); }
From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java
private void showAttackInfoEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_showAttackInfoEvent DefaultTableModel victimModel = (DefaultTableModel) jVictimTable.getModel(); List<Village> victimVillages = new LinkedList<Village>(); List<Village> victimVillagesFaked = new LinkedList<Village>(); for (int i = 0; i < victimModel.getRowCount(); i++) { if ((Boolean) victimModel.getValueAt(i, 2) == Boolean.TRUE) { victimVillagesFaked.add((Village) victimModel.getValueAt(i, 1)); } else {// www . j a va 2s.co m victimVillages.add((Village) victimModel.getValueAt(i, 1)); } } DefaultTableModel attackModel = (DefaultTableModel) jSourcesTable.getModel(); Hashtable<UnitHolder, List<Village>> sources = new Hashtable<UnitHolder, List<Village>>(); Hashtable<UnitHolder, List<Village>> fakes = new Hashtable<UnitHolder, List<Village>>(); for (int i = 0; i < attackModel.getRowCount(); i++) { Village vSource = (Village) attackModel.getValueAt(i, 0); UnitHolder uSource = (UnitHolder) attackModel.getValueAt(i, 1); boolean fake = (Boolean) attackModel.getValueAt(i, 2); if (!fake) { List<Village> sourcesForUnit = sources.get(uSource); if (sourcesForUnit == null) { sourcesForUnit = new LinkedList<Village>(); sourcesForUnit.add(vSource); sources.put(uSource, sourcesForUnit); } else { sourcesForUnit.add(vSource); } } else { List<Village> fakesForUnit = fakes.get(uSource); if (fakesForUnit == null) { fakesForUnit = new LinkedList<Village>(); fakesForUnit.add(vSource); fakes.put(uSource, fakesForUnit); } else { fakesForUnit.add(vSource); } } } DSWorkbenchAttackInfoPanel info = new DSWorkbenchAttackInfoPanel(); info.setVillages(sources, victimVillages, fakes, victimVillagesFaked); JFrame f = new JFrame(); f.add(info); info.refresh(); f.setSize(info.getWidth(), info.getHeight()); f.pack(); f.setVisible(true); }
From source file:Sales.TabbedPaneWin.java
private void createInvoiceBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createInvoiceBtnActionPerformed DefaultTableModel model = (DefaultTableModel) clientCartTable.getModel(); String[] itemCode = new String[model.getRowCount()]; int[] saleQty = new int[model.getRowCount()]; if (Validate.isValidInvoiceId(invoiceNoTxtF.getText())) { if (Validate.isValidClientId(clientIdTxtF.getText())) { if (Validate.isValidOrderId(clientIdTxtF1.getText())) { if (Validate.isValidDiscount(discountTxtF.getText())) { if (Validate.isValidPrice(totalPaymentTxtF.getText())) { if (Validate.isValidPrice(duePaymentTxtF.getText())) { OOInvoice.setINVOICENO(invoiceNoTxtF.getText()); OOInvoice.setINVOICEDATE(invoiceDateTxtF.getText()); OOInvoice.setCLIENTIDFK(clientIdTxtF.getText()); OOInvoice.setREMARKS(remarksTxtF.getText()); OOInvoice.setDUEPAYMENT(Double.parseDouble(duePaymentTxtF.getText())); OOInvoice.setTOTALPAYMENT(Double.parseDouble(totalPaymentTxtF.getText())); OOInvoice.setDISCOUNT(Double.parseDouble(discountTxtF.getText())); OOInvoice.setGRANDTOTAL(Double.parseDouble(grandTotalLbl1.getText())); OOInvoice.setTOTALAMOUNT(Double.parseDouble(totAmountLbl1.getText())); OOInvoice.setORDERID(clientIdTxtF1.getText()); OOInvoice.setPAYMENTTYPE(jComboBox1.getSelectedItem().toString()); for (int i = 0; i < model.getRowCount(); i++) { itemCode[i] = clientCartTable.getModel().getValueAt(i, 0).toString(); }//ww w . ja v a2s .com for (int i = 0; i < model.getRowCount(); i++) { saleQty[i] = (int) clientCartTable.getModel().getValueAt(i, 3); } OOInvoice.setITEMCODE(itemCode); OOInvoice.setSALEQTY(saleQty); try { //insert if (OOInvoice.insertInvoice(model.getRowCount())) {//row count (0,1,2..) or (0) for nothing JOptionPane.showMessageDialog(null, "Invoice Creation Successfull"); resetInvoiceFields(); } else { JOptionPane.showMessageDialog(null, "Error: Use existing ClientID.."); } } catch (Exception ex) { System.out.println(ex.getMessage()); } } else { jLabel82.setVisible(true); JOptionPane.showMessageDialog(null, "Enter valid Due Payment ..."); } } else { jLabel83.setVisible(true); JOptionPane.showMessageDialog(null, "Enter valid Total Payment ..."); } } else { jLabel79.setVisible(true); JOptionPane.showMessageDialog(null, "Enter valid discount ..."); } } else { jLabel81.setVisible(true); JOptionPane.showMessageDialog(null, "Enter valid OrderId ..."); } } else { jLabel78.setVisible(true); JOptionPane.showMessageDialog(null, "Enter valid ClientID ..."); } } else { jLabel77.setVisible(true); JOptionPane.showMessageDialog(null, "Enter valid InvoiceID ..."); } jLabel79.setVisible(false); jLabel82.setVisible(false); jLabel77.setVisible(false); jLabel78.setVisible(false); jLabel81.setVisible(false); jLabel83.setVisible(false); }
From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java
private void editUseSnobs() { int idx = jideTabbedPane1.getSelectedIndex(); if (idx == 0) { //use snobs in villages where snobs exist DefaultTableModel model = (DefaultTableModel) jSourcesTable.getModel(); UnitHolder snob = DataHolder.getSingleton().getUnitByPlainName("snob"); jSourcesTable.invalidate();/*w ww. j a v a2 s . co m*/ Hashtable<Village, Integer> assignedTroops = new Hashtable<Village, Integer>(); for (int row = 0; row < model.getRowCount(); row++) { Village v = (Village) model.getValueAt(row, jSourcesTable.convertColumnIndexToModel(0)); VillageTroopsHolder troops = TroopsManager.getSingleton().getTroopsForVillage(v, TroopsManager.TROOP_TYPE.IN_VILLAGE); if (troops != null) { int availSnobs = troops.getTroopsOfUnitInVillage(snob); Integer assignedSnobs = assignedTroops.get(v); if (assignedSnobs == null) { assignedSnobs = 0; } else { assignedSnobs += 1; } availSnobs -= assignedSnobs; assignedTroops.put(v, assignedSnobs); //snob avail if (availSnobs > 0) { model.setValueAt(snob, row, jSourcesTable.convertColumnIndexToModel(1)); } } } showInfo("Vorhandene AGs eingetragen"); } else { showInfo("Diese Funktion ist nur fr Herkunftsdrfer verfgbar"); } }
From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java
private void targetFromInternalClipboardAction() { String data = ""; try {/*from w ww. j av a 2 s . c o m*/ data = (String) Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null) .getTransferData(DataFlavor.stringFlavor); String[] lines = data.split("\n"); int cnt = 0; DefaultTableModel theModel = (DefaultTableModel) jVictimTable.getModel(); for (String line : lines) { String[] split = line.split(";"); Village v = DataHolder.getSingleton().getVillagesById().get(Integer.parseInt(split[0])); if (v != null) { boolean added = false; for (int i = 0; i < theModel.getRowCount(); i++) { if (jVictimTable.getValueAt(i, 1).equals(v)) { Integer amount = (Integer) jVictimTable.getValueAt(i, 3); jVictimTable.setValueAt(amount + 1, i, 3); cnt++; added = true; break; } } if (!added) { Boolean fake = Boolean.parseBoolean(split[1]); Integer attacks = Integer.parseInt(split[2]); if (attacks != null) { theModel.addRow(new Object[] { v.getTribe(), v, fake, attacks, 0 }); cnt++; } } } } showSuccess(cnt + ((cnt == 1) ? " Eintrag eingefgt" : " Eintrge eingefgt")); } catch (UnsupportedFlavorException ufe) { logger.error("Failed to copy data from internal clipboard", ufe); showError("Fehler beim Einfgen aus der Zwischenablage"); } catch (IOException ioe) { logger.error("Failed to copy data from internal clipboard", ioe); showError("Fehler beim Einfgen aus der Zwischenablage"); } catch (NumberFormatException nfe) { //invalid paste, try village parser List<Village> villages = PluginManager.getSingleton().executeVillageParser(data); if (!villages.isEmpty()) { addTargetVillages(villages); } else { showInfo("Keine verwendbaren Daten in der Zwischenablage gefunden"); } } }
From source file:library.Form_Library.java
License:asdf
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed JFileChooser chooser = new JFileChooser(); int k = chooser.showSaveDialog(this); if (k == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try {/*from w w w . j a v a 2s . com*/ FileWriter out = new FileWriter(file + ".xls"); BufferedWriter bu = new BufferedWriter(out); DefaultTableModel model = (DefaultTableModel) tbBookAdmin.getModel(); for (int i = 0; i < model.getColumnCount(); i++) { bu.write(model.getColumnName(i) + "\t"); } bu.write("\n"); for (int i = 0; i < model.getRowCount(); i++) { for (int j = 0; j < model.getColumnCount(); j++) { bu.write(model.getValueAt(i, j) + "\t"); } bu.write("\n"); } bu.close(); JOptionPane.showMessageDialog(this, "Saved"); } catch (IOException ex) { JOptionPane.showMessageDialog(this, "Can't Save"); } } }
From source file:com.osparking.attendant.AttListForm.java
/** * Update attendant listing table by accessing database table. * It also //from ww w.j a v a2 s . c om * @return */ private int loadAttendantTable(String newID) { DefaultTableModel model = (DefaultTableModel) usersTable.getModel(); Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; StringBuilder sb = new StringBuilder(); sb.append("Select id as 'User ID', name as 'Name', "); sb.append("if(isManager, 'Y', 'N') as 'Manager', "); sb.append("cellphone as 'Cell', phone as 'Phone', email as 'E-mail', "); sb.append("date_format(creationTime, '%Y-%m-%d') as 'Created', "); sb.append("date_format(lastModiTime, '%Y-%m-%d') as 'Modified' "); sb.append("from users_osp"); prevSearchColumn = currSearchColumn; prevSearchString = currSearchString; if (currSearchString.length() > 0) { if (currSearchColumn == LOGIN_ID_LABEL) { sb.append(" Where ID like ? "); } else { sb.append(" Where Name like ? "); } if (newID.length() > 0) { sb.append("or (ID = ?)"); } } try { conn = JDBCMySQL.getConnection(); pstmt = conn.prepareStatement(sb.toString()); int index = 1; if (currSearchString.length() > 0) { pstmt.setString(index++, "%" + currSearchString + "%"); if (newID.length() > 0) { pstmt.setString(index++, newID); } } rs = pstmt.executeQuery(); model.setRowCount(0); while (rs.next()) { model.addRow(new Object[] { rs.getString("User ID"), rs.getString("Name"), rs.getString("Manager"), rs.getString("Cell"), rs.getString("Phone"), rs.getString("E-mail"), rs.getString("Created"), rs.getString("Modified") }); } } catch (Exception ex) { logParkingException(Level.SEVERE, ex, "(refresh user list displaying table)"); } finally { closeDBstuff(conn, pstmt, rs, "(refresh user list displaying table)"); adjustTableHeight(usersTable); countValue.setText(String.valueOf(usersTable.getRowCount())); if (newID.length() > 0 && newIDnotSatisfySearchCondition(newID)) { searchButton.setEnabled(true); } else { searchButton.setEnabled(false); } return model.getRowCount(); } }
From source file:interfaces.InterfazPrincipal.java
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed // TODO add your handling code here: String identificacion = jTextFieldNitProveedores.getText(); String nombre = jTextFieldNombreProveedores.getText(); int identificacionClienteInt = 0; try {// w ww. ja v a 2 s . com ControladorProveedores controladorProveedores = new ControladorProveedores(); ArrayList<Proveedores> listaDeProveedores = controladorProveedores.obtenerProveedores(identificacion, nombre); //Agregar filas DefaultTableModel modelo = (DefaultTableModel) TablaDeProveedores.getModel(); for (int i = 0; i < modelo.getRowCount(); i++) { modelo.removeRow(i); } modelo.setRowCount(0); for (int i = 0; i < listaDeProveedores.size(); i++) { Proveedores proveedor = listaDeProveedores.get(i); Object[] fila = new Object[4]; fila[0] = proveedor.getIdentificacion(); fila[1] = proveedor.getNombre(); //button.setText("<HTML>Click the <FONT color=\"#000099\"><U>link "+i+"</U></FONT>"+ " to go to the Java website.</HTML>"); fila[3] = "Editar"; modelo.addRow(fila); } TablaDeProveedores.setModel(modelo); } catch (Exception e) { JOptionPane.showMessageDialog(this, "Buscar con campos validos", "Error", JOptionPane.ERROR_MESSAGE); } //TablaDeProveedores }
From source file:interfaces.InterfazPrincipal.java
public void generarTablaUsuarios() { //tablaUsuariosDelSistema ControladorUsuarios controladorUsuarios = new ControladorUsuarios(); ArrayList<Usuarios> listaUsuarios = controladorUsuarios.obtenerTodosUsuarios(); DefaultTableModel modeloTabla = (DefaultTableModel) tablaUsuariosDelSistema.getModel(); for (int i = 0; i < modeloTabla.getRowCount(); i++) { modeloTabla.removeRow(i);//from ww w . j a v a 2 s.com } modeloTabla.setRowCount(0); for (int i = 0; i < listaUsuarios.size(); i++) { Usuarios usuarioActual = listaUsuarios.get(i); Object[] rowData = new Object[3]; rowData[0] = usuarioActual.getLogin(); rowData[1] = usuarioActual.getCreation_data(); char habilitado = usuarioActual.getStatus(); if (habilitado == 'e') { rowData[2] = "Habilitado"; } else { rowData[2] = "Inhablitado"; } modeloTabla.addRow(rowData); } tablaUsuariosDelSistema.setModel(modeloTabla); }
From source file:interfaces.InterfazPrincipal.java
private void BotonBuscarClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonBuscarClienteActionPerformed // TODO add your handling code here: String nombreCliente = nombreClienteBusqueda.getText(); String identificacionCliente = identificacionClienteBusqueda.getText(); int identificacionClienteInt = 0; try {/*from w w w . ja v a2s .c o m*/ if (!identificacionCliente.equals("")) { identificacionClienteInt = Integer.parseInt(identificacionCliente); } ControladorCliente controladorCliente = new ControladorCliente(); ArrayList<Cliente> listaDeClientes = controladorCliente.obtenerClientes(nombreCliente, identificacionClienteInt); //Agregar filas DefaultTableModel modelo = (DefaultTableModel) TablaDeClientes.getModel(); for (int i = 0; i < modelo.getRowCount(); i++) { modelo.removeRow(i); } modelo.setRowCount(0); for (int i = 0; i < listaDeClientes.size(); i++) { Cliente cliente = listaDeClientes.get(i); Object[] fila = new Object[4]; fila[0] = cliente.getCliente_id(); fila[1] = cliente.getNombre(); Double montoAPrestar = cliente.getMonto_prestamo(); NumberFormat formatter = new DecimalFormat("#0"); fila[2] = formatter.format(montoAPrestar); fila[3] = "Editar"; modelo.addRow(fila); } TablaDeClientes.setModel(modelo); } catch (Exception e) { JOptionPane.showMessageDialog(this, "La identificacin debe ser numrica, por favor ingrese correctamente el dato", "Error", JOptionPane.ERROR_MESSAGE); } }