Example usage for javax.swing.table DefaultTableModel addColumn

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

Introduction

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

Prototype

public void addColumn(Object columnName) 

Source Link

Document

Adds a column to the model.

Usage

From source file:net.ytbolg.mcxa.VersionCheck.java

private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
    setTitle(Lang.getLang("Version_Title"));

    DefaultTableModel zsbm = (DefaultTableModel) jTable1.getModel();
    DefaultTableModel kzbm = (DefaultTableModel) jTable2.getModel();
    DefaultTableModel jbbm = (DefaultTableModel) jTable3.getModel();
    DefaultTableModel qbm = (DefaultTableModel) jTable4.getModel();

    jButton1.setText(Lang.getLang("Version_Button_Download"));

    jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jTable2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jTable3.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jTable4.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    jTable1.setColumnSelectionAllowed(false);
    jTable2.setColumnSelectionAllowed(false);
    jTable3.setColumnSelectionAllowed(false);
    jTable4.setColumnSelectionAllowed(false);

    jTable1.setRowSelectionAllowed(true);
    jTable2.setRowSelectionAllowed(true);
    jTable3.setRowSelectionAllowed(true);
    jTable4.setRowSelectionAllowed(true);

    zsbm.addColumn(Lang.getLang("Version_Table_McVersion"));
    zsbm.addColumn(Lang.getLang("Version_Table_RelTime"));
    zsbm.addColumn(Lang.getLang("Version_Table_Type"));

    kzbm.addColumn(Lang.getLang("Version_Table_McVersion"));
    kzbm.addColumn(Lang.getLang("Version_Table_RelTime"));
    kzbm.addColumn(Lang.getLang("Version_Table_Type"));

    jbbm.addColumn(Lang.getLang("Version_Table_McVersion"));
    jbbm.addColumn(Lang.getLang("Version_Table_RelTime"));
    jbbm.addColumn(Lang.getLang("Version_Table_Type"));

    qbm.addColumn(Lang.getLang("Version_Table_McVersion"));
    qbm.addColumn(Lang.getLang("Version_Table_RelTime"));
    qbm.addColumn(Lang.getLang("Version_Table_Type"));

    jTabbedPane1.setTitleAt(0, Lang.getLang("Version_TabledPanel_Zsb"));
    jTabbedPane1.setTitleAt(1, Lang.getLang("Version_TabledPanel_Kzb"));
    jTabbedPane1.setTitleAt(2, Lang.getLang("Version_TabledPanel_jbb"));
    jTabbedPane1.setTitleAt(3, Lang.getLang("Version_TabledPanel_qb"));
    try {//from   w  ww . ja v  a 2 s  . c  o  m
        JSONArray ja = (new JSONObject(downloadFile(
                DownLoadURL.getURL(DownLoadURL.VERSION_LIST, Integer.valueOf(Config.getConfig("DownSou")))))
                        .getJSONArray("versions"));
        for (int i = 0; i < ja.length(); i++) {
            JSONObject jo = ja.getJSONObject(i);
            if (jo.getString("type").equals("release")) {
                zsbm.addRow(new Object[] { jo.get("id"), jo.get("releaseTime"), jo.get("type") });
            }
            if (jo.getString("type").equals("snapshot")) {
                kzbm.addRow(new Object[] { jo.get("id"), jo.get("releaseTime"), jo.get("type") });
            }
            if (jo.getString("type").contains("old")) {
                jbbm.addRow(new Object[] { jo.get("id"), jo.get("releaseTime"), jo.get("type") });
            }
            qbm.addRow(new Object[] { jo.get("id"), jo.get("releaseTime"), jo.get("type") });
        }
    } catch (Exception e) {
    } // TODO add your handling code here:      // TODO add your handling code here:
}

From source file:org.freeplane.view.swing.features.time.mindmapmode.nodelist.NodeList.java

/**
 * Creates a table model for the new table and returns it.
 *//*w  w  w . j  a  v a2 s  .c om*/
private DefaultTableModel updateModel() {
    final DefaultTableModel model = new DefaultTableModel() {
        /**
         *
         */
        private static final long serialVersionUID = 1L;

        /*
         * (non-Javadoc)
         * @see javax.swing.table.AbstractTableModel#getColumnClass(int)
         */
        @Override
        public Class<?> getColumnClass(final int arg0) {
            switch (arg0) {
            case DATE_COLUMN:
            case NODE_CREATED_COLUMN:
            case NODE_MODIFIED_COLUMN:
                return Date.class;
            case NODE_TEXT_COLUMN:
            case NODE_NOTES_COLUMN:
            case NODE_DETAILS_COLUMN:
                return TextHolder.class;
            case NODE_ICON_COLUMN:
                return IconsHolder.class;
            default:
                return Object.class;
            }
        }
    };
    model.addColumn(NodeList.COLUMN_DATE);
    model.addColumn(NodeList.COLUMN_TEXT);
    model.addColumn(NodeList.COLUMN_ICONS);
    model.addColumn(NodeList.COLUMN_CREATED);
    model.addColumn(NodeList.COLUMN_MODIFIED);
    model.addColumn(NodeList.COLUMN_DETAILS);
    model.addColumn(NodeList.COLUMN_NOTES);
    if (searchInAllMaps == false) {
        final NodeModel node = Controller.getCurrentController().getMap().getRootNode();
        updateModel(model, node);
    } else {
        final Map<String, MapModel> maps = Controller.getCurrentController().getMapViewManager()
                .getMaps(MModeController.MODENAME);
        for (final MapModel map : maps.values()) {
            final NodeModel node = map.getRootNode();
            updateModel(model, node);
        }
    }
    return model;
}

