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:SparseTableModel.java

public static void main(String[] a) {

    String headers[] = { "A", "B" };
    TableModel model = new SparseTableModel(10, headers);
    JTable table = new JTable(model);
    model.setValueAt("1", 0, 0);
    model.setValueAt("2", 9, 0);
    model.setValueAt("3", 5, 1);
    model.setValueAt("4", 8, 1);

    JFrame frame = new JFrame("Fixed Column Table");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.add(new JScrollPane(table), BorderLayout.CENTER);
    frame.setSize(300, 150);//from w  w w  . j  a  va2  s .  c om
    frame.setVisible(true);
}

From source file:SparseTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Sparse Test");
    String headers[] = { "English", "Japanese" };
    TableModel model = new SparseTableModel(10, headers);
    JTable table = new JTable(model);

    model.setValueAt("one", 0, 0);
    model.setValueAt("ten", 9, 0);
    model.setValueAt("roku - \u516D", 5, 1);
    model.setValueAt("hachi - \u516B", 8, 1);

    JScrollPane scrollPane = new JScrollPane(table);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);/*  w w  w  . ja v a2 s  .  c o  m*/
    frame.setVisible(true);
}

From source file:org.datacleaner.widgets.result.AbstractCrosstabResultSwingRenderer.java

protected void horizontalHeaderCell(String category, TableModel tableModel, int row, int col) {
    if (row >= 0) {
        tableModel.setValueAt(getLabelText(category), row, col);
    }//  w  w w  . j  a v  a 2 s  . c om
}

From source file:org.datacleaner.widgets.result.AbstractCrosstabResultSwingRenderer.java

protected void verticalHeaderCell(String category, TableModel tableModel, int row, int col) {
    if (row >= 0) {
        tableModel.setValueAt(getLabelText(category), row, col);
    }/*w w  w  . j ava2s  . c o m*/
}

From source file:at.tuwien.ifs.feature.evaluation.SimilarityRetrievalGUI.java

private JButton initButtonLoadClassInfo() {
    buttonLoadClassInfo = new JButton("Load class info file");
    buttonLoadClassInfo.setEnabled(false);
    buttonLoadClassInfo.addActionListener(new ActionListener() {
        @Override// ww w  .j  a  va2 s  .c  om
        public void actionPerformed(ActionEvent e) {
            fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            fileChooser.setFileFilter(new ExtensionFileFilterSwing(new String[] { "cls", "txt" }));
            if (fileChooser.getSelectedFile() != null) { // reusing the dialog
                fileChooser.setSelectedFile(null);
            }

            // TODO: remove
            fileChooser
                    .setSelectedFile(new File("/data/music/ISMIRgenre/filelist_ISMIRgenre_mp3_wclasses.txt"));

            int returnVal = fileChooser.showDialog(SimilarityRetrievalGUI.this, "Open class information file");
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                try {
                    SOMLibClassInformation clsInfo = new SOMLibClassInformation(
                            fileChooser.getSelectedFile().getAbsolutePath());
                    // Sanity check if all the inputs are in the class info file
                    String[] labels = inputData.get(0).getLabels();
                    ArrayList<String> missingLabels = new ArrayList<String>();
                    for (String label : labels) {
                        if (!clsInfo.hasClassAssignmentForName(label)) {
                            missingLabels.add(label);
                        }
                    }
                    int answer = JOptionPane.YES_OPTION;
                    if (missingLabels.size() > 0) {
                        System.out.println(missingLabels);
                        String missing = StringUtils.toString(missingLabels.toArray(), 5);
                        answer = JOptionPane.showConfirmDialog(SimilarityRetrievalGUI.this,
                                "Class information file '" + fileChooser.getSelectedFile().getAbsolutePath()
                                        + "' is missing the class assignment for " + missingLabels.size()
                                        + " vectors\n    " + missing + "\nContinue loading?",
                                "Missing class assignment", JOptionPane.YES_NO_OPTION);
                    }
                    if (missingLabels.size() == 0 || answer == JOptionPane.YES_OPTION) {
                        classInfo = clsInfo;
                        TableModel model = databaseDetailsTable.getModel();
                        for (int i = 0; i < labels.length; i++) {
                            model.setValueAt(clsInfo.getClassName(labels[i]), i, 2);
                        }
                        resizeDatabaseDetailsTableColumns();
                    }
                } catch (SOMToolboxException e1) {
                    JOptionPane.showMessageDialog(SimilarityRetrievalGUI.this,
                            "Error loading class information file: " + e1.getMessage() + ". Aborting", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    e1.printStackTrace();
                }
            }
        }
    });
    return buttonLoadClassInfo;
}

