Example usage for javax.swing JTable getColumnCount

List of usage examples for javax.swing JTable getColumnCount

Introduction

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

Prototype

@BeanProperty(bound = false)
public int getColumnCount() 

Source Link

Document

Returns the number of columns in the column model.

Usage

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.SingleCellStatisticsController.java

/**
 * Show p-values in correspondent table//from  w  ww .j av a2 s. co m
 *
 * @param analysisGroup
 */
private void showPValues(SingleCellAnalysisGroup singleCellAnalysisGroup, boolean isAdjusted) {
    String statisticalTestName = singleCellAnalysisController.getAnalysisPanel().getStatTestComboBox()
            .getSelectedItem().toString();
    SingleCellPValuesTableModel pValuesTableModel = new SingleCellPValuesTableModel(singleCellAnalysisGroup,
            isAdjusted);
    JTable pValuesTable = singleCellAnalysisController.getAnalysisPanel().getComparisonTable();
    pValuesTable.setModel(pValuesTableModel);
    Double selectedSignLevel = (Double) singleCellAnalysisController.getAnalysisPanel().getSignLevelComboBox()
            .getSelectedItem();
    // detect significances with selected alpha level
    singleCellStatisticsAnalyzer.detectSignificance(singleCellAnalysisGroup, statisticalTestName,
            selectedSignLevel, isAdjusted);
    boolean[][] significances = singleCellAnalysisGroup.getSignificances();
    for (int i = 1; i < pValuesTable.getColumnCount(); i++) {
        pValuesTable.getColumnModel().getColumn(i)
                .setCellRenderer(new PValuesTableRenderer(new DecimalFormat("#.####"), significances));
    }
    pValuesTable.getTableHeader().setDefaultRenderer(new TableHeaderRenderer(SwingConstants.RIGHT));
}

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

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

    isDemo = true;
    dataset = createDataset(true);

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

    hasExample = true;
    if (!ThreeDPie)
        convertor.dataset2Table(dataset, pulloutFlag);
    else
        convertor.dataset2Table(dataset);

    JTable tempDataTable = convertor.getTable();
    // resetTable();
    resetTableRows(tempDataTable.getRowCount() + 1);
    resetTableColumns(tempDataTable.getColumnCount() + 1);

    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);
            //System.out.println("setting dataTable :"+tempDataTable.getValueAt(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.HistogramChartDemo5.java

/**
 * reset dataTable to default (demo data), and refesh chart
 *//* www.  j a v a2s  . c  om*/
