Example usage for javax.swing JTable getModel

List of usage examples for javax.swing JTable getModel

Introduction

In this page you can find the example usage for javax.swing JTable getModel.

Prototype

public TableModel getModel() 

Source Link

Document

Returns the TableModel that provides the data displayed by this JTable .

Usage

From source file:app.RunApp.java

/**
 * Get selected metrics in table from multiple datasets tab
 * //from  ww  w. j ava2  s  .co m
 * @param jtable Table
 * @return List with the selected metrics
 */
private ArrayList<String> getSelectedMetricsMulti(JTable jtable) {
    ArrayList<String> result = new ArrayList();
    TableModel tmodel = jtable.getModel();

    for (int i = 0; i < tmodel.getRowCount(); i++) {
        if ((Boolean) tmodel.getValueAt(i, 1)) {
            String selected = (String) tmodel.getValueAt(i, 0);
            result.add(selected);
        }
    }
    return result;
}

From source file:app.RunApp.java

/**
 * Generates TableModel for Box Diagrams
 * //w w  w  .  j  a  va  2  s.  c  o m
 * @param jtable Table
 * @param dataset Multi-label dataset
 * @return Generated TableModel
 */
private TableModel boxplotTableModel(JTable jtable) {
    DefaultTableModel tableModel = new DefaultTableModel() {
        @Override
        public boolean isCellEditable(int row, int column) {
            //This causes all cells to be not editable
            return false;
        }
    };

    tableModel.addColumn("Diagram");

    Object[] row = new Object[1];

    row[0] = "#Examples per label";
    tableModel.addRow(row);
    row[0] = "#Examples per labelset";
    tableModel.addRow(row);

    jtable.setModel(tableModel);

    return jtable.getModel();
}

From source file:app.RunApp.java

/**
 * Generates TableModel for attributes/*from  www.j a v a  2 s  . c o  m*/
 * 
 * @param jtable Table
 * @param dataset Multi-label dataset
 * @return Generated TableModel
 */
private TableModel attributesTableModel(JTable jtable, MultiLabelInstances dataset) {
    DefaultTableModel tableModel = new DefaultTableModel() {
        @Override
        public boolean isCellEditable(int row, int column) {
            //This causes all cells to be not editable
            return false;
        }
    };

    tableModel.addColumn("Attribute");

    Object[] row = new Object[1];

    Instances instances = dataset.getDataSet();

    int numLabels = dataset.getNumLabels();

    int numAttributes = instances.numAttributes() - numLabels;

    Attribute att;
    for (int i = 0; i < numAttributes; i++) {
        att = instances.attribute(i);
        if (att.isNumeric()) {
            row[0] = att.name();
            tableModel.addRow(row);
        }
    }

    jtable.setModel(tableModel);

    return jtable.getModel();
}

From source file:app.RunApp.java

/**
 * Generates TableModel for IR intra class
 * /*from   w  ww.  ja  v  a2 s .c  o m*/
 * @param jtable
 * @return 
 */
private TableModel irIntraClassTableModel(JTable jtable) {
    DefaultTableModel tableModel = new DefaultTableModel() {
        @Override
        public boolean isCellEditable(int row, int column) {
            //This causes all cells to be not editable
            return false;
        }
    };

    tableModel.addColumn("Label");
    tableModel.addColumn("IR");

    Object[] row = new Object[2];

    String truncate;

    for (int i = 0; i < imbalancedLabels.length; i++) {
        truncate = Double.toString(imbalancedLabels[i].getIRIntraClass());

        row[0] = imbalancedLabels[i].getName();
        row[1] = MetricUtils.getValueFormatted(truncate, 3);

        tableModel.addRow(row);
    }

    jtable.setModel(tableModel);

    TableColumnModel tcm = jtable.getColumnModel();

    tcm.getColumn(0).setPreferredWidth(80);
    tcm.getColumn(1).setPreferredWidth(50);

    return jtable.getModel();
}

