Example usage for javax.swing JTable getValueAt

List of usage examples for javax.swing JTable getValueAt

Introduction

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

Prototype

public Object getValueAt(int row, int column) 

Source Link

Document

Returns the cell value at row and column.

Usage

From source file:ExtendedDnDDemo.java

protected String exportString(JComponent c) {
    JTable table = (JTable) c;
    rows = table.getSelectedRows();//w w  w. j  ava 2  s  .  c o m
    int colCount = table.getColumnCount();

    StringBuffer buff = new StringBuffer();

    for (int i = 0; i < rows.length; i++) {
        for (int j = 0; j < colCount; j++) {
            Object val = table.getValueAt(rows[i], j);
            buff.append(val == null ? "" : val.toString());
            if (j != colCount - 1) {
                buff.append(",");
            }
        }
        if (i != rows.length - 1) {
            buff.append("\n");
        }
    }

    return buff.toString();
}

From source file:com.smanempat.controller.ControllerClassification.java

private double[][] getDataValue(int rowCountData, JTable tablePreview) {
    double[][] returnValue = new double[rowCountData][3];
    int transMinat = 0;
    for (int i = 0; i < rowCountData; i++) {
        if (tablePreview.getValueAt(i, 8).equals("IPA")) {
            transMinat = 1;//from   w  w w .jav  a 2s .c o m
        } else if (tablePreview.getValueAt(i, 8).equals("IPS")) {
            transMinat = 0;
        }
        returnValue[i][0] = Double.parseDouble(tablePreview.getValueAt(i, 3).toString()) / 4;
        returnValue[i][1] = (Double.parseDouble(tablePreview.getValueAt(i, 4).toString())
                + Double.parseDouble(tablePreview.getValueAt(i, 5).toString())
                + Double.parseDouble(tablePreview.getValueAt(i, 6).toString())
                + Double.parseDouble(tablePreview.getValueAt(i, 7).toString())) / 4;
        returnValue[i][2] = transMinat;
    }
    return returnValue;
}

From source file:cz.lidinsky.editor.TableCellEditor.java

/**
 *  Returnes appropriate component based on the value datatype.
 *//*w w w. j  a v  a  2 s.c o  m*/
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
        int column) {
    KeyValueTableModel tableModel = (KeyValueTableModel) table.getModel();
    valueClass = tableModel.getCellClass(row, column);
    if (Color.class.isAssignableFrom(valueClass)) {
        type = COLOR;
        currentColor = (Color) value;
        return button;
    } else if (selected instanceof Changer && ((String) table.getValueAt(row, 0)).equals("Property")) {
        type = COMBO;
        // get appropriate object
        Changer changer = (Changer) selected;
        // get parent of the object
        Object parent = changer.getParent();
        // get list of appropriate methods
        fillComboBox(parent, changer.getPropertyClass());
        // create component
        // return it
        return comboBox;
    } else if (Method.class.isAssignableFrom(valueClass) && selected instanceof Changer) {
        type = COMBO;
        // get appropriate object
        Changer changer = (Changer) selected;
        // get parent of the object
        Object parent = changer.getParent();
        // get list of appropriate methods
        fillComboBox(parent, changer.getPropertyClass());
        // create component
        // return it
        return comboBox;
    } else if (valueClass == boolean.class) {
        type = CHECK;
        checkBox.setSelected(((Boolean) value).booleanValue());
        return checkBox;
    } else {
        type = TEXT;
        if (value == null)
            value = "";
        textField.setText(value.toString());
        return textField;
    }
}

From source file:es.emergya.ui.plugins.admin.AdminLayers.java

private FiltrarAction getFiltrarAction() {
    return layers.new FiltrarAction() {

        private static final long serialVersionUID = -8261691115496760409L;

        @Override/*from   w  w w .  j  av  a  2s.c  om*/
        protected void applyFilter(JTable filters) {
            final CapaInformacion example = new CapaInformacion();
            Object valueAt = filters.getValueAt(0, 1);
            if (valueAt != null && StringUtils.isNumeric(valueAt.toString())
                    && valueAt.toString().length() > 0) {
                example.setOrden(new Integer(valueAt.toString()));

            }
            valueAt = filters.getValueAt(0, 2);
            if (valueAt != null && valueAt.toString().trim().length() > 0) {
                example.setNombre(valueAt.toString());

            }
            valueAt = filters.getValueAt(0, 3);
            if (valueAt != null && valueAt.toString().trim().length() > 0) {
                example.setUrl(valueAt.toString());

            }
            valueAt = filters.getValueAt(0, 4);
            if (valueAt != null && valueAt.toString().trim().length() > 0) {
                example.setOpcional(valueAt.equals("Opcional"));

            }
            valueAt = filters.getValueAt(0, 5);
            if (valueAt != null && valueAt.toString().trim().length() > 0) {
                example.setHabilitada(valueAt.equals("Habilitada"));

            }
            layers.setTableData(getAll(example));
        }
    };
}

