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:gtu._work.etc.GoogleContactUI.java

private void initGUI() {
    try {/* ww  w.ja  va 2  s. c o m*/
        BorderLayout thisLayout = new BorderLayout();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(thisLayout);
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("jPanel1", null, jPanel1, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
                    {

                        DefaultTableModel model = JTableUtil.createModel(false, googleColumns);
                        model.addRow(new Object[googleColumns.length]);
                        googleTable = new JTable();
                        jScrollPane1.setViewportView(googleTable);
                        googleTable.setModel(model);

                        googleTable.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                JTableUtil.newInstance(googleTable).defaultToolTipText(evt);
                                googleTableMouseClicked(evt);
                            }
                        });
                        JTableUtil.defaultSetting(googleTable);
                        JTableUtil.newInstance(googleTable).showColumnByHeaderValue(defaultShow_googleColumns);
                    }
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("jPanel2", null, jPanel2, null);
            }
        }
        pack();
        this.setSize(642, 405);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

void reloadPropertiesTable() {
    DefaultTableModel model = JTableUtil.createModel(false, "key", "value");
    for (Object key : props.keySet()) {
        model.addRow(new Object[] { key, props.get(key) });
    }/*from w w w  .  j  ava2 s  . c om*/
    propsTable.setModel(model);
}

From source file:com.yosanai.java.swing.config.ConfigPanel.java

public void loadConfig(Map<String, String> config) {
    DefaultTableModel model = (DefaultTableModel) tblConfig.getModel();
    while (0 < model.getRowCount()) {
        model.removeRow(0);//  ww  w . j  a  v a 2  s  . c  o m
    }
    for (String key : config.keySet()) {
        model.addRow(new Object[] { key, (null == config.get(key) ? "" : config.get(key)) });
    }
}

From source file:stockit.allStocks.java

public void setupTable() {
    try {/*ww w  . j a  v a2s. c o  m*/
        DBConnection dbcon = new DBConnection();
        dbcon.establishConnection();
        Statement stmt = dbcon.con.createStatement();
        ResultSet rs = stmt.executeQuery(
                "select stock.StockID, stock.Publicly_Traded, stock.StockName, stock_sector.Sector, stock_daily_performance.Volume, stock_daily_performance.Currency, stock_daily_performance.Opening_Price, stock_daily_performance.Closing_Price, stock_daily_performance.High, stock_daily_performance.Low, stock_daily_performance.Date\n"
                        + "from stock, stock_sector, stock_daily_performance\n"
                        + "WHERE stock.StockID = stock_sector.StockID AND stock_daily_performance.StockID = stock.StockID AND stock_daily_performance.Date IN\n"
                        + "( Select * from\n" + "(\n" + "SELECT max(Date) \n"
                        + "FROM stock_daily_performance, stock\n"
                        + "where stock_daily_performance.StockID=stock.StockID\n" + "group by stock.StockID\n"
                        + "ORDER BY Date \n" + "\n" + ") temp_table)");
        DefaultTableModel model = (DefaultTableModel) table.getModel();
        model.setRowCount(0);
        while (rs.next()) {
            model.addRow(new Object[] { rs.getString("StockID"), rs.getString("StockName"),
                    rs.getString("Publicly_Traded"), rs.getString("Sector"), rs.getString("Volume"),
                    rs.getString("Currency"), rs.getString("Opening_Price"), rs.getString("Closing_Price"),
                    rs.getString("High"), rs.getString("Low"), rs.getString("Date") });
        }
        dbcon.con.close();
    } catch (Exception ex) {
        Logger.getLogger(clientLogin.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.yosanai.java.swing.config.FileBackedConfigDialog.java

protected void load(String... keys) {
    DefaultTableModel model = (DefaultTableModel) tblConfig.getModel();
    while (0 < model.getRowCount()) {
        model.removeRow(0);//  www .  j ava2s.c  om
    }
    for (String key : keys) {
        model.addRow(new Object[] { key, configuration.getString(key, "") });
    }
}

From source file:functions.LoadCSVdata.java

public void LoadFeeDataToJTable(JTable t, String path) {
    try {/*  w  w w  .  ja  v a2 s  .  com*/
        file = new File(path);
        parser = CSVParser.parse(file, Charset.forName("UTF-8"), CSVFormat.DEFAULT);
        DefaultTableModel model = (DefaultTableModel) t.getModel();
        model.setRowCount(0);
        for (CSVRecord c : parser) {
            if (c.getRecordNumber() == 1)
                continue;
            model.addRow(
                    new Object[] { c.get(datatype.GlobalVariable.TYPE), c.get(datatype.GlobalVariable.AMOUNT),
                            c.get(datatype.GlobalVariable.PAID_BY), c.get(datatype.GlobalVariable.PAYER) });
        }
    } catch (Exception e) {
        System.out.println(e);
    }
}

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.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    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);//  w w w.java 2s  . co  m
    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:gtu._work.ui.RenameUI.java

private DefaultTableModel createNewModel() {
    DefaultTableModel model = JTableUtil.createModel(false, "??", "??", "");
    for (XFile f : fileList) {
        model.addRow(this.getXFile(f, null));
    }//w  ww .j  a v  a 2s . com
    renameTable.setModel(model);
    return model;
}

From source file:graph.plotter.PieMenu.java

/**
 * This method works for adding new data entry
 * @param evt //from ww w. j  ava  2s .c  o m
 */
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    // TODO add your handling code here:
    DefaultTableModel model = (DefaultTableModel) Table.getModel();
    model.addRow(new Object[] { jTextField1.getText(), jTextField2.getText() });
    cnt++;

}

From source file:org.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  w ww .ja v a  2 s .  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 = ChartUtils.createPanel(chart, false);

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

    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;
}