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:dylemator.UserList.java

private void filenameComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_filenameComboActionPerformed
    Object item = this.filenameCombo.getSelectedItem();
    exportData = new ArrayList<String[]>();
    File file = new File(item.toString());
    if (file.exists()) {
        String datePattern = "(\\d+-\\d+-\\d+)";
        Pattern r = Pattern.compile(datePattern);
        Matcher m = r.matcher(file.getName());
        String fileDate;//from   ww w.  j  a v  a2s  .  c  o m
        if (m.find()) {
            fileDate = m.group(0);
        } else
            fileDate = new Date(file.lastModified()).toString();

        DefaultTableModel model = (DefaultTableModel) this.personsTable.getModel();
        model.setRowCount(0);
        model.setColumnCount(0);
        try {
            InputStreamReader input = new FileReader(file);
            BufferedReader bufferReader;
            bufferReader = new BufferedReader(input);
            // headers
            String headerLine = bufferReader.readLine();
            String[] headers = headerLine.split(";");
            // kod osoby i data badania
            String[] userHeaders = new String[] { headers[0], headers[1] };
            String[] valueHeaders = Arrays.copyOfRange(headers, 4, headers.length);
            Object[] allHeaders = ArrayUtils.addAll(userHeaders, valueHeaders);

            for (int header = 0; header < allHeaders.length; header++) {
                model.addColumn(allHeaders[header]);

            }
            exportData.add((String[]) allHeaders);

            String line;
            while ((line = bufferReader.readLine()) != null) {
                String[] fields = line.split(";");
                String[] userFields = new String[] { fields[0], fileDate };
                String[] valueFields = Arrays.copyOfRange(fields, 4, fields.length);
                Object[] allValues = ArrayUtils.addAll(userFields, valueFields);
                model.addRow(allValues);
                exportData.add((String[]) allValues);
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(FindDialog.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(FindDialog.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:com.farouk.projectapp.FirstGUI.java

private void UpdatejTable3(Company com) {
    DefaultTableModel modelCompany = new DefaultTableModel();
    modelCompany.setColumnIdentifiers(new String[] { "Name", "Symbol", "Stock Price ()", "Bid Price",
            "Ask Price", "Quantity Bought" });
    modelCompany.addRow(new String[] { com.getName(), com.getSymbol(),
            String.valueOf(com.getStockPrice().doubleValue()), String.valueOf(com.getBidPrice().doubleValue()),
            String.valueOf(com.getAskPrice().doubleValue()), Integer.toString(com.getNumberOwned()) });
    jTable3.setModel(modelCompany);/*from   w  w  w.  j  a v  a 2s  . c  o m*/
}

From source file:gdt.jgui.tool.JEntityEditor.java

private void showElement(Sack entity, String element$) {
    try {/*from  w w w. j  a v  a 2  s  . c o m*/
        //      System.out.println("EntityEditor:showElement:"+element$);
        Core[] ca = null;
        if ("attributes".equals(element$))
            ca = entity.attributesGet();
        else
            ca = entity.elementGet(element$);
        final JTable table = new JTable();
        DefaultTableModel model = new DefaultTableModel(null, new String[] { "type", "name", "value" });
        table.setModel(model);
        table.getTableHeader().setDefaultRenderer(new SimpleHeaderRenderer());
        table.getTableHeader().addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                int col = table.columnAtPoint(e.getPoint());
                String name = table.getColumnName(col);
                //              System.out.println("Column index selected " + col + " " + name);
                sort(name);
            }
        });
        JScrollPane scrollPane = new JScrollPane();
        tabbedPane.add(element$, scrollPane);
        scrollPane.add(table);
        scrollPane.setViewportView(table);
        if (ca != null)
            for (Core aCa : ca) {
                model.addRow(new String[] { aCa.type, aCa.name, aCa.value });
            }
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
}

From source file:NewApplication.java

private void EditTable(Class clazz) {
    // TODO add your handling code here:

    DefaultTableModel model = (DefaultTableModel) jTable2.getModel();

    model.setColumnCount(3);/* w  w  w  . j  a  v a  2 s . c  o m*/

    model.setNumRows(0);

    jTable2.setModel(model);

    TableColumn tc = jTable2.getColumnModel().getColumn(0);
    tc.setHeaderValue("Field Name");
    tc = jTable2.getColumnModel().getColumn(1);
    tc.setHeaderValue("Value");
    tc = jTable2.getColumnModel().getColumn(2);
    tc.setHeaderValue("Type");

    try {

        Field[] fields = clazz.getDeclaredFields();

        for (Field f : fields) {

            Object[] obs = new Object[3];

            model = (DefaultTableModel) jTable2.getModel();

            f.setAccessible(true);

            obs[0] = f.getName();
            obs[2] = f.getType().getName();

            if (f.getName() == "" || f.getName() == null)
                continue;

            model.addRow(obs);

            jTable2.setModel(model);

        }

        jTable2.repaint();

    } catch (Exception ex) {
    }
    ;
}

From source file:br.com.postalis.folhapgto.proc.TelaPrincipal.java

private void preencherTabela() {
    JTableRenderer render = new JTableRenderer();
    render.setHorizontalAlignment(SwingConstants.CENTER);
    DefaultTableCellRenderer centralizar = new DefaultTableCellRenderer();
    centralizar.setHorizontalAlignment(SwingConstants.CENTER);

    ((DefaultTableCellRenderer) tabelaEnvios.getTableHeader().getDefaultRenderer())
            .setHorizontalAlignment(SwingConstants.CENTER);
    tabelaEnvios.getColumnModel().getColumn(0).setCellRenderer(centralizar);
    tabelaEnvios.getColumnModel().getColumn(1).setCellRenderer(centralizar);
    tabelaEnvios.getColumnModel().getColumn(2).setCellRenderer(centralizar);
    tabelaEnvios.getColumnModel().getColumn(3).setCellRenderer(centralizar);
    tabelaEnvios.getColumnModel().getColumn(4).setCellRenderer(centralizar);
    tabelaEnvios.getColumnModel().getColumn(5).setCellRenderer(centralizar);
    tabelaEnvios.getColumnModel().getColumn(6).setCellRenderer(render);
    //        tabelaEnvios.getColumnModel().getColumn(7).setCellRenderer(render);

    DefaultTableModel modelo = (DefaultTableModel) tabelaEnvios.getModel();
    modelo.setNumRows(0);//from  w  ww  .ja v  a  2  s  . c o  m

    try {
        Icon log = new ImageIcon(getClass().getResource("/imagens/notas_20x20.png"));
        //Icon criticas = new ImageIcon(getClass().getResource("/imagens/alerta_20x20.png"));
        SimpleDateFormat formatComHora = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
        SimpleDateFormat formatSemHora = new SimpleDateFormat("dd-MM-yyyy");
        //modelo.addRow(new Object[]{1,formatSemHora.format(DateTime.now().toDate()),formatComHora.format(DateTime.now().toDate()), "JONATHAN",
        //formatComHora.format(DateTime.now().toDate()), "JONATHAN", log, criticas });
        for (PosGpxConsignacaoPopulisControle cp : svc.buscarHistoricoProcessamento()) {
            ;
            modelo.addRow(new Object[] { cp.getSqControle(), formatSemHora.format(cp.getDtReferencia()),
                    cp.getDtExportacao() == null ? "" : formatComHora.format(cp.getDtExportacao()),
                    cp.getCdUserExportacao(),
                    cp.getDtImportacao() == null ? "" : formatComHora.format(cp.getDtImportacao()),
                    cp.getCdUserImportacao(), log });
        }

    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Erro ao carregar a tabela de envios!!!", "Mensagem de erro",
                JOptionPane.OK_OPTION);
    }

}

From source file:vinci.project2.pkg1.View.java

private void calcButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_calcButtonActionPerformed
    try {/*  www. ja v a  2 s .  co  m*/
        Integer.parseInt(ageField.getText());
        Integer.parseInt(retAgeField.getText());
        Double.parseDouble(capRateGainsField.getText());
        Double.parseDouble(iTaxField.getText());
        Double.parseDouble(rorField.getText());
        Double.parseDouble(preBalField.getText());
        Double.parseDouble(postBalField.getText());
        Double.parseDouble(preContField.getText());
        Double.parseDouble(postContField.getText());

        Retirement r = new Retirement();

        clearXY();
        getVars();

        loopVar = retAge - age;
        ror = 1 + ror;

        DefaultTableModel model = (DefaultTableModel) outputTable.getModel();
        model.setRowCount(0);

        for (int q = 0; q < loopVar + 1; q++) {
            String preTaxS = r.preTaxM(q, loopVar, ror, year, preBal, preCont, iTax);
            String postTaxS = r.postTaxM(q, loopVar, year, ror, postBal, capRateGains, preCont, postTax);

            year = Double.parseDouble(preTaxS);
            post = Double.parseDouble(postTaxS);

            String totalS = r.total(total, year, post);

            totalD = Double.parseDouble(totalS);

            yearArray.add(new Year(age, year, post, totalD));

            Object[] row = { age, "$" + preTaxS, "$" + postTaxS, "$" + String.format("%.2f", totalD) };
            model.addRow(row);

            addXY();

            age++;
        }

        outputTable.setModel(model);

        setChart();
    } catch (NumberFormatException e) {
        calcButton.setEnabled(false);
    }
}

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

private JButton getResetQueryBtn() {
    if (resetQueryBtn == null) {
        resetQueryBtn = new JButton();
        resetQueryBtn.setText("???");
        resetQueryBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                DefaultTableModel dirCompareModel = getDefaultTableModel();
                for (Object[] rows : modelOrignList) {
                    dirCompareModel.addRow(rows);
                }// w w  w.j  a  v  a 2s . co  m
                while (dirCompareTable.getModel().getRowCount() != dirCompareModel.getRowCount()) {
                    dirCompareTable.setModel(dirCompareModel);
                    System.out.println("reset dirCompareTable");
                }
                initComponents();
            }
        });
    }
    return resetQueryBtn;
}

