Example usage for javax.swing.table TableModel setValueAt

List of usage examples for javax.swing.table TableModel setValueAt

Introduction

In this page you can find the example usage for javax.swing.table TableModel setValueAt.

Prototype

public void setValueAt(Object aValue, int rowIndex, int columnIndex);

Source Link

Document

Sets the value in the cell at columnIndex and rowIndex to aValue.

Usage

From source file:app.RunApp.java

/**
 * Action for Calculate button from principal tab
 * //from  w  w w  .  j a v  a2 s .c  om
 * @param evt Event
 * @param jtable Table
 */
private void buttonCalculateActionPerformedPrincipal(java.awt.event.ActionEvent evt, JTable jtable) {
    ArrayList<String> metricsList = getMetricsSelectedPrincipal(jtable);

    if (dataset == null) {
        JOptionPane.showMessageDialog(null, "You must load a dataset.", "Warning", JOptionPane.ERROR_MESSAGE);
        return;
    } else if (metricsList.isEmpty()) {
        JOptionPane.showMessageDialog(null, "You must select any metric.", "Warning",
                JOptionPane.ERROR_MESSAGE);
        return;
    }

    //ImbalancedFeature[] label_frenquency = MetricUtils.getImbalancedDataByAppearances(dataset);
    //label_frenquency = MetricUtils.sortByFrequency(label_frenquency);// ordena de mayor a menor

    String value;

    progressBar.setMinimum(0);
    progressBar.setMaximum(metricsList.size() + 1);
    progressBar.setValue(0);
    int v = 1;
    for (String metric : metricsList) {
        progressBar.setValue(v);
        //If metric value exists, don't calculate
        if ((tableMetrics.get(metric) == null) || (tableMetrics.get(metric).equals("-"))) {
            value = MetricUtils.getMetricValue(metric, dataset);
            tableMetrics.put(metric, value.replace(",", "."));
        }

        v++;
    }

    TableModel model = jtable.getModel();

    for (int i = 0; i < model.getRowCount(); i++) {
        model.setValueAt(MetricUtils.getValueFormatted(model.getValueAt(i, 0).toString(),
                tableMetrics.get(model.getValueAt(i, 0).toString())), i, 1);
    }

    jtable.repaint();
}

From source file:app.RunApp.java

/**
 * Action for Invert button from principal tab
 * /*  w  w w  . j  a va 2  s .co m*/
 * @param evt Event
 * @param jtable Table
 */
private void buttonInvertActionButtonPerformed(java.awt.event.ActionEvent evt, JTable jtable) {
    TableModel tmodel = jtable.getModel();

    for (int i = 0; i < tmodel.getRowCount(); i++) {
        if ((Boolean) tmodel.getValueAt(i, 2)) {
            tmodel.setValueAt(Boolean.FALSE, i, 2);
        } else {
            tmodel.setValueAt(Boolean.TRUE, i, 2);
        }
    }

    jtable.setModel(tmodel);
    jtable.repaint();
}

From source file:app.RunApp.java

/**
 * Action for Invert button from multiple datasets tab
 * /*from w  ww .java 2s.co  m*/
 * @param evt Event
 * @param jtable Table
 */
private void buttonInvertActionPerformedMulti(java.awt.event.ActionEvent evt, JTable jtable) {
    TableModel tmodel = jtable.getModel();

    for (int i = 0; i < tmodel.getRowCount(); i++) {
        if ((Boolean) tmodel.getValueAt(i, 1)) {
            tmodel.setValueAt(Boolean.FALSE, i, 1);
        } else {
            tmodel.setValueAt(Boolean.TRUE, i, 1);
        }
    }

    jtable.setModel(tmodel);
    jtable.repaint();
}

From source file:app.RunApp.java

/**
 * Clear table of metrics from principal tab
 *///www.  ja  v a2  s.  c  o  m
private void clearTableMetricsPrincipal() {
    ArrayList<String> metricsList = MetricUtils.getAllMetrics();

    for (String metric : metricsList) {
        if (metric.charAt(0) != '<') {
            tableMetrics.put(metric, "-");
        } else {
            tableMetrics.put(metric, "");
        }
    }

    TableModel model = jTablePrincipal.getModel();

    for (int i = 0; i < model.getRowCount(); i++) {
        if (metricsList.get(i).charAt(0) != '<') {
            model.setValueAt(tableMetrics.get(model.getValueAt(i, 0).toString()), i, 1);
        }
    }

    jTablePrincipal.repaint();
}

