Example usage for javax.swing.table DefaultTableModel addRow

List of usage examples for javax.swing.table DefaultTableModel addRow

Introduction

In this page you can find the example usage for javax.swing.table DefaultTableModel addRow.

Prototype

public void addRow(Object[] rowData) 

Source Link

Document

Adds a row to the end of the model.

Usage

From source file:pkgnew.line.PluginDialog.java

private void listPlugins() {
    DefaultTableModel model = (DefaultTableModel) TablePlugins.getModel();
    PluginManager pluginManager = PluginManager.getInstance();
    List<Plugin> plugins = pluginManager.getPlugins();
    //clear out the table
    for (int i = 0; i < model.getRowCount(); i++) {
        model.removeRow(i);/*from www  .ja  v  a2s  .c o  m*/
    }
    //update the table
    for (Iterator<Plugin> pluginIterator = plugins.iterator(); pluginIterator.hasNext();) {
        Plugin plugin = (Plugin) pluginIterator.next();
        model.addRow(new Object[] { false, plugin.getName(), plugin.isEnabled() });
    }
}

From source file:proyecto4.Principal.java

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
    // TODO add your handling code here:
    DefaultTableModel modelo1 = (DefaultTableModel) jt_agre_ingre.getModel();
    for (int i = 0; i < modelo1.getRowCount(); i++) {
        modelo1.removeRow(i);/*  w  w w .ja  v  a 2  s  .c  o  m*/
    }
    for (int i = 0; i < lista_ingredientes.size(); i++) {
        modelo1.addRow(new Object[] { false, lista_ingredientes.get(i).toString() });
    }
    jd_agregar_producto.setModal(true);
    jd_agregar_producto.pack();
    jd_agregar_producto.setVisible(true);

}

From source file:proyecto4.Principal.java

private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
    // TODO add your handling code here:        
    DefaultTableModel modelo1 = (DefaultTableModel) jt_ordenes_camiones.getModel();
    for (int i = 0; i < modelo1.getRowCount(); i++) {
        modelo1.removeRow(i);//from w w w.j a v a 2s  .co m
    }
    for (int i = 0; i < lista_ordenes_cocineros.size(); i++) {
        modelo1.addRow(new Object[] { false, lista_ordenes_cocineros.get(i).getNombre().toString() });
    }
    jd_camiones.setModal(true);
    jd_camiones.pack();
    jd_camiones.setVisible(true);
}

From source file:put.semantic.fcanew.ui.MainWindow.java

