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:UserInterface.PublisherRole.ViewUserHabitsJPanel.java

public void populateUserHabitsTable(UserPotential userPotential) {
    int rowCount = userHabitsJTable.getRowCount();
    DefaultTableModel model = (DefaultTableModel) userHabitsJTable.getModel();
    model.setRowCount(0);//from   w  ww  . java  2 s.  co m

    for (Tag tag : userPotential.getTagList().getTagList()) {

        Object row[] = new Object[2];
        row[0] = tag.getTagName();
        row[1] = tag.getNumberOfVisits();
        model.addRow(row);
    }

}

From source file:dnd.BasicDnD.java

public BasicDnD() {
    super(new BorderLayout());
    JPanel leftPanel = createVerticalBoxPanel();
    JPanel rightPanel = createVerticalBoxPanel();

    //Create a table model.
    DefaultTableModel tm = new DefaultTableModel();
    tm.addColumn("Column 0");
    tm.addColumn("Column 1");
    tm.addColumn("Column 2");
    tm.addColumn("Column 3");
    tm.addRow(new String[] { "Table 00", "Table 01", "Table 02", "Table 03" });
    tm.addRow(new String[] { "Table 10", "Table 11", "Table 12", "Table 13" });
    tm.addRow(new String[] { "Table 20", "Table 21", "Table 22", "Table 23" });
    tm.addRow(new String[] { "Table 30", "Table 31", "Table 32", "Table 33" });

    //LEFT COLUMN
    //Use the table model to create a table.
    table = new JTable(tm);
    leftPanel.add(createPanelForComponent(table, "JTable"));

    //Create a color chooser.
    colorChooser = new JColorChooser();
    leftPanel.add(createPanelForComponent(colorChooser, "JColorChooser"));

    //RIGHT COLUMN
    //Create a textfield.
    textField = new JTextField(30);
    textField.setText("Favorite foods:\nPizza, Moussaka, Pot roast");
    rightPanel.add(createPanelForComponent(textField, "JTextField"));

    //Create a scrolled text area.
    textArea = new JTextArea(5, 30);
    textArea.setText("Favorite shows:\nBuffy, Alias, Angel");
    JScrollPane scrollPane = new JScrollPane(textArea);
    rightPanel.add(createPanelForComponent(scrollPane, "JTextArea"));

    //Create a list model and a list.
    DefaultListModel listModel = new DefaultListModel();
    listModel.addElement("Martha Washington");
    listModel.addElement("Abigail Adams");
    listModel.addElement("Martha Randolph");
    listModel.addElement("Dolley Madison");
    listModel.addElement("Elizabeth Monroe");
    listModel.addElement("Louisa Adams");
    listModel.addElement("Emily Donelson");
    list = new JList(listModel);
    list.setVisibleRowCount(-1);/*from w w  w. j  a  v a2 s .  com*/
    list.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    list.setTransferHandler(new TransferHandler() {

        public boolean canImport(TransferHandler.TransferSupport info) {
            // we only import Strings
            if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                return false;
            }

            JList.DropLocation dl = (JList.DropLocation) info.getDropLocation();
            if (dl.getIndex() == -1) {
                return false;
            }
            return true;
        }

        public boolean importData(TransferHandler.TransferSupport info) {
            if (!info.isDrop()) {
                return false;
            }

            // Check for String flavor
            if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                displayDropLocation("List doesn't accept a drop of this type.");
                return false;
            }

            JList.DropLocation dl = (JList.DropLocation) info.getDropLocation();
            DefaultListModel listModel = (DefaultListModel) list.getModel();
            int index = dl.getIndex();
            boolean insert = dl.isInsert();
            // Get the current string under the drop.
            String value = (String) listModel.getElementAt(index);

            // Get the string that is being dropped.
            Transferable t = info.getTransferable();
            String data;
            try {
                data = (String) t.getTransferData(DataFlavor.stringFlavor);
            } catch (Exception e) {
                return false;
            }

            // Display a dialog with the drop information.
            String dropValue = "\"" + data + "\" dropped ";
            if (dl.isInsert()) {
                if (dl.getIndex() == 0) {
                    displayDropLocation(dropValue + "at beginning of list");
                } else if (dl.getIndex() >= list.getModel().getSize()) {
                    displayDropLocation(dropValue + "at end of list");
                } else {
                    String value1 = (String) list.getModel().getElementAt(dl.getIndex() - 1);
                    String value2 = (String) list.getModel().getElementAt(dl.getIndex());
                    displayDropLocation(dropValue + "between \"" + value1 + "\" and \"" + value2 + "\"");
                }
            } else {
                displayDropLocation(dropValue + "on top of " + "\"" + value + "\"");
            }

            /**  This is commented out for the basicdemo.html tutorial page.
                       **  If you add this code snippet back and delete the
                       **  "return false;" line, the list will accept drops
                       **  of type string.
                      // Perform the actual import.  
                      if (insert) {
            listModel.add(index, data);
                      } else {
            listModel.set(index, data);
                      }
                      return true;
            */
            return false;
        }

        public int getSourceActions(JComponent c) {
            return COPY;
        }

        protected Transferable createTransferable(JComponent c) {
            JList list = (JList) c;
            Object[] values = list.getSelectedValues();

            StringBuffer buff = new StringBuffer();

            for (int i = 0; i < values.length; i++) {
                Object val = values[i];
                buff.append(val == null ? "" : val.toString());
                if (i != values.length - 1) {
                    buff.append("\n");
                }
            }
            return new StringSelection(buff.toString());
        }
    });
    list.setDropMode(DropMode.ON_OR_INSERT);

    JScrollPane listView = new JScrollPane(list);
    listView.setPreferredSize(new Dimension(300, 100));
    rightPanel.add(createPanelForComponent(listView, "JList"));

    //Create a tree.
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Mia Familia");
    DefaultMutableTreeNode sharon = new DefaultMutableTreeNode("Sharon");
    rootNode.add(sharon);
    DefaultMutableTreeNode maya = new DefaultMutableTreeNode("Maya");
    sharon.add(maya);
    DefaultMutableTreeNode anya = new DefaultMutableTreeNode("Anya");
    sharon.add(anya);
    sharon.add(new DefaultMutableTreeNode("Bongo"));
    maya.add(new DefaultMutableTreeNode("Muffin"));
    anya.add(new DefaultMutableTreeNode("Winky"));
    DefaultTreeModel model = new DefaultTreeModel(rootNode);
    tree = new JTree(model);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    JScrollPane treeView = new JScrollPane(tree);
    treeView.setPreferredSize(new Dimension(300, 100));
    rightPanel.add(createPanelForComponent(treeView, "JTree"));

    //Create the toggle button.
    toggleDnD = new JCheckBox("Turn on Drag and Drop");
    toggleDnD.setActionCommand("toggleDnD");
    toggleDnD.addActionListener(this);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel);
    splitPane.setOneTouchExpandable(true);

    add(splitPane, BorderLayout.CENTER);
    add(toggleDnD, BorderLayout.PAGE_END);
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
}

