Example usage for javax.swing JTable getColumnModel

List of usage examples for javax.swing JTable getColumnModel

Introduction

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

Prototype

public TableColumnModel getColumnModel() 

Source Link

Document

Returns the TableColumnModel that contains all column information of this table.

Usage

From source file:org.eumetsat.metop.visat.IasiInfoView.java

private Component createRadianceAnalysisComponent() {
    BorderLayout layout = new BorderLayout(4, 4);
    JPanel panel = new JPanel(layout);

    radianceTableModel = new RadianceAnalysisTableModel();
    JTable radianceTable = new RadianceAnalysisTable(radianceTableModel);
    radianceTable.getColumnModel().getColumn(0).setPreferredWidth(130);
    JScrollPane scrollPane = new JScrollPane(radianceTable);
    panel.add(scrollPane, BorderLayout.CENTER);

    imageLabel = new JLabel();
    panel.add(imageLabel, BorderLayout.SOUTH);

    return panel;
}

From source file:logdruid.ui.table.StatRecordingEditorTable.java

private void initColumnSizes(JTable theTable) {
    MyTableModel model = (MyTableModel) theTable.getModel();
    TableColumn column = null;//ww  w  .j  a  va 2s . co  m
    Component comp = null;
    int headerWidth = 0;
    int cellWidth = 0;
    // Object[] longValues = model.longValues;
    TableCellRenderer headerRenderer = theTable.getTableHeader().getDefaultRenderer();

    for (int i = 0; i < 6; i++) {
        column = theTable.getColumnModel().getColumn(i);

        comp = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0);
        headerWidth = comp.getPreferredSize().width;
        cellWidth = comp.getPreferredSize().width;

        if (DEBUG) {
            logger.info("Initializing width of column " + i + ". " + "headerWidth = " + headerWidth
                    + "; cellWidth = " + cellWidth);
        }

        column.setPreferredWidth(Math.max(headerWidth, cellWidth));
    }
}

From source file:ecosim.gui.SummaryPane.java

/**
 *  Private method to build the table pane.
 *
 *  @return A JLayeredPane containing the table pane.
 *//*  w ww. j av a2  s  .  co m*/
private JLayeredPane makeTablePane() {
    String[] columnNames = { "", "Estimate", "Hillclimbing", "Low", "High" };
    Integer[] columnWidths = { 250, 60, 60, 60, 60 };
    Object[][] rowData = { { "Number of putative ecotypes (npop)", null, null, null, null },
            { "Rate of ecotype formation (omega)", null, null, null, null },
            { "Rate of periodic selection (sigma)", null, null, null, null } };
    final JLayeredPane pane = new JLayeredPane();
    final JTable table = new JTable(rowData, columnNames) {
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    final JTableHeader header = table.getTableHeader();
    pane.setLayout(new BorderLayout());
    header.setReorderingAllowed(false);
    TableColumnModel cm = table.getColumnModel();
    for (int i = 0; i < columnWidths.length; i++) {
        TableColumn column = cm.getColumn(i);
        column.setMinWidth(columnWidths[i]);
        if (i == 0) {
            column.setCellRenderer(new DefaultTableCellRenderer() {
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                        boolean hasFocus, int row, int column) {
                    Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
                            row, column);
                    cell.setBackground(header.getBackground());
                    cell.setForeground(header.getForeground());
                    return cell;
                }
            });
        }
    }
    pane.add(table.getTableHeader(), "North");
    pane.add(table, "Center");
    // Watch for changes to the Summary object.
    summary.addObserver(new Observer() {
        public void update(Observable o, Object obj) {
            Summary s = (Summary) obj;
            ParameterEstimate estimate = s.getEstimate();
            ParameterSet hillclimbing = s.getHillclimbing();
            ParameterSet[] ci = s.getConfidenceInterval();
            if (estimate != null) {
                ParameterSet e = estimate.getResult();
                table.setValueAt(e.getNpop(), 0, 1);
                table.setValueAt(String.format("%.4f", e.getOmega()), 1, 1);
                table.setValueAt(String.format("%.4f", e.getSigma()), 2, 1);
            }
            if (hillclimbing != null) {
                table.setValueAt(hillclimbing.getNpop(), 0, 2);
                table.setValueAt(String.format("%.4f", hillclimbing.getOmega()), 1, 2);
                table.setValueAt(String.format("%.4f", hillclimbing.getSigma()), 2, 2);
            }
            if (ci[0].getNpop() != null) {
                table.setValueAt(ci[0].getNpop(), 0, 3);
                table.setValueAt(ci[1].getNpop(), 0, 4);
            }
            if (ci[1].getOmega() != null) {
                table.setValueAt(String.format("%.4f", ci[0].getOmega()), 1, 3);

                String fmt = "%.4f";
                if (ci[1].getOmega() > 10.0D) {
                    fmt = "%.1f";
                } else if (ci[1].getOmega() > 1.0D) {
                    fmt = "%.2f";
                }
                table.setValueAt(String.format(fmt, ci[1].getOmega()), 1, 4);
            }
            if (ci[1].getSigma() != null) {
                table.setValueAt(String.format("%.4f", ci[0].getSigma()), 2, 3);
                if (ci[1].getSigma() > 100.0D - MasterVariables.EPSILON) {
                    table.setValueAt("100", 2, 4);
                } else {
                    String fmt = "%.4f";
                    if (ci[1].getSigma() > 10.0D) {
                        fmt = "%.1f";
                    } else if (ci[1].getSigma() > 1.0D) {
                        fmt = "%.2f";
                    }
                    table.setValueAt(String.format(fmt, ci[1].getSigma()), 2, 4);
                }
            }
            pane.repaint();
        }
    });
    return pane;
}