From source file:org.datacleaner.panels.DatabaseDriversPanel.java

private DCTable getDatabaseDriverTable() {
    final List<DatabaseDriverDescriptor> databaseDrivers = _databaseDriverCatalog.getDatabaseDrivers();
    final List<UserDatabaseDriver> userPreferencesDatabaseDrivers = _userPreferences.getDatabaseDrivers();
    final List<UserDatabaseDriver> unknownManuallyInstalledDrivers = getUnknownManuallyInstalledDrivers(
            userPreferencesDatabaseDrivers, databaseDrivers);
    final TableModel tableModel = new DefaultTableModel(
            new String[] { "", "Database", "Driver class", "Installed?", "Used?" },
            databaseDrivers.size() + unknownManuallyInstalledDrivers.size());

    final DCTable table = new DCTable(tableModel);

    final Icon validIcon = imageManager.getImageIcon(IconUtils.STATUS_VALID, IconUtils.ICON_SIZE_SMALL);
    final Icon invalidIcon = imageManager.getImageIcon(IconUtils.STATUS_ERROR, IconUtils.ICON_SIZE_SMALL);

    final int installedCol = 3;
    final int usedCol = 4;
    int row = 0;/* w w  w  . j  a v a  2 s  . c o  m*/
    for (final DatabaseDriverDescriptor dd : databaseDrivers) {
        final String driverClassName = dd.getDriverClassName();
        final String displayName = dd.getDisplayName();

        final Icon driverIcon = imageManager.getImageIcon(DatabaseDriverCatalog.getIconImagePath(dd),
                IconUtils.ICON_SIZE_SMALL);

        tableModel.setValueAt(driverIcon, row, 0);
        tableModel.setValueAt(displayName, row, 1);
        tableModel.setValueAt(driverClassName, row, 2);
        tableModel.setValueAt("", row, 3);
        tableModel.setValueAt("", row, 4);

        final DatabaseDriverState state = _databaseDriverCatalog.getState(dd);
        if (state == DatabaseDriverState.INSTALLED_WORKING) {
            tableModel.setValueAt(validIcon, row, installedCol);
        } else if (state == DatabaseDriverState.INSTALLED_NOT_WORKING) {
            tableModel.setValueAt(invalidIcon, row, installedCol);
        } else if (state == DatabaseDriverState.NOT_INSTALLED) {
            final String[] downloadUrls = dd.getDownloadUrls();
            if (downloadUrls != null) {
                final DCPanel buttonPanel = new DCPanel();
                buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 0));

                final JButton downloadButton = WidgetFactory.createSmallButton(IconUtils.ACTION_DOWNLOAD);
                downloadButton.setToolTipText("Download and install the driver for " + dd.getDisplayName());

                downloadButton.addActionListener(createDownloadActionListener(dd));
                buttonPanel.add(downloadButton);

                tableModel.setValueAt(buttonPanel, row, installedCol);
            }
        }

        if (isUsed(driverClassName)) {
            tableModel.setValueAt(validIcon, row, usedCol);
        }

        row++;
    }

    for (UserDatabaseDriver driver : unknownManuallyInstalledDrivers) {
        final String driverClassName = driver.getDriverClassName();
        final Icon driverIcon = imageManager.getImageIcon(IconUtils.GENERIC_DATASTORE_IMAGEPATH,
                IconUtils.ICON_SIZE_SMALL);
        tableModel.setValueAt(driverIcon, row, 0);
        tableModel.setValueAt("", row, 1);
        tableModel.setValueAt(driverClassName, row, 2);
        final DatabaseDriverState state = driver.getState();
        if (state == DatabaseDriverState.INSTALLED_WORKING) {
            tableModel.setValueAt(validIcon, row, installedCol);
        } else if (state == DatabaseDriverState.INSTALLED_NOT_WORKING) {
            tableModel.setValueAt(invalidIcon, row, installedCol);
        } else if (state == DatabaseDriverState.NOT_INSTALLED) {
            final Icon icon = imageManager.getImageIcon(IconUtils.STATUS_WARNING, IconUtils.ICON_SIZE_SMALL);
            tableModel.setValueAt(icon, row, installedCol);

        }
        if (isUsed(driverClassName)) {
            tableModel.setValueAt(validIcon, row, usedCol);
        }
        row++;
    }

    table.setAlignment(installedCol, Alignment.CENTER);
    table.setAlignment(usedCol, Alignment.CENTER);

    table.setRowHeight(IconUtils.ICON_SIZE_SMALL + 4);
    table.getColumn(0).setMaxWidth(IconUtils.ICON_SIZE_SMALL + 4);
    table.getColumn(installedCol).setMaxWidth(84);
    table.getColumn(usedCol).setMaxWidth(70);
    table.setColumnControlVisible(false);
    return table;
}