From source file:UserInterface.DoctorRole.ViewPatientReport.java

public void PopulateTable() {
    DefaultTableModel model = (DefaultTableModel) summaryTable.getModel();

    model.setRowCount(0);//from w w w  .j ava 2s .c om
    for (Test vs : testdir.getTestdir()) {
        Object row[] = new Object[4];
        row[0] = vs;
        row[1] = vs.getBloodPressure();
        row[2] = vs.getBloodPlatlets();
        row[3] = vs.getHemoglobinLevel();
        model.addRow(row);

    }
}

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

private void callEbaoMsgId(String msgId, boolean exactSearch) {
    if (StringUtils.isBlank(msgId) || StringUtils.length(msgId) < 3) {
        return;// w  ww  .j av  a 2 s  .  c o m
    }
    String dataLike = " like '%" + msgId + "%' ";
    if (exactSearch) {
        dataLike = " = '" + msgId + "' ";
    }
    String sql = "select * from t_string_resource where (str_id = '" + msgId + "' or str_data " + dataLike
            + ") and lang_id = 311 ";
    try {
        Connection conn = this.getDbDataSource().getConnection();
        List<Map<String, Object>> queryList = JdbcDBUtil.queryForList(sql, null, conn, false);
        DefaultTableModel model = (DefaultTableModel) ebaoTable.getModel();
        for (Map<String, Object> map : queryList) {
            model.addRow(new Object[] { map.get("STR_ID"), map.get("STR_DATA") });
        }
        try {
            conn.close();
        } catch (Exception ex) {
        }
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }
}

From source file:UserInterface.CDC.VARESReportingJPanel.java

