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:org.eobjects.datacleaner.widgets.result.UniqueKeyCheckAnalyzerResultSwingRenderer.java

@Override
public JComponent render(UniqueKeyCheckAnalyzerResult result) {
    final int nullCount = result.getNullCount();
    final int nonUniqueCount = result.getNonUniqueCount();

    final DefaultKeyedValues keyedValues = new DefaultKeyedValues();
    keyedValues.addValue("Unique keys", result.getUniqueCount());

    final List<Title> subTitles = new ArrayList<Title>();
    subTitles.add(new ShortTextTitle("Row count: " + result.getRowCount()));
    subTitles.add(new ShortTextTitle("Unique key count: " + result.getUniqueCount()));

    if (nonUniqueCount > 0) {
        keyedValues.addValue("Non-unique keys", nonUniqueCount);
        subTitles.add(new ShortTextTitle("Non-unique key count: " + nonUniqueCount));
    }/*from  ww  w.  ja v  a 2s. c  o m*/

    final String title;
    if (nullCount == 0) {
        title = "Unique and non-unique keys";
    } else {
        keyedValues.addValue(LabelUtils.NULL_LABEL, nullCount);
        title = "Unique, non-unique and <null> keys";
        subTitles.add(new ShortTextTitle("<null> key count: " + result.getNullCount()));
    }

    final DefaultPieDataset dataset = new DefaultPieDataset(keyedValues);
    final JFreeChart chart = ChartFactory.createRingChart(title, dataset, true, true, false);

    chart.setSubtitles(subTitles);

    ChartUtils.applyStyles(chart);
    ChartPanel chartPanel = new ChartPanel(chart);

    final DCPanel leftPanel = new DCPanel();
    leftPanel.setLayout(new VerticalLayout());
    leftPanel.add(WidgetUtils.decorateWithShadow(chartPanel, true, 4));

    final Map<String, Integer> samples = result.getNonUniqueSamples();
    if (samples == null || samples.isEmpty()) {
        return leftPanel;
    }

    final DefaultTableModel samplesTableModel = new DefaultTableModel(new String[] { "Key", "Count" }, 0);
    for (final Entry<String, Integer> entry : samples.entrySet()) {
        final String key = entry.getKey();
        final Integer count = entry.getValue();
        samplesTableModel.addRow(new Object[] { key, count });
    }
    final DCTable samplesTable = new DCTable(samplesTableModel);

    final DCPanel rightPanel = new DCPanel();
    rightPanel.setLayout(new BorderLayout());
    rightPanel.add(DCLabel.dark("Sample non-unique keys:"));
    rightPanel.add(samplesTable.toPanel(), BorderLayout.CENTER);

    final JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    split.setOpaque(false);
    split.add(leftPanel);
    split.add(rightPanel);
    split.setDividerLocation(550);

    return split;
}

From source file:com.cch.aj.entryrecorder.frame.SearchJFrame.java

private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed
    BusyJFrame bf = new BusyJFrame();
    bf.setVisible(true);//from www  .  j a v a 2  s.co m
    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {

        @Override
        protected Void doInBackground() throws Exception {
            List<Entry> list = entrySearchService.Search(txtShift.getText(), txtProduct.getText(),
                    txtBatch.getText());
            DefaultTableModel model = (DefaultTableModel) tblSearch.getModel();
            model.setRowCount(0);
            for (Entry entry : list) {
                model.addRow(new Object[] { entry.getId(), entry.getShift(), entry.getProductId().getCode(),
                        (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(entry.getCreateDate()) });
            }
            return null;
        }

        @Override
        protected void done() {
            bf.setVisible(false);
        }
    };
    worker.execute();

}

From source file:graph.plotter.BarMenu.java

/**
 * This method works for adding new data entry
 * @param evt /*ww w. ja  va2s .  c o m*/
 */
private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
    DefaultTableModel model = (DefaultTableModel) Table.getModel();
    model.addRow(new Object[] { jTextField1.getText(), jTextField2.getText() });
    count++;

}

From source file:charitypledge.Pledge.java

private void loadPledgeTable(String name, String type, String contribution) {
    // Set Object[] variable and add row to jTable
    Object[] row = { name, type, contribution };
    DefaultTableModel model = (DefaultTableModel) PledgeViewTable.getModel();
    model.addRow(row);
}

From source file:gtu._work.ui.JSFMakerUI_attrDialog.java

