Example usage for javax.swing.table DefaultTableModel DefaultTableModel

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

Introduction

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

Prototype

public DefaultTableModel() 

Source Link

Document

Constructs a default DefaultTableModel which is a table of zero columns and zero rows.

Usage

From source file:app.RunApp.java

/**
 * Generate TableModel for label frequency
 * //from  w  ww . ja v  a 2 s  .  co 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 attributes//from   w  w  w  .j  a  v  a2  s. c  om
 * 
 * @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 Box Diagrams
 * /*from w  w w. j  a  v a 2  s.  co  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 IR intra class
 * /*from ww  w. j av a2s  . 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
 * /*  w  ww .j  a  v  a  2  s .c  om*/
 * @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 imbalanced data
 * //  ww w .  ja v a 2  s.  c o  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();
}

From source file:app.RunApp.java

/**
 * Generates TableModel for labels per example values
 * /*from ww w .  j a v a  2s  .  c  o 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 frequency values
 * //from   w  w w .  j a  v a2s. 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:src.gui.ItSIMPLE.java

/**
 * This method initializes planDatabasePanel
 *
 * @return javax.swing.JPanel/* w  ww .ja v a2 s.co  m*/
 */
private JPanel getPlanDatabasePanel() {
    //TODO:

    if (planDatabasePanel == null) {
        planDatabasePanel = new JPanel(new BorderLayout());
        //planDatabasePanel.add(getPlanDatabaseToolBar(), BorderLayout.NORTH);

        //top panel (toolbar + filter filed
        JPanel topPanel = new JPanel(new BorderLayout());
        topPanel.add(getPlanDatabaseToolBar(), BorderLayout.NORTH);

        planFilterPanel = new JPanel(new BorderLayout());
        planfilterTextPane = new JTextPane();
        planfilterTextPane.setBackground(Color.WHITE);
        //planfilterTextPane.setPreferredSize(new Dimension(250,100));
        planfilterTextPane.setFont(new Font("Monospaced", Font.PLAIN, 14));
        planfilterTextPane.setToolTipText("<html>Please use only the following column names:<br>"
                + "id<br>project<br>domain<br>plannername<br>plannerversion<br>nactions<br>quality</html>");
        JScrollPane scrollText = new JScrollPane();
        scrollText.setViewportView(planfilterTextPane);
        JLabel descriptionLabel = new JLabel("<html>Filter: </html>");
        planFilterPanel.add(descriptionLabel, BorderLayout.NORTH);
        planFilterPanel.add(scrollText, BorderLayout.CENTER);
        planFilterPanel.setPreferredSize(new Dimension(250, 90));
        planFilterPanel.setVisible(false);
        topPanel.add(planFilterPanel, BorderLayout.CENTER);

        planDatabasePanel.add(topPanel, BorderLayout.NORTH);

        resultPlanTableModel = new DefaultTableModel();
        resultPlanTable = new JTable(resultPlanTableModel) {
            @Override
            public boolean isCellEditable(int row, int column) {
                //avoid columns that can not edit (leaving only the evaluation to edit)
                return false;
                //if(column < 4){
                //    return false;
                //}else{
                //    return true;
                //}
            }
        };

        //resultPlanTableModel.addTableModelListener(this);

        //allows a single row selection
        resultPlanTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        resultPlanTableModel.addColumn("id");
        //resultPlanTableModel.addColumn("#");
        resultPlanTableModel.addColumn("project");
        resultPlanTableModel.addColumn("domain");
        resultPlanTableModel.addColumn("problem");
        //resultPlanTableModel.addColumn("planner");
        resultPlanTableModel.addColumn("plannername");
        resultPlanTableModel.addColumn("nactions");
        //resultPlanTableModel.addColumn("# actions");
        resultPlanTableModel.addColumn("cost");
        resultPlanTableModel.addColumn("quality");

        //resultPlanTable.getColumnModel().getColumn(0).setMinWidth(25);
        //resultPlanTable.getColumnModel().getColumn(0).setMaxWidth(50);
        //resultPlanTable.getColumnModel().getColumn(1).setMinWidth(30);
        //resultPlanTable.getColumnModel().getColumn(1).setMaxWidth(40);
        //resultPlanTable.getColumnModel().getColumn(2).setMinWidth(150);
        //resultPlanTable.getColumnModel().getColumn(2).setMaxWidth(300);
        //resultPlanTable.getColumnModel().getColumn(3).setMinWidth(150);
        //resultPlanTable.getColumnModel().getColumn(3).setMaxWidth(300);
        //resultPlanTable.getColumnModel().getColumn(4).setMinWidth(150);
        //resultPlanTable.getColumnModel().getColumn(4).setMaxWidth(300);
        //resultPlanTable.getColumnModel().getColumn(6).setMinWidth(55);
        //resultPlanTable.getColumnModel().getColumn(6).setMaxWidth(75);
        //resultPlanTable.getColumnModel().getColumn(7).setMinWidth(50);
        //resultPlanTable.getColumnModel().getColumn(7).setMaxWidth(70);

        resultPlanTable.getColumnModel().getColumn(0).setMinWidth(25);
        resultPlanTable.getColumnModel().getColumn(0).setMaxWidth(50);
        resultPlanTable.getColumnModel().getColumn(1).setMinWidth(150);
        resultPlanTable.getColumnModel().getColumn(1).setMaxWidth(300);
        resultPlanTable.getColumnModel().getColumn(2).setMinWidth(150);
        resultPlanTable.getColumnModel().getColumn(2).setMaxWidth(300);
        resultPlanTable.getColumnModel().getColumn(3).setMinWidth(150);
        resultPlanTable.getColumnModel().getColumn(3).setMaxWidth(300);
        resultPlanTable.getColumnModel().getColumn(5).setMinWidth(55);
        resultPlanTable.getColumnModel().getColumn(5).setMaxWidth(75);
        resultPlanTable.getColumnModel().getColumn(6).setMinWidth(50);
        resultPlanTable.getColumnModel().getColumn(6).setMaxWidth(70);
        resultPlanTable.getColumnModel().getColumn(7).setMinWidth(50);
        resultPlanTable.getColumnModel().getColumn(7).setMaxWidth(70);

        //do not show the id (for now)
        //resultPlanTable.removeColumn(resultPlanTable.getColumnModel().getColumn(0));

        JScrollPane scrollPlanResultPane = new JScrollPane(resultPlanTable);

        planDatabasePanel.add(scrollPlanResultPane, BorderLayout.CENTER);
        //planDatabasePanel.add(new JPanel(), BorderLayout.CENTER);
    }

    return planDatabasePanel;
}