private void populateTable() {
    DefaultTableModel model = (DefaultTableModel) summaryjTable.getModel();
    model.setRowCount(0);//ww w.  j a v a 2s . c  o m
    if (business.getStateList() != null) {
        for (StateNetwork state : business.getStateList()) {
            Object[] row = new Object[3];
            row[0] = state;
            row[1] = state.getTotalVaccinesAdministeredInState();
            row[2] = state.getTotalFailedVaccinesInState();

            model.addRow(row);
        }

    }

}

From source file:BasicDnD.java

public BasicDnD() {
    super(new BorderLayout());
    JPanel leftPanel = createVerticalBoxPanel();
    JPanel rightPanel = createVerticalBoxPanel();

    // Create a table model.
    DefaultTableModel tm = new DefaultTableModel();
    tm.addColumn("Column 0");
    tm.addColumn("Column 1");
    tm.addColumn("Column 2");
    tm.addColumn("Column 3");
    tm.addRow(new String[] { "Table 00", "Table 01", "Table 02", "Table 03" });
    tm.addRow(new String[] { "Table 10", "Table 11", "Table 12", "Table 13" });
    tm.addRow(new String[] { "Table 20", "Table 21", "Table 22", "Table 23" });
    tm.addRow(new String[] { "Table 30", "Table 31", "Table 32", "Table 33" });

    // LEFT COLUMN
    // Use the table model to create a table.
    table = new JTable(tm);
    leftPanel.add(createPanelForComponent(table, "JTable"));

    // Create a color chooser.
    colorChooser = new JColorChooser();
    leftPanel.add(createPanelForComponent(colorChooser, "JColorChooser"));

    // RIGHT COLUMN
    // Create a textfield.
    textField = new JTextField(30);
    textField.setText("Favorite foods:\nPizza, Moussaka, Pot roast");
    rightPanel.add(createPanelForComponent(textField, "JTextField"));

    // Create a scrolled text area.
    textArea = new JTextArea(5, 30);
    textArea.setText("Favorite shows:\nBuffy, Alias, Angel");
    JScrollPane scrollPane = new JScrollPane(textArea);
    rightPanel.add(createPanelForComponent(scrollPane, "JTextArea"));

    // Create a list model and a list.
    DefaultListModel listModel = new DefaultListModel();
    listModel.addElement("Martha Washington");
    listModel.addElement("Abigail Adams");
    listModel.addElement("Martha Randolph");
    listModel.addElement("Dolley Madison");
    listModel.addElement("Elizabeth Monroe");
    listModel.addElement("Louisa Adams");
    listModel.addElement("Emily Donelson");
    list = new JList(listModel);
    list.setVisibleRowCount(-1);//from   w w  w  .j  av a2  s  .co  m
    list.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    list.setTransferHandler(new TransferHandler() {

        public boolean canImport(TransferHandler.TransferSupport info) {
            // we only import Strings
            if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                return false;
            }

            JList.DropLocation dl = (JList.DropLocation) info.getDropLocation();
            if (dl.getIndex() == -1) {
                return false;
            }
            return true;
        }

        public boolean importData(TransferHandler.TransferSupport info) {
            if (!info.isDrop()) {
                return false;
            }

            // Check for String flavor
            if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                displayDropLocation("List doesn't accept a drop of this type.");
                return false;
            }

            JList.DropLocation dl = (JList.DropLocation) info.getDropLocation();
            DefaultListModel listModel = (DefaultListModel) list.getModel();
            int index = dl.getIndex();
            boolean insert = dl.isInsert();
            // Get the current string under the drop.
            String value = (String) listModel.getElementAt(index);

            // Get the string that is being dropped.
            Transferable t = info.getTransferable();
            String data;
            try {
                data = (String) t.getTransferData(DataFlavor.stringFlavor);
            } catch (Exception e) {
                return false;
            }

            // Display a dialog with the drop information.
            String dropValue = "\"" + data + "\" dropped ";
            if (dl.isInsert()) {
                if (dl.getIndex() == 0) {
                    displayDropLocation(dropValue + "at beginning of list");
                } else if (dl.getIndex() >= list.getModel().getSize()) {
                    displayDropLocation(dropValue + "at end of list");
                } else {
                    String value1 = (String) list.getModel().getElementAt(dl.getIndex() - 1);
                    String value2 = (String) list.getModel().getElementAt(dl.getIndex());
                    displayDropLocation(dropValue + "between \"" + value1 + "\" and \"" + value2 + "\"");
                }
            } else {
                displayDropLocation(dropValue + "on top of " + "\"" + value + "\"");
            }

            /**
             * This is commented out for the basicdemo.html tutorial page. * If you
             * add this code snippet back and delete the * "return false;" line, the
             * list will accept drops * of type string. // Perform the actual
             * import. if (insert) { listModel.add(index, data); } else {
             * listModel.set(index, data); } return true;
             */
            return false;
        }

        public int getSourceActions(JComponent c) {
            return COPY;
        }

        protected Transferable createTransferable(JComponent c) {
            JList list = (JList) c;
            Object[] values = list.getSelectedValues();

            StringBuffer buff = new StringBuffer();

            for (int i = 0; i < values.length; i++) {
                Object val = values[i];
                buff.append(val == null ? "" : val.toString());
                if (i != values.length - 1) {
                    buff.append("\n");
                }
            }
            return new StringSelection(buff.toString());
        }
    });
    list.setDropMode(DropMode.ON_OR_INSERT);

    JScrollPane listView = new JScrollPane(list);
    listView.setPreferredSize(new Dimension(300, 100));
    rightPanel.add(createPanelForComponent(listView, "JList"));

    // Create a tree.
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Mia Familia");
    DefaultMutableTreeNode sharon = new DefaultMutableTreeNode("Sharon");
    rootNode.add(sharon);
    DefaultMutableTreeNode maya = new DefaultMutableTreeNode("Maya");
    sharon.add(maya);
    DefaultMutableTreeNode anya = new DefaultMutableTreeNode("Anya");
    sharon.add(anya);
    sharon.add(new DefaultMutableTreeNode("Bongo"));
    maya.add(new DefaultMutableTreeNode("Muffin"));
    anya.add(new DefaultMutableTreeNode("Winky"));
    DefaultTreeModel model = new DefaultTreeModel(rootNode);
    tree = new JTree(model);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    JScrollPane treeView = new JScrollPane(tree);
    treeView.setPreferredSize(new Dimension(300, 100));
    rightPanel.add(createPanelForComponent(treeView, "JTree"));

    // Create the toggle button.
    toggleDnD = new JCheckBox("Turn on Drag and Drop");
    toggleDnD.setActionCommand("toggleDnD");
    toggleDnD.addActionListener(this);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel);
    splitPane.setOneTouchExpandable(true);

    add(splitPane, BorderLayout.CENTER);
    add(toggleDnD, BorderLayout.PAGE_END);
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
}