From source file:org.datacleaner.widgets.result.ValueDistributionResultSwingRendererGroupDelegate.java

private void drillToOverview(final ValueCountingAnalyzerResult result) {
    final TableModel model = new DefaultTableModel(new String[] { "Value", LabelUtils.COUNT_LABEL },
            _valueCounts.size());/*from  w w w  .  j av  a 2s  . c o m*/

    int i = 0;
    for (final ValueFrequency valueFreq : _valueCounts) {
        final String key = valueFreq.getName();
        final int count = valueFreq.getCount();
        model.setValueAt(key, i, 0);

        if (valueFreq.isComposite() && valueFreq.getChildren() != null && !valueFreq.getChildren().isEmpty()) {
            DCPanel panel = new DCPanel();
            panel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));

            JLabel label = new JLabel(count + "");
            JButton button = WidgetFactory.createSmallButton(IconUtils.ACTION_DRILL_TO_DETAIL);
            button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    drillToGroup(result, valueFreq, true);
                }
            });

            panel.add(label);
            panel.add(Box.createHorizontalStrut(4));
            panel.add(button);

            model.setValueAt(panel, i, 1);
        } else {
            setCountValue(result, model, i, valueFreq);
        }
        i++;
    }
    _table.setModel(model);
    _backButton.setVisible(false);
    _rightPanel.updateUI();
}

From source file:org.eobjects.datacleaner.widgets.result.ValueDistributionResultSwingRendererGroupDelegate.java

private void drillToOverview(final ValueCountingAnalyzerResult result) {
    final TableModel model = new DefaultTableModel(new String[] { "Value", LabelUtils.COUNT_LABEL },
            _valueCounts.size());/*w w w  . j a v  a 2s.c  o  m*/

    int i = 0;
    for (final ValueFrequency valueFreq : _valueCounts) {
        final String key = valueFreq.getName();
        final int count = valueFreq.getCount();
        model.setValueAt(key, i, 0);

        if (valueFreq.isComposite() && valueFreq.getChildren() != null && !valueFreq.getChildren().isEmpty()) {
            DCPanel panel = new DCPanel();
            panel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));

            JLabel label = new JLabel(count + "");
            JButton button = WidgetFactory.createSmallButton("images/actions/drill-to-detail.png");
            button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    drillToGroup(result, valueFreq, true);
                }
            });

            panel.add(label);
            panel.add(Box.createHorizontalStrut(4));
            panel.add(button);

            model.setValueAt(panel, i, 1);
        } else {
            setCountValue(result, model, i, valueFreq);
        }
        i++;
    }
    _table.setModel(model);
    _backButton.setVisible(false);
}

From source file:org.datacleaner.widgets.result.ValueDistributionResultSwingRendererGroupDelegate.java

private void drillToGroup(ValueCountingAnalyzerResult result, ValueFrequency valueFrequency,
        boolean showBackButton) {
    final List<ValueFrequency> children = valueFrequency.getChildren();
    final TableModel model = new DefaultTableModel(
            new String[] { valueFrequency.getName() + " value", LabelUtils.COUNT_LABEL }, children.size());

    final Iterator<ValueFrequency> valueCounts = children.iterator();
    int i = 0;/*w  ww.  ja  va  2 s .  co  m*/
    while (valueCounts.hasNext()) {
        ValueFrequency vc = valueCounts.next();
        model.setValueAt(LabelUtils.getLabel(vc.getValue()), i, 0);
        setCountValue(result, model, i, vc);
        i++;
    }
    _table.setModel(model);
    _backButton.setVisible(showBackButton);
    _rightPanel.updateUI();
}

From source file:org.eobjects.datacleaner.widgets.result.ValueDistributionResultSwingRendererGroupDelegate.java

private void drillToGroup(ValueCountingAnalyzerResult result, ValueFrequency valueFrequency,
        boolean showBackButton) {
    final List<ValueFrequency> children = valueFrequency.getChildren();
    final TableModel model = new DefaultTableModel(
            new String[] { valueFrequency.getName() + " value", LabelUtils.COUNT_LABEL }, children.size());

    final Iterator<ValueFrequency> valueCounts = children.iterator();
    int i = 0;/*from   w w  w  .j  a  va2 s  .c  o m*/
    while (valueCounts.hasNext()) {
        ValueFrequency vc = valueCounts.next();
        model.setValueAt(LabelUtils.getLabel(vc.getValue()), i, 0);
        setCountValue(result, model, i, vc);
        i++;
    }
    _table.setModel(model);
    _backButton.setVisible(showBackButton);
}