From source file:src.gui.ItSIMPLE.java

/**
 * This method initializes rationaleDatabasePanel
 *
 * @return javax.swing.JPanel/*from   w w  w.ja  v a 2  s  .co m*/
 */
private JPanel getRationaleDatabasePanel() {
    //TODO:

    if (rationaleDatabasePanel == null) {
        rationaleDatabasePanel = new JPanel(new BorderLayout());
        rationaleDatabasePanel.add(getRationaleDatabaseToolBar(), BorderLayout.NORTH);

        resultRationaleTableModel = new DefaultTableModel();
        resultRationaleTable = new JTable(resultRationaleTableModel) {
            @Override
            public boolean isCellEditable(int row, int column) {
                //avoid columns that can not edit (leaving only the evaluation to edit)
                return false;
                //if(column < 4){
                //    return false;
                //}else{
                //    return true;
                //}
            }
        };

        //resultRationaleTableModel.addTableModelListener(this);

        //allows a single row selection
        resultRationaleTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        resultRationaleTableModel.addColumn("id");
        //resultRationaleTableModel.addColumn("#");
        resultRationaleTableModel.addColumn("name");
        resultRationaleTableModel.addColumn("range");
        resultRationaleTableModel.addColumn("project");
        resultRationaleTableModel.addColumn("domain");
        resultRationaleTableModel.addColumn("problem");
        resultRationaleTableModel.addColumn("planid");
        resultRationaleTableModel.addColumn("impact");
        //resultRationaleTableModel.addColumn("quality");

        /*
         resultRationaleTable.getColumnModel().getColumn(0).setMinWidth(25);
        resultRationaleTable.getColumnModel().getColumn(0).setMaxWidth(50);
        resultRationaleTable.getColumnModel().getColumn(1).setMaxWidth(25);
        //resultRationaleTable.getColumnModel().getColumn(2).setMinWidth(200);
        //resultRationaleTable.getColumnModel().getColumn(2).setMaxWidth(500);
        resultRationaleTable.getColumnModel().getColumn(3).setMinWidth(100);
        resultRationaleTable.getColumnModel().getColumn(3).setMaxWidth(400);
        resultRationaleTable.getColumnModel().getColumn(4).setMinWidth(50);
        resultRationaleTable.getColumnModel().getColumn(4).setMaxWidth(300);
        resultRationaleTable.getColumnModel().getColumn(5).setMinWidth(50);
        resultRationaleTable.getColumnModel().getColumn(5).setMaxWidth(300);
        resultRationaleTable.getColumnModel().getColumn(6).setMinWidth(50);
        resultRationaleTable.getColumnModel().getColumn(6).setMaxWidth(300);
        resultRationaleTable.getColumnModel().getColumn(7).setMinWidth(40);
        resultRationaleTable.getColumnModel().getColumn(7).setMaxWidth(55);
         */

        resultRationaleTable.getColumnModel().getColumn(0).setMinWidth(25);
        resultRationaleTable.getColumnModel().getColumn(0).setMaxWidth(50);
        //resultRationaleTable.getColumnModel().getColumn(1).setMinWidth(200);
        //resultRationaleTable.getColumnModel().getColumn(1).setMaxWidth(500);
        resultRationaleTable.getColumnModel().getColumn(2).setMinWidth(100);
        resultRationaleTable.getColumnModel().getColumn(2).setMaxWidth(400);
        resultRationaleTable.getColumnModel().getColumn(3).setMinWidth(50);
        resultRationaleTable.getColumnModel().getColumn(3).setMaxWidth(300);
        resultRationaleTable.getColumnModel().getColumn(4).setMinWidth(50);
        resultRationaleTable.getColumnModel().getColumn(4).setMaxWidth(300);
        resultRationaleTable.getColumnModel().getColumn(5).setMinWidth(50);
        resultRationaleTable.getColumnModel().getColumn(5).setMaxWidth(300);
        resultRationaleTable.getColumnModel().getColumn(6).setMinWidth(40);
        resultRationaleTable.getColumnModel().getColumn(6).setMaxWidth(55);
        resultRationaleTable.getColumnModel().getColumn(7).setMinWidth(60);
        resultRationaleTable.getColumnModel().getColumn(7).setMaxWidth(70);

        //do not show the id (for now)
        //resultRationaleTable.removeColumn(resultPlanTable.getColumnModel().getColumn(0));

        JScrollPane scrollPlanResultPane = new JScrollPane(resultRationaleTable);

        rationaleDatabasePanel.add(scrollPlanResultPane, BorderLayout.CENTER);
        //rationaleDatabasePanel.add(new JPanel(), BorderLayout.CENTER);
    }

    return rationaleDatabasePanel;
}