From source file:com.willwinder.universalgcodesender.uielements.panels.ControllerProcessorSettingsPanel.java

/**
 *  ------------------------------/*from  w ww  . j a v a 2s .c  o  m*/
 *  |  [      controller      ]  |
 *  | [ ] front processor 1      |
 *  | [ ] front processor 2      |
 *  | [ ] end processor 1        |
 *  | [ ] end processor 2        |
 * 
 *  | [+]                   [-]  |
 *  |  ________________________  |
 *  | | Enabled | Pattern      | |
 *  | |  [y]    | T\d+         | |
 *  | |  [n]    | M30          | |
 *  |  ------------------------  |
 *  |____________________________|
 */
@Override
protected void updateComponentsInternal(Settings s) {
    this.removeAll();
    initCustomRemoverTable(customRemoverTable);
    setLayout(new MigLayout("wrap 1, inset 5, fillx", "fill"));

    super.addIgnoreChanges(controllerConfigs);

    ConfigTuple ct = configFiles.get(controllerConfigs.getSelectedItem());
    ProcessorConfigGroups pcg = ct.loader.getProcessorConfigs();
    System.out.println(ct.file);

    for (ProcessorConfig pc : pcg.Front) {
        add(new ProcessorConfigCheckbox(pc, CommandProcessorLoader.getHelpForConfig(pc)));
    }

    for (ProcessorConfig pc : pcg.End) {
        add(new ProcessorConfigCheckbox(pc, CommandProcessorLoader.getHelpForConfig(pc)));
    }

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new MigLayout("wrap 3", "grow, fill", ""));
    add(buttonPanel, add);
    add(buttonPanel, new JLabel());
    add(buttonPanel, remove);
    addIgnoreChanges(buttonPanel);

    DefaultTableModel model = (DefaultTableModel) this.customRemoverTable.getModel();
    for (ProcessorConfig pc : pcg.Custom) {
        Boolean enabled = pc.enabled;
        String pattern = "";
        if (pc.args != null && !pc.args.get("pattern").isJsonNull()) {
            pattern = pc.args.get("pattern").getAsString();
        }
        model.addRow(new Object[] { enabled, pattern });
    }
    addIgnoreChanges(new JScrollPane(customRemoverTable), "height 100");

    SwingUtilities.updateComponentTreeUI(this);
}