private void continueStart() {
    final List<Attribute> forced = getAttributes(2);
    if (forced.isEmpty()) {
        forced.addAll(getAttributes(1));
    }/*ww  w  .  j av  a 2 s.  com*/
    logger.trace("START");
    for (Attribute a : getUsedAttributes()) {
        logger.trace("ATTR: {}", a);
    }
    context = new PartialContext(new SimpleSetOfAttributes(getUsedAttributes()), kb);
    context.addProgressListener(progressListener);
    context.updateContext();
    contextTable.setRowSorter(new TableRowSorter<>());
    contextTable.setModel(new ContextDataModel(context));
    contextTable.setDefaultRenderer(Object.class, new PODCellRenderer(kb.getReasoner()));
    Enumeration<TableColumn> e = contextTable.getColumnModel().getColumns();
    JComboBox comboBox = new JComboBox(new Object[] { "+", "-", " " });
    while (e.hasMoreElements()) {
        TableColumn col = e.nextElement();
        col.setHeaderRenderer(new VerticalTableHeaderCellRenderer());
        col.setCellEditor(new DefaultCellEditor(comboBox));
        if (col.getModelIndex() >= 1) {
            col.setPreferredWidth(20);
        }
    }
    List<? extends FeatureCalculator> calculators = availableCalculatorsModel.getChecked();
    for (FeatureCalculator calc : calculators) {
        if (calc instanceof EndpointCalculator) {
            ((EndpointCalculator) calc).setMappings(mappingsPanel1.getMappings());
        }
    }
    Classifier classifier = (Classifier) classifierToUse.getSelectedItem();
    classifier.setRejectedWeight((Double) rejectedWeight.getValue());
    mlExpert = new MLExpert(classifier, (Integer) credibilityTreshold.getValue(), calculators,
            getIgnoreTreshold(), context, getAutoAcceptTreshold());
    mlExpert.addEventListener(new MLExpertEventListener() {

        @Override
        public void implicationAccepted(ImplicationDescription i, boolean autoDecision) {
            logger.trace("ACCEPT");
            setButtonsEnabled(false);
            ((ConfusionMatrix) confusionMatrix.getModel()).add(i.getSuggestion(), Expert.Decision.ACCEPT);
            registerImplication(i.getImplication(), i.getClassificationOutcome(), Expert.Decision.ACCEPT);
        }

        @Override
        public void implicationRejected(ImplicationDescription i, boolean autoDecision) {
            logger.trace("REJECT");
            setButtonsEnabled(false);
            ((ConfusionMatrix) confusionMatrix.getModel()).add(i.getSuggestion(), Expert.Decision.REJECT);
            registerImplication(i.getImplication(), i.getClassificationOutcome(), Expert.Decision.REJECT);
        }

        private TableModel getFeaturesTableModel(Map<String, Double> features) {
            DefaultTableModel model = new DefaultTableModel(new String[] { "feature", "value" }, 0);
            for (Map.Entry<String, Double> f : features.entrySet()) {
                model.addRow(new Object[] { f.getKey(), f.getValue() });
            }
            return model;
        }

        @Override
        public void ask(ImplicationDescription i, String justification) {
            logger.trace("ASK: {}", i.getImplication());
            highlightButton(i.getSuggestion());
            ((ContextDataModel) contextTable.getModel()).setCurrentImplication(i.getImplication());
            justificationText.setText(justification);
            implicationText.setText(String.format("<html>%s</html>", i.getImplication().toString()));
            {
                Map<String, String> desc = i.getImplication().describe(kb);
                String s = "<html><table border=\"1\">";
                s += "<tr><th>Attribute</th><th>Label</th></tr>";
                for (Map.Entry<String, String> e : desc.entrySet()) {
                    s += String.format("<tr><td>%s</td><td><pre>%s</pre></td></tr>", e.getKey(), e.getValue());
                }
                s += "</table></html>";
                implicationText.setToolTipText(s);
            }
            setButtonsEnabled(true);
            featuresTable.setModel(getFeaturesTableModel(i.getFeatures()));
        }
    });
    learningExamplesTable.setModel(classifier.getExamplesTableModel());
    fca = new FCA();
    fca.setContext(context);
    fca.setExpert(mlExpert);
    new SwingWorker() {
        @Override
        protected Object doInBackground() throws Exception {
            fca.reset(forced);
            fca.run();
            return null;
        }

        @Override
        protected void done() {
            try {
                get();
                logger.trace("FINISHED");
                if (script != null) {
                    String name = JOptionPane.showInputDialog(MainWindow.this,
                            "Jeeli chcesz otrzyma punkty z TSiSS, podaj swoje imi, nazwisko i nr indeksu",
                            "TSiSS", JOptionPane.QUESTION_MESSAGE);
                    if (name != null) {
                        logger.trace("NAME: {}", name);
                    }
                    script.submitLog(new File("fca.log"));
                }
                implicationText.setText("Bye-bye");
            } catch (InterruptedException | ExecutionException ex) {
                implicationText.setText(ex.getLocalizedMessage());
                ex.printStackTrace();
            }
        }
    }.execute();
}

From source file:secureemailclient.applet.MessageListPanel.java

public void loadMessageList(List<Message> messageList) {
    DefaultTableModel model = (DefaultTableModel) jTableMessages.getModel();
    model.setRowCount(0);/*from   w w  w.  java  2 s  . co m*/
    for (Message message : messageList) {
        MessagePart payload = message.getPayload();

        String date = null, from = null, to = null, subject = null;

        List<MessagePartHeader> headers = payload.getHeaders();
        for (MessagePartHeader header : headers) {
            switch (header.getName()) {
            case "To":
                to = header.getValue();
                break;
            case "From":
                from = header.getValue();
                break;
            case "Subject":
                subject = header.getValue();
                break;
            case "Date":
                date = header.getValue();
                break;
            }
        }

        model.addRow(
                new Object[] { to, "<html>" + StringEscapeUtils.unescapeHtml4(message.getSnippet()) + "</html>",
                        date, message.getId() });
    }
}