From source file:org.freeplane.view.swing.features.time.mindmapmode.NodeList.java

/**
 * Creates a table model for the new table and returns it.
 *///from  ww  w .j a v a  2  s.  com
private DefaultTableModel updateModel() {
    final DefaultTableModel model = new DefaultTableModel() {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        /*
         * (non-Javadoc)
         * @see javax.swing.table.AbstractTableModel#getColumnClass(int)
         */
        @Override
        public Class<?> getColumnClass(final int arg0) {
            switch (arg0) {
            case DATE_COLUMN:
            case NODE_CREATED_COLUMN:
            case NODE_MODIFIED_COLUMN:
                return Date.class;
            case NODE_TEXT_COLUMN:
                return NodeHolder.class;
            case NODE_ICON_COLUMN:
                return IconsHolder.class;
            case NODE_NOTES_COLUMN:
                return NotesHolder.class;
            default:
                return Object.class;
            }
        }
    };
    model.addColumn(NodeList.COLUMN_DATE);
    model.addColumn(NodeList.COLUMN_TEXT);
    model.addColumn(NodeList.COLUMN_ICONS);
    model.addColumn(NodeList.COLUMN_CREATED);
    model.addColumn(NodeList.COLUMN_MODIFIED);
    model.addColumn(NodeList.COLUMN_NOTES);
    if (searchInAllMaps == false) {
        final NodeModel node = Controller.getCurrentController().getMap().getRootNode();
        updateModel(model, node);
    } else {
        final Map<String, MapModel> maps = Controller.getCurrentController().getMapViewManager()
                .getMaps(MModeController.MODENAME);
        for (final MapModel map : maps.values()) {
            final NodeModel node = map.getRootNode();
            updateModel(model, node);
        }
    }
    return model;
}

From source file:org.ut.biolab.medsavant.client.patient.AddPatientsForm.java

private void createTable() throws RemoteException, SQLException {
    scrollPane.getViewport().setBackground(Color.white);

    DefaultTableModel model = new DefaultTableModel() {
        @Override/*from w  w w  .  j ava  2 s  .  co  m*/
        public boolean isCellEditable(int row, int col) {
            return col != 0;
        }
    };
    model.addColumn("Short Name");
    model.addColumn("Value");

    CustomField[] fields = null;
    try {
        fields = MedSavantClient.PatientManager.getPatientFields(LoginController.getSessionID(),
                ProjectController.getInstance().getCurrentProjectID());
    } catch (SessionExpiredException ex) {
        MedSavantExceptionHandler.handleSessionExpiredException(ex);
    }
    for (int i = 1; i < fields.length; i++) { //skip patient id
        model.addRow(new Object[] { fields[i], "" });
    }

    table.setModel(model);

    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            setTip();
        }
    });

    table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
}

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);// ww  w.  ja  va2  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);
        }
    }
}

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);//from w w  w .j av  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. java  2s  . c om
    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: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//from ww  w.jav  a  2s  . c o  m
        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:Visao.Outros.FRMRelatorio.java

private void preencheTabelaVenda() {
    DefaultTableModel dtm = this.criaTabelaVenda();

    dtm.addColumn("Cdigo");
    dtm.addColumn("Data e hora");
    dtm.addColumn("Valor total");
    dtm.addColumn("Situao");
    dtm.addColumn("Cliente");
    dtm.addColumn("Funcionrio");

    for (Venda dado : dadosVenda) {
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm - dd/MM/yyyy");
        String dataHora = sdf.format(dado.getDataHora());

        String situacao = "";

        if (dado.getSituacao().equals(Venda.Situacao.PAGO)) {
            situacao = "Pago";
        } else {/*from ww  w .j av a 2  s .com*/
            situacao = "No pago";
        }

        dtm.addRow(new Object[] { dado.getCodigo(), dataHora, dado.getValorTotal(), situacao,
                dado.getCliente().getNome(), dado.getFuncionario().getNome() });
    }

    tableVenda.setModel(dtm);
    this.calculaTotalVenda();
}

From source file:Visao.Outros.FRMRelatorio.java

private void preencheTabelaFornecimento() {
    DefaultTableModel dtm = this.criaTabelaFornecimento();

    dtm.addColumn("Cdigo");
    dtm.addColumn("Data");
    dtm.addColumn("Valor total");
    dtm.addColumn("Nota fiscal");
    dtm.addColumn("Fornecedor");

    for (Fornecimento dado : dadosFornecimento) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        String dataHora = sdf.format(dado.getData());

        dtm.addRow(new Object[] { dado.getCodigo(), dataHora, dado.getValorTotal(), dado.getnNotaFiscal(),
                dado.getFornecedor().getNome() });
    }//from ww  w.j  a v a2  s.com

    tableFornecimento.setModel(dtm);
    this.calculaTotalFornecimento();
}