From source file:UserInterface.SearchPatientJPanel.java

public void populateTable() {
    DefaultTableModel dtm = (DefaultTableModel) patientTable.getModel();
    dtm.setRowCount(0);//from w ww .ja  v a  2 s  . com
    for (Person P : personDirectory.getpersonDirectory()) {
        if (P.getPatient().getPatientId() != null) {
            Object row[] = new Object[4];
            row[0] = P.getPatient();
            row[1] = P.getPatient().getPatientId();
            row[2] = P.getPatient().getDoctorName();
            row[3] = P.getPatient().getPharmacy();
            dtm.addRow(row);
        }
    }
}

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

private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
    String tag = StringUtils.trim((String) tagComboBox.getSelectedItem());

    if (tag == null || tag.isEmpty()) {
        parent.alertError(parent, "Please enter a tag");
    } else {/*  w  w  w .  j a  v a 2s  . c om*/
        DefaultTableModel model = (DefaultTableModel) tagTable.getModel();
        int rowCount = model.getRowCount();

        for (int i = 0; i < rowCount; i++) {
            if (model.getValueAt(i, 0).equals(tag)) {
                parent.alertError(parent, "\"" + tag + "\" is already assigned to this channel");
                return;
            }
        }

        model.addRow(new Object[] { tag });
        tagTable.setRowSelectionInterval(rowCount, rowCount);
        dispose();
    }
}

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

public RegexAttachmentDialog(AttachmentHandlerProperties properties) {
    super(PlatformUI.MIRTH_FRAME, true);
    this.parent = PlatformUI.MIRTH_FRAME;

    setTitle("Set Attachment Properties");
    getContentPane().setBackground(UIConstants.BACKGROUND_COLOR);
    setLayout(new MigLayout("novisualpadding, hidemode 3, insets 12", "[fill, grow]"));
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    setPreferredSize(new Dimension(650, 550));

    initComponents();// www.  j  a v  a2  s.  com
    initLayout();
    initInboundReplacementTable();
    initOutboundReplacementTable();

    attachmentHandlerProperties = properties;

    List<RegexInfo> regexInfoList = new ArrayList<RegexInfo>();

    if (attachmentHandlerProperties.getProperties().containsKey("regex.pattern")) {
        String regex = StringUtils
                .defaultString(attachmentHandlerProperties.getProperties().get("regex.pattern"));
        String mimeType = StringUtils
                .defaultString(attachmentHandlerProperties.getProperties().get("regex.mimetype"));
        regexInfoList.add(new RegexInfo(regex, mimeType));
    }

    int count = 0;
    while (attachmentHandlerProperties.getProperties().containsKey("regex.pattern" + count)) {
        String regex = StringUtils
                .defaultString(attachmentHandlerProperties.getProperties().get("regex.pattern" + count));
        String mimeType = StringUtils
                .defaultString(attachmentHandlerProperties.getProperties().get("regex.mimetype" + count));
        regexInfoList.add(new RegexInfo(regex, mimeType));
        count++;
    }

    Object[][] regexTableData = new Object[regexInfoList.size()][2];
    int i = 0;
    for (RegexInfo regexInfo : regexInfoList) {
        regexTableData[i][0] = regexInfo.pattern;
        regexTableData[i][1] = regexInfo.mimeType;
        i++;
    }
    ((RefreshTableModel) regexTable.getModel()).refreshDataVector(regexTableData);

    count = 0;
    while (attachmentHandlerProperties.getProperties().containsKey("regex.replaceKey" + count)) {
        DefaultTableModel tableModel = (DefaultTableModel) inboundReplacementTable.getModel();
        tableModel.addRow(
                new Object[] { attachmentHandlerProperties.getProperties().get("regex.replaceKey" + count),
                        attachmentHandlerProperties.getProperties().get("regex.replaceValue" + count) });
        count++;
    }

    count = 0;
    while (attachmentHandlerProperties.getProperties().containsKey("outbound.regex.replaceKey" + count)) {
        DefaultTableModel tableModel = (DefaultTableModel) outboundReplacementTable.getModel();
        tableModel.addRow(new Object[] {
                attachmentHandlerProperties.getProperties().get("outbound.regex.replaceKey" + count),
                attachmentHandlerProperties.getProperties().get("outbound.regex.replaceValue" + count) });
        count++;
    }

    setLocationRelativeTo(parent);
    setVisible(true);
}