From source file:userinterface.DoctorWorkArea.DiagnosePatientJPanel.java

public void populateTable() {

    DefaultTableModel model = (DefaultTableModel) productTable.getModel();

    model.setRowCount(0);/*from  w  ww . j  av a  2 s. c  o m*/
    for (Product product : enterprise.getProductCatalog().getProductcatalog()) {

        Object[] row = new Object[4];
        row[0] = product;
        row[1] = product.getModelNumber();
        row[2] = product.getPrice();
        row[3] = product.getAvailableAmount();

        model.addRow(row);

    }
}

From source file:Interface.FoodCollectionSupervisor.FoodCollectionWorkArea.java

private void populateNewRequestTable() {
    DefaultTableModel model = (DefaultTableModel) tblNewRequest.getModel();
    model.setRowCount(0);//from w  ww .j  ava 2s  .c  o  m
    for (WorkRequest request : organization.getWorkQueue().getWorkRequestList()) {
        //request = (FoodCollectionWorkRequest) request;
        if (request.getStatus().equalsIgnoreCase("New Request")) {

            Object[] row = new Object[7];
            row[0] = ((FoodCollectionWorkRequest) request);
            row[1] = ((FoodCollectionWorkRequest) request).getFood().getFoodType();
            row[2] = ((FoodCollectionWorkRequest) request).getSender().getEmployee();
            row[3] = ((FoodCollectionWorkRequest) request).getFood().getFoodPriority();
            row[4] = ((FoodCollectionWorkRequest) request).getSender().getEmployee().getAddress();
            row[5] = ((FoodCollectionWorkRequest) request).getDriverName();
            row[6] = request.getStatus();
            model.addRow(row);
        }

    }

}