From source file:app.RunApp.java

/**
 * Generates TableModel for IR inter class
 * //from   w ww  .  j  ava 2  s  . c  o m
 * @param jtable
 * @return 
 */
private TableModel irInterClassTableModel(JTable jtable) {
    DefaultTableModel tableModel = new DefaultTableModel() {
        @Override
        public boolean isCellEditable(int row, int column) {
            //This causes all cells to be not editable
            return false;
        }
    };

    tableModel.addColumn("Label");
    tableModel.addColumn("IR");

    Object[] row = new Object[2];

    String truncate;

    IRInterClass = MetricUtils.getIRInterClassValues(labelAppearances);

    int temp = IRInterClass.length - 1;
    for (int i = temp; i >= 0; i--) {
        truncate = Double.toString(IRInterClass[i]);

        row[0] = labelAppearances[i].getName();
        row[1] = MetricUtils.getValueFormatted(truncate, 3);

        tableModel.addRow(row);
    }

    jtable.setModel(tableModel);

    TableColumnModel tcm = jtable.getColumnModel();
    tcm.getColumn(0).setPreferredWidth(80);
    tcm.getColumn(1).setPreferredWidth(50);

    return jtable.getModel();
}

From source file:app.RunApp.java

/**
 * Generate TableModel for label frequency
 * /*w ww.  jav a  2 s.c  o  m*/
 * @param jtable Table
 * @param dataset Multi-label dataset
 * @return Generated TableModel
 */
private TableModel labelFrequencyTableModel(JTable jtable, MultiLabelInstances dataset) {
    DefaultTableModel tableModel = new DefaultTableModel() {
        @Override
        public boolean isCellEditable(int row, int column) {
            //This causes all cells to be not editable
            return false;
        }
    };

    tableModel.addColumn("Label");
    tableModel.addColumn("# Examples");
    tableModel.addColumn("Frequency");

    Object[] row = new Object[3];

    ImbalancedFeature current;
    double freq;
    String truncate;

    for (int i = 0; i < dataset.getNumLabels(); i++) {
        current = labelAppearances[i];

        row[0] = current.getName();
        freq = current.getAppearances() * 1.0 / dataset.getNumInstances();

        row[1] = current.getAppearances();

        truncate = Double.toString(freq);
        row[2] = MetricUtils.truncateValue(truncate, 4);

        tableModel.addRow(row);
    }

    jtable.setModel(tableModel);

    TableColumnModel tcm = jtable.getColumnModel();

    tcm.getColumn(0).setPreferredWidth(80);
    tcm.getColumn(1).setPreferredWidth(70);
    tcm.getColumn(2).setPreferredWidth(70);

    return jtable.getModel();
}

From source file:app.RunApp.java

/**
 * Generates TableModel for frequency values
 * /*from w ww . j a  v  a  2 s. com*/
 * @param jtable Table
 * @param dataset Multi-label dataset
 * @return Generated TableModel
 */
private TableModel frequencyTableModel(JTable jtable, MultiLabelInstances dataset) {
    DefaultTableModel tableModel = new DefaultTableModel() {
        @Override
        public boolean isCellEditable(int row, int column) {
            //This causes all cells to be not editable
            return false;
        }
    };

    tableModel.addColumn("Label");
    tableModel.addColumn("# Examples");
    tableModel.addColumn("Frequency");

    Object[] row = new Object[3];

    ImbalancedFeature current;
    double freq;
    String truncate;

    for (int i = 0; i < dataset.getNumLabels(); i++) {
        current = labelAppearances[i];

        row[0] = current.getName();
        freq = current.getAppearances() * 1.0 / dataset.getNumInstances();

        row[1] = current.getAppearances();

        truncate = Double.toString(freq);
        row[2] = MetricUtils.getValueFormatted(truncate, 4);

        tableModel.addRow(row);
    }

    jtable.setModel(tableModel);

    TableColumnModel tcm = jtable.getColumnModel();
    tcm.getColumn(0).setPreferredWidth(80);
    tcm.getColumn(1).setPreferredWidth(70);
    tcm.getColumn(2).setPreferredWidth(50);

    return jtable.getModel();
}