From source file:org.eobjects.datacleaner.panels.DatabaseDriversPanel.java

private DCTable getDatabaseDriverTable() {
    final List<DatabaseDriverDescriptor> databaseDrivers = _databaseDriverCatalog.getDatabaseDrivers();
    final TableModel tableModel = new DefaultTableModel(
            new String[] { "", "Database", "Driver class", "Installed?", "Used?" }, databaseDrivers.size());

    final DCTable table = new DCTable(tableModel);

    final Icon validIcon = imageManager.getImageIcon(IconUtils.STATUS_VALID, IconUtils.ICON_SIZE_SMALL);
    final Icon invalidIcon = imageManager.getImageIcon(IconUtils.STATUS_ERROR, IconUtils.ICON_SIZE_SMALL);

    final int installedCol = 3;
    final int usedCol = 4;
    int row = 0;/*  www . j a  v  a2s  . c om*/
    for (final DatabaseDriverDescriptor dd : databaseDrivers) {
        final String driverClassName = dd.getDriverClassName();
        final String displayName = dd.getDisplayName();

        final Icon driverIcon = imageManager.getImageIcon(DatabaseDriverCatalog.getIconImagePath(dd),
                IconUtils.ICON_SIZE_SMALL);

        tableModel.setValueAt(driverIcon, row, 0);
        tableModel.setValueAt(displayName, row, 1);
        tableModel.setValueAt(driverClassName, row, 2);
        tableModel.setValueAt("", row, 3);
        tableModel.setValueAt("", row, 4);

        final DatabaseDriverState state = _databaseDriverCatalog.getState(dd);
        if (state == DatabaseDriverState.INSTALLED_WORKING) {
            tableModel.setValueAt(validIcon, row, installedCol);
        } else if (state == DatabaseDriverState.INSTALLED_NOT_WORKING) {
            tableModel.setValueAt(invalidIcon, row, installedCol);
        } else if (state == DatabaseDriverState.NOT_INSTALLED) {
            final String[] downloadUrls = dd.getDownloadUrls();
            if (downloadUrls != null) {
                final DCPanel buttonPanel = new DCPanel();
                buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 0));

                final JButton downloadButton = WidgetFactory.createSmallButton("images/actions/download.png");
                downloadButton.setToolTipText("Download and install the driver for " + dd.getDisplayName());

                downloadButton.addActionListener(createDownloadActionListener(dd));
                buttonPanel.add(downloadButton);

                tableModel.setValueAt(buttonPanel, row, installedCol);
            }
        }

        if (isUsed(driverClassName)) {
            tableModel.setValueAt(validIcon, row, usedCol);
        }

        row++;
    }

    table.setAlignment(installedCol, Alignment.CENTER);
    table.setAlignment(usedCol, Alignment.CENTER);

    table.setRowHeight(IconUtils.ICON_SIZE_SMALL + 4);
    table.getColumn(0).setMaxWidth(IconUtils.ICON_SIZE_SMALL + 4);
    table.getColumn(installedCol).setMaxWidth(84);
    table.getColumn(usedCol).setMaxWidth(70);
    table.setColumnControlVisible(false);
    return table;
}

From source file:org.openstreetmap.josm.gui.preferences.imagery.CacheContentsPanel.java

private static JTable getTableForCache(final CacheAccess<String, BufferedImageCacheEntry> cache,
        final TableModel tableModel) {
    final JTable ret = new JTable(tableModel);

    ButtonColumn buttonColumn = new ButtonColumn(new AbstractAction() {
        @Override/*from  w  ww. j a v  a  2s.  co  m*/
        public void actionPerformed(ActionEvent e) {
            int row = ret.convertRowIndexToModel(ret.getEditingRow());
            tableModel.setValueAt("0", row, 1);
            cache.remove(ret.getValueAt(row, 0).toString() + ':');
        }
    });
    TableColumn tableColumn = ret.getColumnModel().getColumn(2);
    tableColumn.setCellRenderer(buttonColumn);
    tableColumn.setCellEditor(buttonColumn);
    return ret;
}