From source file:Import.pnl_import_vcf.java

public void setMapTable(JTable table, DefaultTableModel model, String[] selectedFamilies,
        String[] selectedTableFamilies) {
    model.setRowCount(0);/*from  w  w  w. j  a v a  2s  . c  om*/
    model.addColumn("Import Column");
    model.addColumn("Map to");
    TableColumn sportColumn = table.getColumnModel().getColumn(1);
    JComboBox comboBox = new JComboBox();
    for (String a : selectedFamilies) {
        comboBox.addItem(a);
    }
    sportColumn.setCellEditor(new DefaultCellEditor(comboBox));
    for (String b : selectedTableFamilies) {
        String[] tmp = new String[1];
        tmp[0] = b;
        model.addRow(tmp);
    }
}

From source file:com.emr.schemas.ButtonColumn.java

/**
 *  Create the ButtonColumn to be used as a renderer and editor. The
 *  renderer and editor will automatically be installed on the TableColumn
 *  of the specified column.//from  w w w  . j  ava 2  s . co m
 *
 *  @param table the table containing the button renderer/editor
 *  @param action the Action to be invoked when the button is invoked
 *  @param column the column to which the button renderer/editor is added
 */
public ButtonColumn(JTable table, Action action, int column, String btnText) {
    this.table = table;
    this.action = action;
    this.btnText = btnText;

    renderButton = new JButton();
    editButton = new JButton();
    editButton.setFocusPainted(false);
    editButton.addActionListener(this);
    originalBorder = editButton.getBorder();
    setFocusBorder(new LineBorder(Color.BLUE));

    TableColumnModel columnModel = table.getColumnModel();
    columnModel.getColumn(column).setCellRenderer(this);
    columnModel.getColumn(column).setCellEditor(this);
    table.addMouseListener(this);
}

From source file:logdruid.ui.mainpanel.MetadataRecordingSelectorPanel.java

private void initColumnSizes(JTable theTable) {
    MyTableModel model = (MyTableModel) theTable.getModel();
    TableColumn column = null;/*from   w w  w .  java2  s .  c o  m*/
    Component comp = null;
    int headerWidth = 0;
    int cellWidth = 0;
    // Object[] longValues = model.longValues;
    TableCellRenderer headerRenderer = theTable.getTableHeader().getDefaultRenderer();

    for (int i = 0; i < 4; i++) {
        column = theTable.getColumnModel().getColumn(i);
        comp = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0);
        headerWidth = comp.getPreferredSize().width;
        cellWidth = comp.getPreferredSize().width;
        column.setPreferredWidth(Math.max(headerWidth, cellWidth));
    }
}

From source file:com.sec.ose.osi.ui.frm.main.manage.AddProjectTableModel.java

public void setColumnView(JTable table) {
    table.setShowVerticalLines(false);//from  w w  w  .  ja v  a2 s  . co  m
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setColumnSelectionAllowed(false);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
    table.setRowHeight(30);

    JTableHeader header = table.getTableHeader();
    header.setPreferredSize(new java.awt.Dimension(table.getTableHeader().getWidth(), 30));
    header.setFont(new Font("Arial", Font.BOLD, 12));
    header.setReorderingAllowed(false);

    TableColumnModel cm = table.getColumnModel();
    TableColumn col = null;

    searchHeader = new CheckBoxHeader(new CheckboxHeaderItemListener(table, COL_ISSELECT), "");
    col = cm.getColumn(COL_ISSELECT);
    col.setHeaderRenderer(searchHeader);
}

