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:app.RunApp.java

/**
 * Generates TableModel for attributes/*from w w  w.j av a2 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 w  w .j  a  v  a2s  .c  om*/
 * @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 ww  w .ja va2  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

/**
 * Generates TableModel for frequency values
 * //ww w .j  a v  a2 s  . co m
 * @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

/**
 * Generate TableModel for label frequency
 * //w  w w.  j av  a2s .c om
 * @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 labels per example values
 * //w  w  w  .ja  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
 * /*from   w  w w  .j a va  2  s  . c om*/
 * @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();
}

From source file:app.RunApp.java

/**
 * Set frequency of labelsets/*w  ww .j a v a 2s  . c  om*/
 * 
 * @param jtable Table
 * @param dataset Dataset
 * @param stat Statistics
 * @param cp Plot
 * @return Generated TableModel
 * @throws Exception 
 */
private TableModel labelsetsFrequencyTableModel(JTable jtable, MultiLabelInstances dataset, Statistics stat,
        CategoryPlot cp) throws Exception {
    DefaultTableModel tableModel = new DefaultTableModel() {
        @Override
        public boolean isCellEditable(int row, int column) {
            //This causes all cells to be not editable
            return false;
        }
    };

    DefaultCategoryDataset myData = new DefaultCategoryDataset();

    tableModel.addColumn("Labelset Id");
    tableModel.addColumn("# Examples");
    tableModel.addColumn("Frequency");

    double freq;

    //Labelsets frequency
    HashMap<LabelSet, Integer> result = stat.labelCombCount();
    labelsetStringsByFreq = new ArrayList<>(result.size());

    double sum = 0.0;
    Set<LabelSet> keysets = result.keySet();

    Object[] row = new Object[3];

    int count = 1;

    ArrayList<ImbalancedFeature> listImbalanced = new ArrayList();
    ImbalancedFeature temp;

    int value;
    for (LabelSet current : keysets) {
        value = result.get(current);
        temp = new ImbalancedFeature(current.toString(), value);
        listImbalanced.add(temp);
    }

    labelsetsSorted = new ImbalancedFeature[listImbalanced.size()];
    labelsetsFrequency = new double[listImbalanced.size()];

    while (!listImbalanced.isEmpty()) {
        temp = Utils.getMax(listImbalanced);
        labelsetsSorted[count - 1] = temp;
        value = temp.getAppearances();
        labelsetsFrequency[count - 1] = value;
        row[0] = count;
        freq = value * 1.0 / dataset.getNumInstances();
        sum += freq;

        String valueFreq = Double.toString(freq);
        row[1] = value;

        row[2] = MetricUtils.getValueFormatted(valueFreq, 4);
        tableModel.addRow(row);

        String id = "ID: " + Integer.toString(count);

        myData.setValue(freq, id, "");
        labelsetStringsByFreq.add(temp.getName());

        count++;
        listImbalanced.remove(temp);
    }

    jtable.setModel(tableModel);
    jtable.setBounds(jtable.getBounds());

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

    //graph
    cp.setDataset(myData);

    sum = sum / keysets.size();
    Marker start = new ValueMarker(sum);
    start.setLabelFont(new Font("SansSerif", Font.BOLD, 12));
    start.setLabel("                        Mean: " + MetricUtils.truncateValue(sum, 4));
    start.setPaint(Color.red);
    cp.addRangeMarker(start);

    return jtable.getModel();
}

From source file:app.RunApp.java

/**
 * Set label IR//  w  ww .ja va  2  s .  c  o  m
 * 
 * @param jtable Table
 * @param stat Statistics
 * @param cp CategoryPlot
 * @return Generated TableModel
 * @throws Exception 
 */