From source file:sk.stuba.fiit.kvasnicka.topologyvisual.gui.simulation.SimulationTopComponent.java

private void loadRules(DefaultTableModel model, List<Data> dataList) {
    //delete all old simulation rules
    while (model.getRowCount() != 0) {
        model.removeRow(0);//from  ww w  .ja  v  a 2 s. c o  m
    }

    //add new simulation rules
    for (Data rule : dataList) {
        model.addRow(new Object[] { rule.getId(), rule.getName(), rule.getSourceVertex().getName(),
                rule.getDestinationVertex().getName(), rule.isPing() });
    }
}

From source file:sms.Form1Exams.java

public void findUsers() {
    String[] Subjects = findSubjectid();
    String[] Subjectsnames = findSubjectname();
    int subjectCount = Subjects.length;
    //JOptionPane.showMessageDialog(null, subjectCount);

    ArrayList<ExamDbDataHolder> users = ListUsers(this.sid.getText());
    DefaultTableModel model = new DefaultTableModel();

    //    String [] subjectsIdentifiers={"Maths","Eng","Kisw","Phy","Chem","Bio","Hist","Geo","Cre","Hre","Agri","Home Scie","Arts","Comp",
    //                                      "B/c","Wood","Metal","Music","French","German","Arabic","Business"};
    //    for(int y=0;y<Subjects.length;y++){
    //        //  w  w  w  . j a v a2s  . c  om
    //    }
    //    String []toCol;
    String col[] = { "Adm", "Uniq" };

    // String [] subjectsIdentifiers={}
    String[] both = (String[]) ArrayUtils.addAll(col, Subjectsnames);

    model.setColumnIdentifiers(both);
    Object[] row = new Object[subjectCount + 4];
    for (int i = 0; i < users.size(); i++) {

        row[0] = ((ExamDbDataHolder) users.get(i)).getSid();

        row[1] = ((ExamDbDataHolder) users.get(i)).getUnique();

        int c = 2;
        for (int s = 0; s < Subjects.length; s++) {

            if (Subjects[s].equals("s1")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getMathematics();
                c++;
            } else if (Subjects[s].equals("s2")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getEnglish();
                c++;
            } else if (Subjects[s].equals("s3")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getKiswahili();
                c++;
            } else if (Subjects[s].equals("s4")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getPhysics();
                c++;
            } else if (Subjects[s].equals("s5")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getChemistry();
                c++;
            } else if (Subjects[s].equals("s6")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getBiology();
                c++;
            } else if (Subjects[s].equals("s7")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getHistory();
                c++;
            } else if (Subjects[s].equals("s8")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getGeography();
                c++;
            } else if (Subjects[s].equals("s9")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getCre();
                c++;
            } else if (Subjects[s].equals("s10")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getIre();
                c++;
            } else if (Subjects[s].equals("s11")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getHre();
                c++;
            } else if (Subjects[s].equals("s12")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getAgriculture();
                c++;
            } else if (Subjects[s].equals("s13")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getHomescience();
                c++;
            } else if (Subjects[s].equals("s14")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getArtdesign();
                c++;
            } else if (Subjects[s].equals("s15")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getComputer();
                c++;

            } else if (Subjects[s].equals("s16")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getBuilding();
                c++;
            } else if (Subjects[s].equals("s17")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getWoodwork();
                c++;
            } else if (Subjects[s].equals("s18")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getMetalwork();
                c++;
            } else if (Subjects[s].equals("s19")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getMusic();
                c++;
            } else if (Subjects[s].equals("s20")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getFrench();
                c++;
            } else if (Subjects[s].equals("s21")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getGerman();
                c++;
            } else if (Subjects[s].equals("s22")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getArabic();
                c++;
            } else if (Subjects[s].equals("s23")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getBusiness();
                c++;
            }
        }

        //      row[2] = ((ExamDbDataHolder)users.get(i)).getMathematics();
        //      row[3] = ((ExamDbDataHolder)users.get(i)).getEng();
        //      row[4] = ((ExamDbDataHolder)users.get(i)).getKiswa();
        //      row[5] = ((ExamDbDataHolder)users.get(i)).getPhy();
        //      row[6] = ((ExamDbDataHolder)users.get(i)).getChem();
        //      row[7] = ((ExamDbDataHolder)users.get(i)).getBio();
        //      row[8] = ((ExamDbDataHolder)users.get(i)).getHist();
        //      row[9] = ((ExamDbDataHolder)users.get(i)).getGeo();
        //      row[10] = ((ExamDbDataHolder)users.get(i)).getCre();
        //      row[11] = ((ExamDbDataHolder)users.get(i)).getAgri();
        //      row[12] = ((ExamDbDataHolder)users.get(i)).getBs();

        model.addRow(row);
    }
    this.table.setModel(model);
}