From source file:com.vgi.mafscaling.Rescale.java

private boolean getMafTableData(JTable mafTable, ArrayList<Double> voltArray, ArrayList<Double> gsArray) {
    String value;//from   w  w w  .  j  a  va 2s.c  o  m
    for (int i = 0; i < mafTable.getColumnCount(); ++i) {
        for (int j = 0; j < mafTable.getRowCount(); ++j) {
            value = mafTable.getValueAt(j, i).toString();
            if (value.isEmpty())
                return true;
            if (!Utils.validateDouble(value, j, i, mafTable.getName()))
                return false;
        }
        voltArray.add(Double.parseDouble(mafTable.getValueAt(0, i).toString()));
        gsArray.add(Double.parseDouble(mafTable.getValueAt(1, i).toString()));
    }
    if (voltArray.size() != gsArray.size()) {
        JOptionPane.showMessageDialog(null,
                "Data sets (volt/gs) in  " + mafTable.getName() + " have different length", "Invalid Data",
                JOptionPane.ERROR_MESSAGE);
        return false;
    }
    return true;
}

From source file:edu.ucla.stat.SOCR.chart.demo.NormalDistributionDemo.java

/**
 * use demo data to reset JTable and redraw the graph
 *//*from   w  w  w  .j a  va  2s  .c  o m*/
public void resetExample() {

    XYDataset dataset = createDataset(true);

    JFreeChart chart = createChart(dataset);
    chartPanel = new ChartPanel(chart, false);
    setChart();

    hasExample = true;
    convertor.normalDataset2Table(mean, stdDev);
    JTable tempDataTable = convertor.getTable();
    resetTableRows(tempDataTable.getRowCount() + 1);
    resetTableColumns(tempDataTable.getColumnCount() + 2);

    for (int i = 0; i < tempDataTable.getColumnCount(); i++) {
        columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i));
        //  System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i));
    }

    columnModel = dataTable.getColumnModel();
    dataTable.setTableHeader(new EditableHeader(columnModel));

    for (int i = 0; i < tempDataTable.getRowCount(); i++)
        for (int j = 0; j < tempDataTable.getColumnCount(); j++) {
            dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j);
        }
    dataPanel.removeAll();
    dataPanel.add(new JScrollPane(dataTable));
    dataTable.setGridColor(Color.gray);
    dataTable.setShowGrid(true);
    dataTable.doLayout();
    // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003
    try {
        dataTable.setDragEnabled(true);
    } catch (Exception e) {
    }

    dataPanel.validate();

    // do the mapping

    int columnCount = dataTable.getColumnCount();
    for (int i = 0; i < columnCount / 2 - 1; i++) {
        addButtonIndependent();
        addButtonDependent();
    }
    //updateStatus(url);
}

From source file:edu.ucla.stat.SOCR.chart.demo.IndexChart.java

public void resetExample() {
    //  System.out.println("resetExample get called");
    XYDataset dataset = createDataset1(true);

    JFreeChart chart = createChart(dataset);
    chartPanel = new ChartPanel(chart, false);
    setChart();//from  w  w w  .  j a  v  a2  s. c om

    hasExample = true;

    //  System.out.println("row_count="+row_count);
    //  System.out.println("raw+x="+raw_x[0]);
    convertor.Y2Table(raw_x, row_count);
    //convertor.dataset2Table(dataset);            
    JTable tempDataTable = convertor.getTable();

    resetTableRows(tempDataTable.getRowCount() + 1);
    resetTableColumns(tempDataTable.getColumnCount());

    for (int i = 0; i < tempDataTable.getColumnCount(); i++) {
        columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i));
        //  System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i));
    }

    columnModel = dataTable.getColumnModel();
    dataTable.setTableHeader(new EditableHeader(columnModel));

    for (int i = 0; i < tempDataTable.getRowCount(); i++)
        for (int j = 0; j < tempDataTable.getColumnCount(); j++) {
            dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j);
        }

    dataPanel.removeAll();
    dataPanel.add(new JScrollPane(dataTable));
    dataTable.setGridColor(Color.gray);
    dataTable.setShowGrid(true);
    dataTable.doLayout();
    // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003
    try {
        dataTable.setDragEnabled(true);
    } catch (Exception e) {
    }

    dataPanel.validate();

    // do the mapping
    addButtonIndependent();//Y
    updateStatus(url);
}