From source file:ui.Analyze.java

private void genaratePermintaan(LocalDate awal, LocalDate akhir) throws SQLException {
    org.jfree.data.general.DefaultPieDataset data = new org.jfree.data.general.DefaultPieDataset();
    javax.swing.table.DefaultTableModel m = new javax.swing.table.DefaultTableModel(
            new String[] { "Nama Barang", "Jumlah" }, 0) {
        @Override// w  w w .  ja  v a 2  s .  c  om
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    tblMinta.setModel(m);
    java.sql.PreparedStatement p = d.getPS(
            "select detjual.brg,sum(detjual.jum)as qty from jual left join detjual on jual.nota=detjual.nota "
                    + "where jual.tgl>=? and " + "jual.tgl<=? group by detjual.brg");
    p.setDate(1, Date.valueOf(awal));
    p.setDate(2, Date.valueOf(akhir));
    java.sql.ResultSet r = p.executeQuery();
    while (r.next()) {
        String brg = r.getString("brg");
        double qty = r.getDouble("qty");
        data.setValue(brg, qty);
        m.addRow(new String[] { brg, "" + qty });
    }
    r.close();
    p.close();
    org.jfree.chart.ChartPanel cp = new org.jfree.chart.ChartPanel(
            ChartFactory.createPieChart("Permintaan", data, true, true, false));
    cp.setSize(pnlMinta.getSize());
    if (0 < pnlMinta.getComponentCount())
        pnlMinta.removeAll();
    pnlMinta.add(cp);
}