From source file:sms.ViewResults.java

public void findUsers() {
    methods nn = new methods();
    Form1Exams n = new Form1Exams();
    String[] Subjects = n.findSubjectid();
    String[] Subjectsnames = n.findSubjectname();
    int subjectCount = Subjects.length;
    //JOptionPane.showMessageDialog(null, subjectCount);

    ArrayList<ExamDbDataHolder> users = ListUsers(this.sid.getText());
    DefaultTableModel model = new DefaultTableModel();

    //    String [] subjectsIdentifiers={"Maths","Eng","Kisw","Phy","Chem","Bio","Hist","Geo","Cre","Hre","Agri","Home Scie","Arts","Comp",
    //                                      "B/c","Wood","Metal","Music","French","German","Arabic","Business"};
    //    for(int y=0;y<Subjects.length;y++){
    //        //from www.ja  v  a 2s .  com
    //    }
    //    String []toCol;
    String col[] = { "Adm", "Uniq", "Total", "Ave", "AGG" };

    // String [] subjectsIdentifiers={}
    String[] both = (String[]) ArrayUtils.addAll(col, Subjectsnames);

    model.setColumnIdentifiers(both);
    Object[] row = new Object[subjectCount + 6];
    for (int i = 0; i < users.size(); i++) {

        row[0] = ((ExamDbDataHolder) users.get(i)).getSid();

        row[1] = ((ExamDbDataHolder) users.get(i)).getUnique();
        row[2] = ((ExamDbDataHolder) users.get(i)).getTotal();
        float g = Float.valueOf(((ExamDbDataHolder) users.get(i)).getTotal());
        //  tbl.addCell(String.format("%.1f", g));

        row[3] = String.format("%.1f", g / getYear());
        String gr = nn.checkGrade(yearid, String.format("%.1f", g / getYear()));
        row[4] = gr;
        int c = 5;
        for (int s = 0; s < Subjects.length; s++) {

            if (Subjects[s].equals("s1")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getMathematics();
                c++;
            } else if (Subjects[s].equals("s2")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getEnglish();
                c++;
            } else if (Subjects[s].equals("s3")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getKiswahili();
                c++;
            } else if (Subjects[s].equals("s4")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getPhysics();
                c++;
            } else if (Subjects[s].equals("s5")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getChemistry();
                c++;
            } else if (Subjects[s].equals("s6")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getBiology();
                c++;
            } else if (Subjects[s].equals("s7")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getHistory();
                c++;
            } else if (Subjects[s].equals("s8")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getGeography();
                c++;
            } else if (Subjects[s].equals("s9")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getCre();
                c++;
            } else if (Subjects[s].equals("s10")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getIre();
                c++;
            } else if (Subjects[s].equals("s11")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getHre();
                c++;
            } else if (Subjects[s].equals("s12")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getAgriculture();
                c++;
            } else if (Subjects[s].equals("s13")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getHomescience();
                c++;
            } else if (Subjects[s].equals("s14")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getArtdesign();
                c++;
            } else if (Subjects[s].equals("s15")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getComputer();
                c++;

            } else if (Subjects[s].equals("s16")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getBuilding();
                c++;
            } else if (Subjects[s].equals("s17")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getWoodwork();
                c++;
            } else if (Subjects[s].equals("s18")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getMetalwork();
                c++;
            } else if (Subjects[s].equals("s19")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getMusic();
                c++;
            } else if (Subjects[s].equals("s20")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getFrench();
                c++;
            } else if (Subjects[s].equals("s21")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getGerman();
                c++;
            } else if (Subjects[s].equals("s22")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getArabic();
                c++;
            } else if (Subjects[s].equals("s23")) {
                row[c] = ((ExamDbDataHolder) users.get(i)).getBusiness();
                c++;
            }
        }
        model.addRow(row);

    }
    this.table.setModel(model);
    counter(model.getRowCount());
}