private void initGUI() {
    try {//from w  w  w . j  a  va 2 s.  com
        final SwingActionUtil actionUtil = SwingActionUtil.newInstance(this);
        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("attribute", null, jPanel1, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(379, 233));
                    {
                        DefaultTableModel model = JTableUtil.createModel(true, "enable", "attribute", "value");
                        attrTable = new JTable();

                        //XXX defnine attribute
                        model.addRow(transfromAttribute(new Attribute("size", null, "",
                                new String[] { "", "3", "5", "10", "15", "20" })));
                        model.addRow(transfromAttribute(
                                new Attribute("readonly", null, "", new String[] { "", "false", "true" })));
                        model.addRow(transfromAttribute(
                                new Attribute("styleClass", null, "", new String[] { "", "readonly-input" })));
                        //XXX defnine attribute

                        jScrollPane1.setViewportView(attrTable);
                        attrTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
                        attrTable.setAutoscrolls(true);
                        attrTable.setAutoCreateRowSorter(false);
                        attrTable.setUpdateSelectionOnSort(false);
                        attrTable.setAutoCreateColumnsFromModel(true);
                        attrTable.setColumnSelectionAllowed(true);
                        attrTable.setModel(model);
                        attrTable.getTableHeader().setAutoscrolls(true);
                        attrTable.getTableHeader().setDebugGraphicsOptions(DebugGraphics.BUFFERED_OPTION);
                        attrTable.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                actionUtil.invokeAction(evt);
                            }
                        });
                        attrTable.addKeyListener(JTableUtil.newInstance(attrTable).defaultKeyAdapter());
                    }
                }
                {
                    confirmOk = new JButton();
                    jPanel1.add(confirmOk, BorderLayout.SOUTH);
                    confirmOk.setText("OK");
                    confirmOk.setPreferredSize(new java.awt.Dimension(379, 32));
                    confirmOk.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            actionUtil.invokeAction(evt);
                        }
                    });
                }
            }

            actionUtil.addAction(confirmOk, ActionEvent.class, new Action() {
                public void action(EventObject evt) throws Exception {
                    dispose();
                    setVisible(false);
                }
            });

            actionUtil.addAction(attrTable, MouseEvent.class, new Action() {
                public void action(EventObject evt) throws Exception {
                    if (!JMouseEventUtil.buttonLeftClick(2, evt)) {
                        return;
                    }

                    int colPos = JTableUtil.newInstance(attrTable).getSelectedColumn();
                    int rowPos = JTableUtil.newInstance(attrTable).getSelectedRow();

                    Function func = Function.valueOf(colPos);
                    if (func == null) {
                        System.err.println("ERROR!!!!!");
                        return;
                    }

                    Attribute realAttr = (Attribute) JTableUtil.newInstance(attrTable).getModel()
                            .getValueAt(rowPos, Function.VALUE.col);

                    switch (func) {
                    case ENABLE:
                        boolean bool = (Boolean) JTableUtil.newInstance(attrTable).getModel().getValueAt(rowPos,
                                Function.ENABLE.col);
                        JTableUtil.newInstance(attrTable).getModel().setValueAt(!bool, rowPos,
                                Function.ENABLE.col);
                        break;
                    case ATTRIBUTE:
                        break;
                    case VALUE:
                        String value = (String) JOptionPaneUtil.newInstance().showInputDialog_drowdown("choice",
                                "", realAttr.dropdown, realAttr.defaultVal);
                        realAttr.value = value;
                        JTableUtil.newInstance(attrTable).getModel().setValueAt(StringUtils.isNotEmpty(value),
                                rowPos, Function.ENABLE.col);
                        break;
                    }
                }
            });

        }
        setSize(400, 300);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:net.java.sip.communicator.plugin.propertieseditor.SearchField.java

/**
 * Runs in {@link #filterThread} to apply {@link #filter} to the displayed
 * <tt>ConfigurationService</tt> properties.
 *//*from  w ww.j  ava 2 s.c  o  m*/