private TableModel irLabelsetsTableModel(JTable jtable, Statistics stat, CategoryPlot cp) throws Exception {
    DefaultTableModel tableModel = new DefaultTableModel() {
        @Override
        public boolean isCellEditable(int row, int column) {
            //This causes all cells to be not editable
            return false;
        }
    };

    DefaultCategoryDataset myData = new DefaultCategoryDataset();

    tableModel.addColumn("Labelset id");
    tableModel.addColumn("IR values");

    //Labelsets frequency
    HashMap<LabelSet, Integer> labelsetsFrequency = stat.labelCombCount();
    labelsetStringByIR = new ArrayList<>(labelsetsFrequency.size());

    Set<LabelSet> keysets = labelsetsFrequency.keySet();

    Object[] row = new Object[2];

    int count = 1;
    double IR_labelset;
    int max = getMax(keysets, labelsetsFrequency);

    ArrayList<ImbalancedFeature> listImbalanced = new ArrayList();
    ImbalancedFeature temp;

    int value;

    for (LabelSet current : keysets) {
        value = labelsetsFrequency.get(current);
        IR_labelset = max / (value * 1.0);
        String temp1 = MetricUtils.truncateValue(IR_labelset, 4);
        IR_labelset = Double.parseDouble(temp1);

        temp = new ImbalancedFeature(current.toString(), value, IR_labelset);
        listImbalanced.add(temp);
    }

    labelsetsIRSorted = new ImbalancedFeature[listImbalanced.size()];
    labelsetsByIR = new double[listImbalanced.size()]; //stores IR per labelset

    String truncate;

    while (!listImbalanced.isEmpty()) {
        temp = Utils.getMin(listImbalanced);

        labelsetsIRSorted[count - 1] = temp;
        labelsetsByIR[count - 1] = temp.getIRIntraClass();

        row[0] = count;

        truncate = Double.toString(temp.getIRIntraClass());
        row[1] = MetricUtils.getValueFormatted(truncate, 3);

        tableModel.addRow(row);

        myData.setValue(temp.getIRIntraClass(), Integer.toString(count), "");
        labelsetStringByIR.add(temp.getName());

        count++;
        listImbalanced.remove(temp);
    }

    jtable.setModel(tableModel);
    jtable.setBounds(jtable.getBounds());

    //Resize columns
    TableColumnModel tcm = jtable.getColumnModel();

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

    //graph
    cp.setDataset(myData);

    //get mean
    double sum = 0;
    for (int i = 0; i < labelsetsIRSorted.length; i++) {
        sum += labelsetsIRSorted[i].getIRIntraClass();
    }
    sum = sum / labelsetsIRSorted.length;

    Marker start = new ValueMarker(sum);
    start.setPaint(Color.blue);
    start.setLabelFont(new Font("SansSerif", Font.BOLD, 12));
    start.setLabel("                        Mean: " + MetricUtils.truncateValue(sum, 4));
    cp.addRangeMarker(start);

    return jtable.getModel();
}

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

private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
    jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jTable2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

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

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

    setTitle(Lang.getLang("Forge_Window_Loading"));
    jButton1.setText(Lang.getLang("Forge_Button_Download"));
    jTabbedPane1.setTitleAt(0, Lang.getLang("Forge_TabledPanel_OlderVersion"));
    jTabbedPane1.setTitleAt(1, Lang.getLang("Forge_TabledPanel_NewerVersion"));

    DefaultTableModel newvm = (DefaultTableModel) jTable1.getModel();
    DefaultTableModel oldvm = (DefaultTableModel) jTable2.getModel();
    newvm.addColumn(Lang.getLang("Forge_Table_ForgeVer"));
    newvm.addColumn(Lang.getLang("Forge_Table_McVer"));
    newvm.addColumn(Lang.getLang("Forge_Table_RelTime"));
    oldvm.addColumn(Lang.getLang("Forge_Table_ForgeVer"));
    oldvm.addColumn(Lang.getLang("Forge_Table_McVer"));
    oldvm.addColumn(Lang.getLang("Forge_Table_RelTime"));
    jTable1.setSelectionMode(SINGLE_SELECTION);
    jTable2.setSelectionMode(SINGLE_SELECTION);

    JSONArray newv = null;//from  w  w  w . j  a v  a  2 s.co m
    try {
        newv = new JSONArray(downloadFile("http://bmclapi.bangbang93.com/forge/versionlist"));
    } catch (JSONException ex) {
        Logger.getLogger(ForgeCheck.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ForgeCheck.class.getName()).log(Level.SEVERE, null, ex);
    }
    JSONArray oldv = null;
    try {
        oldv = new JSONArray(downloadFile("http://bmclapi.bangbang93.com/forge/legacylist"));
    } catch (JSONException ex) {
        Logger.getLogger(ForgeCheck.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(ForgeCheck.class.getName()).log(Level.SEVERE, null, ex);
    }
    for (int i = 0; i < newv.length(); i++) {
        try {
            JSONObject jo = newv.getJSONObject(i);
            newvm.addRow(new Object[] { jo.get("ver"), jo.get("mcver"), jo.get("releasetime") });
        } catch (JSONException ex) {
            //    Logger.getogger(ForgeDownloader.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    for (int i = 0; i < oldv.length(); i++) {
        try {
            JSONObject jo = oldv.getJSONObject(i);
            oldvm.addRow(new Object[] { jo.get("ver"), jo.get("mcver"), jo.get("releasetime") });
        } catch (JSONException ex) {
            //    Logger.getogger(ForgeDownloader.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    setTitle(Lang.getLang("Forge_Title"));// TODO add your handling code here:        // TODO add your handling code here:
}