From source file:sms.ViewResults.java

public void counter(int count) {

    DefaultTableModel model = new DefaultTableModel();
    String[] c = { "count" };
    model.setColumnIdentifiers(c);//w  ww. ja  v  a  2  s .  c  om
    Object[] row = new Object[1];

    for (int a = 1; a <= count; a++) {

        row[0] = a;

        model.addRow(row);
    }

    this.tblCounter.setModel(model);

}

From source file:StockForecast.Main.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    // TODO add your handling code here:
    Connect a = new Connect();
    DefaultTableModel tm = new DefaultTableModel();
    jTable1.setRowHeight(25);//from   w w  w.  ja v a  2 s  .  com
    tm.addColumn("User ID");
    tm.addColumn("Username");
    tm.addColumn("Password");
    tm.addColumn("User Type");
    tm.addColumn("Name");
    tm.addColumn("");
    tm.addColumn("");
    Action delete = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            jTable1 = (JTable) e.getSource();
            int modelRow = Integer.valueOf(e.getActionCommand());
            ((DefaultTableModel) jTable1.getModel()).removeRow(modelRow);
        }
    };

    String selectItem = jComboBox2.getSelectedItem().toString();
    String partQuery = "";
    String text = "";
    System.out.println(jComboBox4.getItemCount());
    if (jComboBox4.isEnabled()) {
        if (jComboBox4.getItemCount() > 0) {
            switch (selectItem) {
            case "All":
                partQuery = "";
                break;
            case "User ID":
                text = jComboBox4.getSelectedItem().toString();
                partQuery = " WHERE LOGINID='" + text + "'";
                break;
            case "User Name":
                text = jComboBox4.getSelectedItem().toString();
                partQuery = " WHERE NAME='" + text + "'";
                break;
            case "User Phone Number":
                text = jComboBox4.getSelectedItem().toString();
                partQuery = " WHERE NAME='" + text + "'";
                break;
            default:
                System.out.println("This Search Condition Not Yet Implemented");
            }
            try {
                ResultSet rs = a.connectSelect("1",
                        "SELECT * FROM ROOT.LOGIN NATURAL JOIN PROFILE" + partQuery);
                if (text.equals("")) {
                    JOptionPane.showMessageDialog(this, "Please Input Search Text");
                } else if (!rs.next()) {
                    JOptionPane.showMessageDialog(this, "There Is No Data With " + selectItem + ": " + text
                            + "\n" + "Please Try Using Valid (" + selectItem + ")");
                } else {
                    do {
                        tm.addRow(new Object[] { rs.getString(1), rs.getString(2), rs.getString(3),
                                rs.getString(4), rs.getString(6), "Delete", "Update" });
                        jTable1.setModel(tm);

                        ButtonColumn buttonColumn = new ButtonColumn(jTable1, delete, 5);
                        ButtonColumn btnColumn = new ButtonColumn(jTable1, delete, 6);
                        buttonColumn.setMnemonic(KeyEvent.VK_D);
                        btnColumn.setMnemonic(KeyEvent.VK_U);
                    } while (rs.next());
                }

            } catch (Exception ex) {
                System.out.println("Error: " + ex);
            }
        } else {
            JOptionPane.showMessageDialog(this, "There Is no Data Display in Table");
        }

    } else {
        try {
            ResultSet rs = a.connectSelect("1", "SELECT * FROM ROOT.LOGIN NATURAL JOIN PROFILE");
            if (!rs.next()) {
                JOptionPane.showMessageDialog(this, "There Is no Data Display in Table");
            } else {
                do {
                    tm.addRow(new Object[] { rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4),
                            rs.getString(6), "Delete", "Update" });
                    jTable1.setModel(tm);

                    ButtonColumn buttonColumn = new ButtonColumn(jTable1, delete, 5);
                    ButtonColumn btnColumn = new ButtonColumn(jTable1, delete, 6);
                    buttonColumn.setMnemonic(KeyEvent.VK_D);
                    btnColumn.setMnemonic(KeyEvent.VK_U);
                } while (rs.next());
            }

        } catch (Exception ex) {
            Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}