From source file:app.RunApp.java

/**
 * Action for Calculate button from principal tab
 * /*from   w  w  w  .j  a va2  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

/**
 * Generates TableModel for labels per example values
 * /* w  w w .j  a v a  2s.  co m*/
 * @param jtable Table
 * @param labelsPerExample Number of labels per example
 * @return Generated TableModel
 */
private TableModel labelsPerExampleTableModel(JTable jtable, HashMap<Integer, Integer> labelsPerExample) {
    DefaultTableModel tableModel = new DefaultTableModel() {
        @Override
        public boolean isCellEditable(int row, int column) {
            //This causes all cells to be not editable
            return false;
        }
    };

    tableModel.addColumn("# Labels");
    tableModel.addColumn("# Examples");
    tableModel.addColumn("Frequency");

    Object[] row = new Object[3];

    double freq;
    int freqCurrent;
    String truncate;

    int max = Utils.maxKey(labelsPerExample);

    for (int i = 0; i <= max; i++) {
        freqCurrent = 0;
        if (labelsPerExample.get(i) != null) {
            freqCurrent = labelsPerExample.get(i);
        }

        freq = freqCurrent * 1.0 / dataset.getNumInstances();

        row[0] = i;
        row[1] = freqCurrent;
        truncate = Double.toString(freq);
        row[2] = MetricUtils.getValueFormatted(truncate, 4);

        tableModel.addRow(row);
    }

    jtable.setModel(tableModel);

    TableColumnModel tcm = jtable.getColumnModel();
    tcm.getColumn(0).setPreferredWidth(80);
    tcm.getColumn(1).setPreferredWidth(50);
    tcm.getColumn(2).setPreferredWidth(70);

    return jtable.getModel();
}

From source file:app.RunApp.java

/**
 * Generates TableModel for imbalanced data
 * // w w w  .ja v a 2 s.co m
 * @param jtable Table
 * @param dataset Multi-label dataset
 * @return Generated TableModel
 */
private TableModel imbalancedTableModel(JTable jtable, MultiLabelInstances dataset) {
    DefaultTableModel tableModel = new DefaultTableModel() {
        @Override
        public boolean isCellEditable(int row, int column) {
            //This causes all cells to be not editable
            return false;
        }
    };

    tableModel.addColumn("Label");
    tableModel.addColumn("IR intra class");
    tableModel.addColumn("IR inter class");
    tableModel.addColumn("STDEV intra class");
    imbalancedLabels = MetricUtils.sortImbalancedDataByIRIntraClass(imbalancedLabels);

    Object[] row = new Object[4];
    double std;
    String truncate;

    ImbalancedFeature current;

    for (int i = 0; i < dataset.getNumLabels(); i++) {
        current = imbalancedLabels[i];

        row[0] = current.getName();

        truncate = Double.toString(current.getIRIntraClass());
        row[1] = MetricUtils.truncateValue(truncate, 5);

        truncate = Double.toString(current.getIRInterClass());
        row[2] = MetricUtils.truncateValue(truncate, 5);

        std = Math.sqrt(current.getVariance());
        row[3] = MetricUtils.truncateValue(std, 4);

        tableModel.addRow(row);
    }

    jtable.setModel(tableModel);

    TableColumnModel tcm = jtable.getColumnModel();
    tcm.getColumn(0).setPreferredWidth(100);
    tcm.getColumn(1).setPreferredWidth(20);
    tcm.getColumn(2).setPreferredWidth(80);
    tcm.getColumn(3).setPreferredWidth(40);

    return jtable.getModel();
}