List of usage examples for javax.swing JTable setBounds
public void setBounds(Rectangle r)
From source file:app.RunApp.java
/** * Set frequency of labelsets/*from ww w.j a v a2s .com*/ * * @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/*from ww w.j a va2s.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(); }