From source file:logdruid.ui.RecordingList.java

private void initColumnSizes(JTable theTable) {
    MyTableModel2 model = (MyTableModel2) theTable.getModel();
    TableColumn column = null;//from  w  w w.  jav  a2 s . com
    Component comp = null;
    int headerWidth = 0;
    int cellWidth = 0;
    // Object[] longValues = model.longValues;
    TableCellRenderer headerRenderer = theTable.getTableHeader().getDefaultRenderer();

    for (int i = 0; i < 4; i++) {
        column = theTable.getColumnModel().getColumn(i);

        comp = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0);
        headerWidth = comp.getPreferredSize().width;
        cellWidth = comp.getPreferredSize().width;
        column.setPreferredWidth(Math.max(headerWidth, cellWidth));
    }
}

From source file:logdruid.ui.DateEditor.java

private void initColumnSizes(JTable theTable) {
    MyTableModel2 model = (MyTableModel2) theTable.getModel();
    TableColumn column = null;//from  ww  w  .j a  va 2  s  .co m
    Component comp = null;
    int headerWidth = 0;
    int cellWidth = 0;
    // Object[] longValues = model.longValues;
    TableCellRenderer headerRenderer = theTable.getTableHeader().getDefaultRenderer();

    for (int i = 0; i < 3; i++) {
        column = theTable.getColumnModel().getColumn(i);

        comp = headerRenderer.getTableCellRendererComponent(null, column.getHeaderValue(), false, false, 0, 0);
        headerWidth = comp.getPreferredSize().width;

        /*
         * comp = table.getDefaultRenderer(model.getColumnClass(i)).
         * getTableCellRendererComponent( table, longValues[i], false,
         * false, 0, i);
         */
        cellWidth = comp.getPreferredSize().width;

        if (DEBUG) {
            logger.info("Initializing width of column " + i + ". " + "headerWidth = " + headerWidth
                    + "; cellWidth = " + cellWidth);
        }

        column.setPreferredWidth(Math.max(headerWidth, cellWidth));
    }
}

From source file:com.sec.ose.osi.ui.frm.main.manage.ManagedProjectTableModel.java

public void setColumnType(JTable table) {
    table.setShowVerticalLines(false);//from   ww  w.  j a  v a  2  s  . c  o  m
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setColumnSelectionAllowed(false);
    table.setRowSelectionAllowed(false);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setRowHeight(30);

    JTableHeader header = table.getTableHeader();
    header.setPreferredSize(new java.awt.Dimension(table.getTableHeader().getWidth(), 30));
    header.setFont(new Font("Arial", Font.BOLD, 12));
    header.setReorderingAllowed(false);

    TableColumnModel cm = table.getColumnModel();
    TableColumn col = null;

    analyzeHeader = new CheckBoxHeader(new CheckboxHeaderItemListener(table, COL_ANALYZE_TARGET),
            "Analyze Target");
    col = cm.getColumn(COL_ANALYZE_TARGET);
    col.setHeaderRenderer(analyzeHeader);

    JCheckBox chkbox = new JCheckBox();
    chkbox.setBackground(Color.white);
    chkbox.setHorizontalAlignment(JLabel.CENTER);
    col.setCellRenderer(new DefaultTableCellRenderer() {
        private static final long serialVersionUID = 1L;

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            ManagedProjectTableModel model = (ManagedProjectTableModel) table.getModel();

            String sPrjName = (String) table.getValueAt(row, ManagedProjectTableModel.COL_PROJECT_NAME);
            OSIProjectInfo item = model.getProjectInfo(sPrjName);

            JCheckBox chkbox = new JCheckBox();
            chkbox.setSelected(((Boolean) value).booleanValue());
            if (item != null) {
                chkbox.setEnabled(item.isLocationValid());
            }
            chkbox.setHorizontalAlignment(JLabel.CENTER);
            chkbox.setBackground(Color.white);

            return (Component) chkbox;
        }
    });
    col.setCellEditor(new DefaultCellEditor(chkbox));

    col = cm.getColumn(COL_ANALYZE_STATUS);
    col.setCellRenderer(new StatusIconCellRenderer());

    col = cm.getColumn(COL_SOURCE_LOCATION);
    col.setCellRenderer(new FileBrowseCellRenderer());
    col.setCellEditor(new FileBrowseCellEditor());
}