List of usage examples for javax.swing.table DefaultTableModel addRow
public void addRow(Object[] rowData)
From source file:StockForecast.Main.java
private void displayUser() throws Exception { String selectItem = jComboBox2.getSelectedItem().toString(); Connect connect = new Connect(); DefaultTableModel displayTable = new DefaultTableModel(); String text = jComboBox4.getSelectedItem().toString(); System.out.println(text.toUpperCase()); displayTable.addColumn("User ID"); displayTable.addColumn("Username"); displayTable.addColumn("Password"); displayTable.addColumn("User Type"); displayTable.addColumn("Name"); displayTable.addColumn(""); displayTable.addColumn(""); ResultSet rs = connect.connectSelect("1", "SELECT * FROM ROOT.LOGIN NATURAL JOIN PROFILE WHERE LOGINID='" + text + "'"); displayTable.addRow(new Object[] { rs.getString("loginid"), rs.getString("username"), rs.getString("password"), rs.getString("usertype"), rs.getString("name"), "Delete", "Update" }); jTable1.setModel(displayTable);// ww w . ja v a 2s .c o m Action delete = new AbstractAction() { public void actionPerformed(ActionEvent e) { JTable table = (JTable) e.getSource(); int modelRow = Integer.valueOf(e.getActionCommand()); ((DefaultTableModel) table.getModel()).removeRow(modelRow); } }; ButtonColumn buttonColumn = new ButtonColumn(jTable1, delete, 5); ButtonColumn btnColumn = new ButtonColumn(jTable1, delete, 6); buttonColumn.setMnemonic(KeyEvent.VK_D); btnColumn.setMnemonic(KeyEvent.VK_U); }
From source file:StockForecast.Stock.java
private void displayStock() throws Exception { DefaultTableModel model = new DefaultTableModel(); jTable1.setModel(model);//from w w w .ja va2 s . com model.addColumn("Entity Name"); model.addColumn("Symbol"); Connect connect = new Connect(); ResultSet rs = connect.connectSelect("1", "SELECT * FROM ROOT.STOCK"); while (rs.next()) { model.addRow(new Object[] { rs.getString(1), rs.getString(2) }); } }
From source file:thesis.Ontology_System.java
public void populate_search() { DefaultTableModel model = (DefaultTableModel) ad_table.getModel(); // table_overview.getColumnModel().getColumn(1).setCellRenderer(new TableCellLongTextRenderer ()); ad_table.getTableHeader().setFont(new java.awt.Font("Segoe UI", Font.BOLD, 14)); ad_table.getTableHeader().setBackground(Color.WHITE); ad_table.setShowGrid(true);//from ww w. j a va 2s . co m String searched = jTextField1.getText(); searched = "%" + searched + "%"; String category = (String) jComboBox1.getSelectedItem(); switch (category) { case "Ad/Product": { category = "ad_name"; break; } case "Brand": { category = "brand"; break; } case "Model": { category = "model"; break; } case "Site": { category = "site"; break; } } for (int row_index = ad_table.getRowCount(); ad_table.getRowCount() != 0; row_index--) { if (row_index == 0) { JOptionPane.showMessageDialog(null, "last"); } model.removeRow(row_index - 1); } try { sql = "SELECT * FROM `ontology_system_final_table` WHERE `" + category + "` LIKE '" + searched + "' "; pst = getConnectiontoDB().prepareStatement(sql); rs = pst.executeQuery(); while (rs.next()) { model.addRow(new Object[] { rs.getString("ad_name"), rs.getString("site"), rs.getString("brand"), rs.getString("model"), rs.getString("price"), rs.getString("chipset"), rs.getString("cpu"), rs.getString("camera_primary"), rs.getString("memory_internal") }); } } catch (SQLException err) { System.err.println(err); } }
From source file:tk.egsf.ddns.janela.java
private void JBatualizalistaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JBatualizalistaActionPerformed String https_url = "https://ddns.egsf.tk/webservice/gethosts"; String gethostsjson = JSON_helper.getJsonUrl(https_url, ddns.getBasicAuth()); if (gethostsjson == "") { return;/*from ww w. jav a 2 s . com*/ } JSONArray jsa = new JSONArray(gethostsjson); DefaultTableModel model = (DefaultTableModel) jTable1.getModel(); List<Boolean> selected = new ArrayList<Boolean>(); int rowcount = jTable1.getRowCount(); for (int i = 0; i < rowcount; i++) { selected.add((Boolean) jTable1.getValueAt(i, 2)); } model.setNumRows(0); try { for (int i = 0; i < jsa.length(); i++) { System.out.println(jsa.get(i)); JSONObject js = jsa.getJSONObject(i); Object[] row = new Object[] { js.getString("host") + "." + js.getString("zone"), js.getString("ip") }; model.addRow(row); } model.fireTableDataChanged(); for (int i = 0; i < selected.size(); i++) { Boolean boolean1 = selected.get(i); jTable1.setValueAt(boolean1, i, 2); } } catch (Exception e) { System.out.println("Erro: " + e.getMessage()); } }
From source file:UI.CreateRoom.java
/** * Creates new form CreateRoom/*from www . j a v a2s . c om*/ */ public CreateRoom() { initComponents(); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { super.windowClosing(e); HomePage homePage; try { homePage = new HomePage(); homePage.setVisible(true); } catch (JSONException ex) { Logger.getLogger(CreateRoom.class.getName()).log(Level.SEVERE, null, ex); } JSONObject response = null; try { response = SSLClient.postMessage(getMessgeQuit()); } catch (IOException E) { // TODO Auto-generated catch block E.printStackTrace(); } try { status = response.getInt(STATUS); } catch (JSONException ex) { Logger.getLogger(Registration.class.getName()).log(Level.SEVERE, null, ex); } if (JudgeStatus.OutputStatus(status) == false) { return; } } }); timer_roominfo = new java.util.Timer(true); DefaultTableModel model = (DefaultTableModel) jRoom.getModel(); Ask4Roominfo task = new Ask4Roominfo(); task.setOnRefreshListner(new Ask4Roominfo.OnRefreshListener() { @Override public void onRefresh(String test) { model.setRowCount(0); title = Room.Getroom().GetTtile(); number = Room.Getroom().GetMaxPlayers(); type = Room.Getroom().GetGameType(); //System.out.println(title + " " + number + " " + type); if (type == 1) { game_type = "BlackJack"; } wager = Room.Getroom().GetWager(); jTitle.setText("Welcome to " + title); jMax.setText(number + ""); jWager.setText(wager + ""); jType.setText(game_type); if (task.Get_members_num() > 0) { for (int i = 0; i < task.Get_members_num(); i++) { if (i == 0) { if (task.Get_Members()[i].get_members_id() != Player.GetPlayer().GetUserId()) { jStart.setVisible(false); } } model.addRow(new Object[] { task.Get_Members()[i].get_members_id(), task.Get_Members()[i].get_members_nickname() }); //System.out.println(task.get_room_name()[i]+task.get_creator_name()[i]+task.get_game_name()[i]+task.get_currentmax()[i]); } } //System.out.println("RoomStatus!!" + task.Get_roomstatus()); if (task.Get_roomstatus() == 2) { BlackJackUINew ui = new BlackJackUINew(); ui.setVisible(true); try { ui.DoSomethingAtBegin(); } catch (MessagingException ex) { Logger.getLogger(BlackJackUINew.class.getName()).log(Level.SEVERE, null, ex); } timer_roominfo.cancel(); CreateRoom.this.dispose(); } } }); timer_roominfo.schedule(task, START_TIME, PERIOD); }
From source file:UI.HomePage.java
public HomePage() throws JSONException { initComponents();/*from www .java2s .com*/ jRecord.setVisible(false); //jScrollPane1.getViewport().setOpaque(false); //jScrollPane1.setOpaque(false); //jScrollPane1.getColumnHeader().setOpaque(false); //getContentPane().add(jScrollPane1,BorderLayout.CENTER); jName.setText(Player.GetPlayer().GetNickName()); jMoney.setText("Money: " + Player.GetPlayer().GetBalance() + ""); jRank.setText("Rank: " + Player.GetPlayer().GetRank() + ""); timer_roomlist = new java.util.Timer(true); //Ask4RoomList task = new Ask4RoomList(); DefaultTableModel model = (DefaultTableModel) jRoomList.getModel(); jRoomList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (jRoomList.getSelectedRow() == -1) { return; } else { selected_row = jRoomList.getSelectedRow(); //System.out.println("Listener: " + selected_row); } } }); task.setOnRefreshListner(new Ask4RoomList.OnRefreshListener() { @Override public void onRefresh(String test) { model.setRowCount(0); jName.setText(Player.GetPlayer().GetNickName()); jMoney.setText("Money: " + Player.GetPlayer().GetBalance() + ""); jRank.setText("Rank: " + Player.GetPlayer().GetRank() + ""); if (task.get_room_number() > 0) { for (int i = 0; i < task.get_room_number(); i++) { model.addRow(new Object[] { task.get_room_title()[i], task.get_creator_name()[i], task.get_room_name()[i], task.get_currentmax()[i] }); //System.out.println(task.get_room_name()[i]+task.get_creator_name()[i]+task.get_game_name()[i]+task.get_currentmax()[i]); } } if (selected_row != -1) { jRoomList.setRowSelectionInterval(selected_row, selected_row); //System.out.println(jRoomList.getSelectedRow()); } roomids = task.get_roomids(); roomwagers = task.get_room_wager(); roomtypes = task.get_room_type(); roommax = task.get_room_max(); roomtitles = task.get_room_title(); } }); timer_roomlist.schedule(task, START_TIME, PERIOD); //System.out.println("Reach"); }
From source file:uk.chromis.pos.forms.JRootApp.java
private void poweredbyMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_poweredbyMouseClicked JFrame sampleFrame = new JFrame(); final Action exit = new AbstractAction("Exit") { @Override/*w w w .j a va 2s.c om*/ public final void actionPerformed(final ActionEvent e) { sampleFrame.setVisible(false); sampleFrame.dispose(); } }; String currentPath = null; if (OSValidator.isMac()) { try { currentPath = new File( JRootApp.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()) .toString(); } catch (URISyntaxException ex) { } } else { currentPath = System.getProperty("user.dir") + "\\chromispos.jar"; } String md5 = null; try { FileInputStream fis = new FileInputStream(new File(currentPath)); md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(fis); fis.close(); } catch (FileNotFoundException ex) { Logger.getLogger(JRootApp.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(JRootApp.class.getName()).log(Level.SEVERE, null, ex); } /* int mb = 1024*1024; //Getting the runtime reference from system Runtime runtime = Runtime.getRuntime(); System.out.println("##### Heap utilization statistics [MB] #####"); //Print used memory System.out.println("Used Memory:" + (runtime.totalMemory() - runtime.freeMemory()) / mb); //Print free memory System.out.println("Free Memory:" + runtime.freeMemory() / mb); //Print total available memory System.out.println("Total Memory:" + runtime.totalMemory() / mb); //Print Maximum available memory System.out.println("Max Memory:" + runtime.maxMemory() / mb); */ AboutDialog dialog = new AboutDialog(); JPanel dialogPanel = new JPanel(); MigLayout layout = new MigLayout("", "[fill]"); DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); model.addColumn("Details"); model.addColumn("Value"); model.addRow(new Object[] { "Database Version", readDataBaseVersion() }); model.addRow(new Object[] { "Java Version", System.getProperty("java.version") }); model.addRow(new Object[] { "Jar MD5", md5 }); model.addRow(new Object[] { "Operating System", System.getProperty("os.name") }); model.addRow(new Object[] { "Sync library", Sync.getVersion() }); JScrollPane scrollPane = new JScrollPane(table); JPanel mainPanel = new JPanel(layout); JLabel label = new JLabel(); JPanel btnPanel = new JPanel(); dialogPanel.add(dialog); mainPanel.add(dialogPanel, "wrap"); mainPanel.add(scrollPane, "wrap"); JButton btnExit = new JButton(exit); btnPanel.add(btnExit, "width 100!"); mainPanel.add(btnPanel, "right, wrap"); mainPanel.add(new JLabel(), "wrap"); sampleFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); sampleFrame.setPreferredSize(new Dimension(500, 300)); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); sampleFrame.setLocation(dim.width / 2 - 250, dim.height / 2 - 150); sampleFrame.setUndecorated(true); mainPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 4)); sampleFrame.add(mainPanel); sampleFrame.pack(); sampleFrame.setVisible(true); }
From source file:view.ManageOrganization.java
private void loadValuesInTable() { Dbcon dbcon = new Dbcon(); DefaultTableModel dt = (DefaultTableModel) jTable1.getModel(); ResultSet rs = dbcon.select("select * from tbl_organisation order by organisation_id asc"); try {//from ww w . java 2 s . co m while (rs.next()) { dt.addRow(new String[] { rs.getString(1), rs.getString(2), (rs.getString(10).trim().equals("1")) ? "active" : "blocked" }); } jTable1.setModel(dt); } catch (SQLException ex) { ex.printStackTrace(); } disableAll(); }
From source file:view.MultipleSignDialog.java
/** * Creates new form MultipleSignStatusDialog * * @param parent// w w w. j av a 2 s .co m * @param modal * @param alFiles * @param settings * @param dest */ public MultipleSignDialog(java.awt.Frame parent, boolean modal, final ArrayList<File> alFiles, final CCSignatureSettings settings, final String dest) { super(parent, modal); initComponents(); updateText(); jProgressBar1.setMinimum(0); jProgressBar1.setMaximum(alFiles.size()); jProgressBar1.setString(Bundle.getBundle().getString("pb.signed") + ": 0 " + Bundle.getBundle().getString("of") + alFiles.size()); final DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel(); final SignatureListener sl = new SignatureListener() { @Override public void onSignatureComplete(String filename, boolean valid, String message) { dtm.addRow(new Object[] { filename, (valid ? Bundle.getBundle().getString("label.signatureOk") : Bundle.getBundle().getString("label.signatureFailed")) + (message.isEmpty() ? "" : " - " + message) }); } }; Runnable r = new Runnable() { @Override public void run() { int numSigned = 0; btnClose.setEnabled(false); for (File file : alFiles) { String destinationPath = ""; boolean validPath = false; if (dest == null) { if (file.getName().endsWith(".pdf")) { destinationPath = file.getAbsolutePath() .substring(0, file.getAbsolutePath().length() - 4).concat("(aCCinado).pdf"); if (new File(destinationPath).exists()) { int num = 1; while (!validPath) { destinationPath = file.getAbsolutePath() .substring(0, file.getAbsolutePath().length() - 4) .concat("(aCCinado" + num + ").pdf"); if (new File(destinationPath).exists()) { destinationPath = file.getAbsolutePath() .substring(0, file.getAbsolutePath().length() - 4) .concat("(aCCinado).pdf"); num++; } else { break; } } } } } else { if (file.getName().endsWith(".pdf")) { destinationPath = dest + File.separator + file.getName() .substring(0, file.getName().length() - 4).concat("(aCCinado).pdf"); if (new File(destinationPath).exists()) { int num = 1; while (!validPath) { destinationPath = dest + File.separator + file.getName().substring(0, file.getName().length() - 4) .concat("(aCCinado" + num + ").pdf"); if (new File(destinationPath).exists()) { destinationPath = dest + File.separator + file.getName() .substring(0, file.getName().length() - 4).concat("(aCCinado).pdf"); num++; } else { break; } } } } } try { // Aplicar if (CCInstance.getInstance().signPdf(file.getAbsolutePath(), destinationPath, settings, sl)) { signedDocsList.add(new File(destinationPath)); numSigned++; jProgressBar1.setValue(numSigned); jProgressBar1.setString(Bundle.getBundle().getString("pb.signed") + ": " + numSigned + " " + Bundle.getBundle().getString("of") + " " + alFiles.size()); } else { //JOptionPane.showMessageDialog(this, "Erro desconhecido: ver log", "Assinatura falhou", JOptionPane.ERROR_MESSAGE); } } catch (CertificateException | IOException | DocumentException | KeyStoreException | NoSuchAlgorithmException | InvalidAlgorithmParameterException ex) { Logger.getLogger(MultipleSignDialog.class.getName()).log(Level.SEVERE, null, ex); } catch (SignatureFailedException ex) { if (ex.getLocalizedMessage().equals(Bundle.getBundle().getString("userCanceled"))) { String msg = Bundle.getBundle().getString("msg.cancelSigning"); Object[] options = { Bundle.getBundle().getString("yes"), Bundle.getBundle().getString("no") }; int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (opt == JOptionPane.YES_OPTION) { jProgressBar1.setValue(jProgressBar1.getMaximum()); jProgressBar1.setString(Bundle.getBundle().getString("pb.canceled")); break; } } } } btnClose.setEnabled(true); } }; Thread t = new Thread(r); t.start(); }