From source file:com.smanempat.view.ViewClassification.java

private double[][] getDataValue(int rowCountData, JTable tablePreview) {
    double[][] returnValue = new double[rowCountData][3];
    double transMinat = 0;
    for (int i = 0; i < rowCountData; i++) {
        if (tablePreview.getValueAt(i, 8).equals("IPA")) {
            transMinat = 1.0;/*from w w  w . j  a  v a2s  .  com*/
        } else if (tablePreview.getValueAt(i, 8).equals("IPS")) {
            transMinat = 0.0;
        }
        returnValue[i][0] = Double.parseDouble(tablePreview.getValueAt(i, 3).toString()) / 4;
        returnValue[i][1] = (Double.parseDouble(tablePreview.getValueAt(i, 4).toString())
                + Double.parseDouble(tablePreview.getValueAt(i, 5).toString())
                + Double.parseDouble(tablePreview.getValueAt(i, 6).toString())
                + Double.parseDouble(tablePreview.getValueAt(i, 7).toString())) / 4;
        returnValue[i][2] = transMinat;
    }
    return returnValue;
}

From source file:edu.ucla.stat.SOCR.chart.SuperCategoryChart_Stat.java

/**
 * reset dataTable to default (demo data), and refesh chart
 *///  w  w w. jav a 2  s  .  c o m
public void resetExample() {

    dataset = (DefaultStatisticalCategoryDataset) createDataset(true);

    JFreeChart chart = createChart(dataset);
    chartPanel = new ChartPanel(chart, false);
    //      setSummary(dataset);
    setChart();

    hasExample = true;
    convertor.dataset2Table(dataset);
    JTable tempDataTable = convertor.getTable();
    resetTableRows(tempDataTable.getRowCount() + 1);
    resetTableColumns(tempDataTable.getColumnCount() + 1);

    for (int i = 0; i < tempDataTable.getColumnCount(); i++) {
        columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i));
    }
    columnModel = dataTable.getColumnModel();
    dataTable.setTableHeader(new EditableHeader(columnModel));

    for (int i = 0; i < tempDataTable.getRowCount(); i++)
        for (int j = 0; j < tempDataTable.getColumnCount(); j++) {
            dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j);
        }
    dataPanel.removeAll();
    dataPanel.add(new JScrollPane(dataTable));
    dataTable.setGridColor(Color.gray);
    dataTable.setShowGrid(true);
    dataTable.doLayout();
    // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003
    try {
        dataTable.setDragEnabled(true);
    } catch (Exception e) {
    }

    dataPanel.validate();

    // do the mapping
    setMapping();
    updateStatus(url);
}

From source file:edu.ucla.stat.SOCR.chart.demo.HistogramChartDemo3.java

/**
 * reset dataTable to default (demo data), and refesh chart
 *///from w w w  .  j  a  v a  2s . c  o m
public void resetExample() {
    isDemo = true;
    IntervalXYDataset dataset = createDataset(isDemo);

    JFreeChart chart = createChart(dataset);
    chartPanel = new ChartPanel(chart, false);
    setChart();

    hasExample = true;

    convertor.dataset2Table((TimeSeriesCollection) dataset);
    JTable tempDataTable = convertor.getTable();
    int seriesCount = tempDataTable.getColumnCount() / 2;
    resetTableRows(tempDataTable.getRowCount() + 1);
    resetTableColumns(seriesCount * 2);

    for (int i = 0; i < seriesCount * 2; i++) {
        columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i));
        //  System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i));
    }

    columnModel = dataTable.getColumnModel();
    dataTable.setTableHeader(new EditableHeader(columnModel));

    for (int i = 0; i < tempDataTable.getRowCount(); i++)
        for (int j = 0; j < tempDataTable.getColumnCount(); j++) {
            dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j);
        }
    dataPanel.removeAll();
    dataPanel.add(new JScrollPane(dataTable));
    dataTable.setGridColor(Color.gray);
    dataTable.setShowGrid(true);

    // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003
    try {
        dataTable.setDragEnabled(true);
    } catch (Exception e) {
    }

    dataPanel.validate();

    // do the mapping
    for (int i = 0; i < seriesCount; i++) {
        addButtonIndependent();
        addButtonDependent();
    }

    updateStatus(url);
}