private void runInFilterThread() {
    String prevFilter = null;
    long prevFilterTime = 0;

    do {
        final String filter;

        synchronized (filterSyncRoot) {
            filter = this.filter;

            /*
             * If the currentThread is idle for too long (which also means
             * that the filter has not been changed), kill it because we do
             * not want to keep it alive forever.
             */
            if ((prevFilterTime != 0) && StringUtils.equalsIgnoreCase(filter, prevFilter)) {
                long timeout = FILTER_THREAD_TIMEOUT - (System.currentTimeMillis() - prevFilterTime);

                if (timeout > 0) {
                    // The currentThread has been idle but not long enough.
                    try {
                        filterSyncRoot.wait(timeout);
                        continue;
                    } catch (InterruptedException ie) {
                        // The currentThread will die bellow at the break.
                    }
                }
                // Commit suicide.
                if (Thread.currentThread().equals(filterThread))
                    filterThread = null;
                break;
            }
        }

        List<String> properties = confService.getAllPropertyNames();
        final List<Object[]> rows = new ArrayList<Object[]>(properties.size());

        for (String property : properties) {
            String value = (String) confService.getProperty(property);
            if ((filter == null) || StringUtils.containsIgnoreCase(property, filter)
                    || StringUtils.containsIgnoreCase(value, filter)) {
                rows.add(new Object[] { property, confService.getProperty(property) });
            }
        }

        // If in the meantime someone has changed the filter, we don't want
        // to update the GUI but filter the results again.
        if (StringUtils.equalsIgnoreCase(filter, this.filter)) {
            LowPriorityEventQueue.invokeLater(new Runnable() {
                public void run() {
                    DefaultTableModel model = (DefaultTableModel) table.getModel();

                    model.setRowCount(0);
                    for (Object[] row : rows) {
                        model.addRow(row);
                        if (filter != SearchField.this.filter)
                            return;
                    }
                }
            });
        }

        prevFilter = filter;
        prevFilterTime = System.currentTimeMillis();
    } while (true);
}

From source file:charitypledge.Pledge.java

private void SubmitButtonActionPerformed(java.awt.event.ActionEvent evt) {

    String name, charity, contribution;
    name = NameTextField.getText();/*from  ww  w . jav a  2 s  . co  m*/
    contribution = AmountTextField.getText();
    if (name.equals("")) {
        JOptionPane.showMessageDialog(rootPane, "Please enter your name. ");
        return;
    }
    if (contribution.equals("")) {
        JOptionPane.showMessageDialog(rootPane, "Please enter an amount. ");
        return;
    }
    if (CharityComboBox.getSelectedIndex() == 0) {
        JOptionPane.showMessageDialog(rootPane, "Please select a charity. ");
        return;
    } else {
        charity = CharityComboBox.getSelectedItem().toString();
        Object[] row = { name, charity, contribution, false };
        DefaultTableModel model = (DefaultTableModel) PledgeViewTable.getModel();
        model.addRow(row);
        String[] JSONrow = { "name", name, "charity", charity, "contribution", contribution };
        JsonWrite(JSONrow);
        // WriteDB(name, charity, contribution);
    }
}

From source file:gtu._work.ui.RegexCatchReplacer.java

/**
 * @param fromPattern//from   w ww.jav a  2 s.  c  o  m
 *            ???pattern
 * @param toFormat
 *            ??pattern
 * @param replaceText
 *            ??
 */
void replacer(String fromPattern, String toFormat, String replaceText) {
    try {
        Pattern pattern = Pattern.compile(fromPattern);
        Matcher matcher = pattern.matcher(replaceText);
        Map<String, Integer> tmap = new LinkedHashMap<String, Integer>();
        String tempStr = null;
        for (; matcher.find();) {
            tempStr = toFormat.toString();
            for (int ii = 0; ii <= matcher.groupCount(); ii++) {
                System.out.println(ii + " -- " + matcher.group(ii));
                tempStr = tempStr.replaceAll("#" + ii + "#", Matcher.quoteReplacement(matcher.group(ii)));
                if (!tmap.containsKey(tempStr)) {
                    tmap.put(tempStr, 0);
                }
                tmap.put(tempStr, tmap.get(tempStr) + 1);
            }
        }
        DefaultTableModel model = JTableUtil.createModel(true, "match", "count");
        for (String str : tmap.keySet()) {
            model.addRow(new Object[] { str, tmap.get(str) });
        }
        setTitle("total : " + model.getRowCount());
        resultArea.setModel(model);
    } catch (Exception ex) {
        JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog(ex.getMessage(), getTitle());
        ex.printStackTrace();
    }
}

From source file:com.mirth.connect.client.ui.RegexAttachmentDialog.java

private void inboundNewButtonActionPerformed(ActionEvent evt) {
    DefaultTableModel model = ((DefaultTableModel) inboundReplacementTable.getModel());
    int row = model.getRowCount();

    model.addRow(new Object[] { "", "" });

    inboundReplacementTable.setRowSelectionInterval(row, row);

    parent.setSaveEnabled(true);/*from  w ww.  j a v  a2 s.co  m*/
}

From source file:com.mirth.connect.client.ui.RegexAttachmentDialog.java

private void outboundNewButtonActionPerformed(ActionEvent evt) {
    DefaultTableModel model = ((DefaultTableModel) outboundReplacementTable.getModel());
    int row = model.getRowCount();

    model.addRow(new Object[] { "", "" });

    outboundReplacementTable.setRowSelectionInterval(row, row);

    parent.setSaveEnabled(true);//from   ww w.j  av a 2  s .c  om
}