public void resetExample() {
    isDemo = true;
    IntervalXYDataset dataset = createDataset(isDemo);

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

    hasExample = true;

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

    //correct the column name
    //  columnModel.getColumn(0).setHeaderValue("Data");
    columnModel.getColumn(0).setHeaderValue("Frequency");

    /*   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();

    setMapping();

    updateStatus(url);
}

From source file:ExtendedDnDDemo.java

protected void importString(JComponent c, String str) {
    JTable target = (JTable) c;
    DefaultTableModel model = (DefaultTableModel) target.getModel();
    int index = target.getSelectedRow();

    //Prevent the user from dropping data back on itself.
    //For example, if the user is moving rows #4,#5,#6 and #7 and
    //attempts to insert the rows after row #5, this would
    //be problematic when removing the original rows.
    //So this is not allowed.
    if (rows != null && index >= rows[0] - 1 && index <= rows[rows.length - 1]) {
        rows = null;//from   www .j  a  va2 s  .co  m
        return;
    }

    int max = model.getRowCount();
    if (index < 0) {
        index = max;
    } else {
        index++;
        if (index > max) {
            index = max;
        }
    }
    addIndex = index;
    String[] values = str.split("\n");
    addCount = values.length;
    int colCount = target.getColumnCount();
    for (int i = 0; i < values.length && i < colCount; i++) {
        model.insertRow(index++, values[i].split(","));
    }
}

From source file:com.puzzle.gui.MainFrame.java

/**
 * table?//from w ww  . j a v a 2 s.  co  m
 *
 * @param table
 */
public static void makeJtableFace(javax.swing.JTable table) {

    try {
        DefaultTableCellRenderer tcr = new DefaultTableCellRenderer() {
            public java.awt.Component getTableCellRendererComponent(javax.swing.JTable table, Object value,
                    boolean isSelected, boolean hasFocus, int row, int column) {
                if (row % 2 == 0) {
                    setBackground(java.awt.Color.white); //
                } else if (row % 2 == 1) {
                    setBackground(new java.awt.Color(206, 231, 255)); //?
                }
                return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            }
        };
        for (int i = 0; i < table.getColumnCount(); i++) {
            table.getColumn(table.getColumnName(i)).setCellRenderer(tcr);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

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

private void clearAfrDataTable(JTable table) {
    while (AfrTableRowCount < table.getRowCount())
        Utils.removeRow(AfrTableRowCount, table);
    while (AfrTableColumnCount < table.getColumnCount())
        Utils.removeColumn(AfrTableColumnCount, table);
    Utils.clearTable(table);//from   ww  w.  j a va  2 s  . com
}

From source file:edu.ku.brc.specify.tasks.subpane.ESResultsTablePanel.java

/**
 * @param table/*from w w  w.  j a  v a 2  s. c o m*/
 * @param model
 */
protected void autoResizeColWidth(final JTable table, final DefaultTableModel model) {
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setModel(model);

    int margin = 5;

    DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();

    int preferredWidthTotal = 0;
    int renderedWidthTotal = 0;
    int[] colWidths = new int[table.getColumnCount()];
    int[] strWidths = new int[table.getColumnCount()];
    for (int i = 0; i < table.getColumnCount(); i++) {
        int vColIndex = i;
        TableColumn col = colModel.getColumn(vColIndex);
        int width = 0;

        TableCellRenderer headerRenderer = col.getHeaderRenderer();
        if (headerRenderer instanceof JLabel) {
            ((JLabel) headerRenderer).setHorizontalAlignment(SwingConstants.CENTER);
        }

        // Get width of column header
        TableCellRenderer renderer = col.getCellRenderer();
        if (renderer == null) {
            renderer = table.getTableHeader().getDefaultRenderer();
        }

        Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0,
                0);

        width = comp.getPreferredSize().width;

        // Get maximum width of column data
        int strWidth = 0;
        boolean isString = model.getColumnClass(i) == String.class;
        for (int r = 0; r < table.getRowCount(); r++) {
            renderer = table.getCellRenderer(r, vColIndex);
            Object objVal = table.getValueAt(r, vColIndex);
            if (isString && objVal != null) {
                strWidth = Math.max(strWidth, ((String) objVal).length());
            }
            comp = renderer.getTableCellRendererComponent(table, objVal, false, false, r, vColIndex);
            width = Math.max(width, comp.getPreferredSize().width);
        }

        // Add margin
        width += 2 * margin;

        preferredWidthTotal += col.getPreferredWidth();
        colWidths[i] = width;
        strWidths[i] = strWidth;

        renderedWidthTotal += width;
    }

    if (renderedWidthTotal > preferredWidthTotal) {
        for (int i = 0; i < table.getColumnCount(); i++) {
            TableColumn col = colModel.getColumn(i);
            TableCellRenderer renderer = col.getCellRenderer();
            if (renderer != null) {
                ((JLabel) renderer).setHorizontalAlignment(
                        strWidths[i] > 20 ? SwingConstants.LEFT : SwingConstants.CENTER);
                //((JLabel)renderer).setHorizontalAlignment(SwingConstants.LEFT);
            }

            if (model.getColumnCount() > 3 && renderedWidthTotal > preferredWidthTotal) {
                col.setPreferredWidth(colWidths[i]);
            }
        }
    }

    ((DefaultTableCellRenderer) table.getTableHeader().getDefaultRenderer())
            .setHorizontalAlignment(SwingConstants.LEFT);

    // table.setAutoCreateRowSorter(true);
    table.getTableHeader().setReorderingAllowed(false);
}

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

public void resetExample() {

    XYDataset dataset = createDataset(true);
    // System.out.println("resetExample num_series="+num_series);
    XYDataset[] ds1 = new XYDataset[num_series];
    ds1[0] = dataset;//from ww  w  .  ja va 2  s . c  om

    kernels = null;
    chart = createChart(ds1);
    refreshChartPanel();
    setChart();

    hasExample = true;
    //      convertor.dataset2Table((TimeSeriesCollection)dataset);            
    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
    int columnCount = dataTable.getColumnCount();
    for (int i = 0; i < columnCount / 2; i++) {
        //System.out.println("mapping");
        addButtonIndependent();
        addButtonDependent();

    }

    getMapping();
    //   System.out.println("resetExample get called indepvar"+independentVarLength );
    updateStatus(url);
}

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

protected void setTable(XYDataset ds) {
    // update results table after segment
    //System.out.println("setTable get called");
    //printDataset(ds);

    if (segment_flag) {
        // System.out.println("settable: setting segment resultTable");
        resultsTables = new CustomJTable[num_series];
        for (int s = 0; s < num_series; s++) {
            resultsTables[s] = mEMexperiment[s].getResultsTable();
        }//from   ww w.ja  v  a 2s  .co  m
    } else {
        convertor.dataset2Table((XYDataset) ds);
        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++) {

                String v = (String) tempDataTable.getValueAt(i, j);
                //if (v!="null" && v!="NaN")
                dataTable.setValueAt(v, i, j);
            }
    } //no segment

    // int columnCount = dataTable.getColumnCount();

    //attention this is a quick fix for losted mapping, need revisit!!!!!
    for (int i = 0; i < num_series; i++) {
        //System.out.println("mapping");
        addButtonIndependent();
        addButtonDependent();

    }

    setTablePane();

    // don't bring graph to the front
    if (tabbedPanelContainer.getTitleAt(tabbedPanelContainer.getSelectedIndex()) != ALL) {
        //   tabbedPanelContainer.setSelectedIndex(tabbedPanelContainer.indexOfComponent(graphPanel));
    } else {
        setMixPanel();
    }
}

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

protected void emptyResultsTable() {
    String[] resultsHeading = new String[2];
    resultsHeading[0] = "Kernel";
    resultsHeading[1] = "Resutls";
    String[][] results = new String[1][2];
    JTable tempResultsTable = new JTable(results, resultsHeading);
    resetRTableRows(tempResultsTable.getRowCount());

    for (int i = 0; i < tempResultsTable.getRowCount(); i++)
        for (int j = 0; j < tempResultsTable.getColumnCount(); j++) {
            for (int s = 0; s < num_series; s++) {
                resultsTables[s].setValueAt(tempResultsTable.getValueAt(i, j), i, j);
            }/*from  w  w w.  j av a2s .c  o  m*/
        }
}