Example usage for javax.swing.table TableColumn setMaxWidth

List of usage examples for javax.swing.table TableColumn setMaxWidth

Introduction

In this page you can find the example usage for javax.swing.table TableColumn setMaxWidth.

Prototype

@BeanProperty(description = "The maximum width of the column.")
public void setMaxWidth(int maxWidth) 

Source Link

Document

Sets the TableColumn's maximum width to maxWidth or, if maxWidth is less than the minimum width, to the minimum width.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int rows = 3;
    int cols = 3;
    JTable table = new JTable(rows, cols);

    TableColumn col = table.getColumnModel().getColumn(0);
    col.setMinWidth(100);/*from  ww  w  .  ja v  a 2 s  . c om*/
    col.setMaxWidth(100);
    col.setPreferredWidth(100);

}

From source file:ThreadViewer.java

public ThreadViewer() {

    JTable table = new JTable(tableModel);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);

    TableColumnModel colModel = table.getColumnModel();
    int numColumns = colModel.getColumnCount();

    for (int i = 0; i < numColumns - 1; i++) {
        TableColumn col = colModel.getColumn(i);

        col.sizeWidthToFit();//from  ww  w .  j  av a  2s . c  om
        col.setPreferredWidth(col.getWidth() + 5);
        col.setMaxWidth(col.getWidth() + 5);
    }

    JScrollPane sp = new JScrollPane(table);

    setLayout(new BorderLayout());
    add(sp, BorderLayout.CENTER);
}

From source file:com.emental.mindraider.ui.panels.ConceptAttachmentsJPanel.java

public void init() {
    JPanel pp;//from w w w.  j  a  v  a  2s .c om
    setBorder(new TitledBorder(Messages.getString("ConceptJPanel.attachments")));
    setLayout(new BorderLayout());

    // button
    pp = new JPanel();
    pp.setLayout(new GridLayout(3, 1));
    JButton jbutton = new JButton("", IconsRegistry.getImageIcon("attach.png"));
    jbutton.setToolTipText(Messages.getString("ConceptJPanel.attachLocalResourceToConcept"));
    jbutton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // some concept must be selected - select graph node according
            // to the selected concept =-> touchgraph
            // method needed
            if (conceptJPanel.getConceptResource() == null) {
                JOptionPane.showMessageDialog(MindRaider.mainJFrame,
                        Messages.getString("ConceptJPanel.attachResourceWarning"),
                        Messages.getString("ConceptJPanel.attachmentError"), JOptionPane.ERROR_MESSAGE);
                return;
            }
            new AttachmentJDialog(conceptJPanel.getConceptResource());
        }
    });
    pp.add(jbutton);
    // @todo edit resource description
    // jbutton=new JButton("",IconsRegistry.getImageIcon("attachLink.png"));
    // jbutton.setToolTipText("Attach web resource to concept");
    // jbutton.addActionListener(new ActionListener() {
    // public void actionPerformed(ActionEvent e) {
    // }
    // });
    // pp.add(jbutton);
    // attach another concept/folder/resource... - perhaps extra frame with
    // radio
    jbutton = new JButton("", IconsRegistry.getImageIcon("launch.png"));
    jbutton.setToolTipText(Messages.getString("ConceptJPanel.showAttachment"));
    jbutton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (attachmentsTableModel.attachments != null) {
                if (attachments.getSelectedRow() == -1) {
                    JOptionPane.showMessageDialog(MindRaider.mainJFrame,
                            Messages.getString("ConceptJPanel.selectAttachmentToLaunch"),
                            Messages.getString("ConceptJPanel.attachmentError"), JOptionPane.ERROR_MESSAGE);
                    return;
                }
                String uri = attachmentsTableModel.attachments[attachments.getSelectedRow()].getUrl();
                if (uri != null) {
                    Node node = new Node();
                    node.setLabel(uri);
                    node.setURL(uri);
                    node.setType(
                            MindRaider.spidersColorProfileRegistry.getCurrentProfile().getLiteralNodeType());
                    MindRaider.spidersGraph.handleDoubleSelect(node);
                }
            }
        }
    });
    pp.add(jbutton);
    jbutton = new JButton("", IconsRegistry.getImageIcon("explorerDiscardSmall.png"));
    jbutton.setToolTipText(Messages.getString("ConceptJPanel.removeAttachment"));
    pp.add(jbutton);
    jbutton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (attachmentsTableModel.attachments != null) {
                if (getAttachments().getSelectedRow() != -1) {
                    logger.debug(Messages.getString("ConceptJPanel.removingAttachment",
                            getAttachments().getSelectedRow()));
                    String attachUrl = getAttachmentsTableModel().attachments[getAttachments().getSelectedRow()]
                            .getUrl();
                    logger.debug(Messages.getString("ConceptJPanel.removingAttachmentUrl", attachUrl));
                    if (conceptJPanel.getConceptResource() != null) {
                        // check, that selected node is type of literal
                        // (helper on spiders graph)
                        MindRaider.noteCustodian.removeAttachment(
                                MindRaider.profile.getActiveOutlineUri().toString(),
                                conceptJPanel.getConceptResource(), attachUrl);
                        conceptJPanel.refresh();
                        MindRaider.spidersGraph.renderModel();
                        return;
                    }
                }
                JOptionPane.showMessageDialog(MindRaider.mainJFrame,
                        Messages.getString("ConceptJPanel.selectAttachmentToRemove"),
                        Messages.getString("ConceptJPanel.attachmentError"), JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    add(pp, BorderLayout.EAST);

    // table
    attachmentsTableModel = new AttachmentsTableModel();
    attachments = new JTable(attachmentsTableModel) {

        private static final long serialVersionUID = 1L;

        public String getToolTipText(MouseEvent e) {
            String tip = null;
            java.awt.Point p = e.getPoint();
            int rowIndex = rowAtPoint(p);

            AttachmentsTableModel model = (AttachmentsTableModel) getModel();
            tip = Messages.getString("ConceptJPanel.attachmentUrl") + model.attachments[rowIndex].getUrl();
            // You can omit this part if you know you don't
            // have any renderers that supply their own tool
            // tips.
            // tip = super.getToolTipText(e);
            return tip;
        }
    };
    TableColumn column = attachments.getColumnModel().getColumn(0);
    column.setMaxWidth(50);
    attachments.setRowHeight(20);
    attachments.setAutoscrolls(true);
    attachments.setPreferredScrollableViewportSize(new Dimension(500, 70));
    JScrollPane scrollPane = new JScrollPane(attachments);
    add(scrollPane, BorderLayout.CENTER);
}

From source file:net.sf.profiler4j.console.ClassListPanel.java

/**
 * This method initializes classesTable/*  w w w  .j  av a 2s . c  o m*/
 * 
 * @return javax.swing.JTable
 */
private JTable getClassesTable() {
    if (classesTable == null) {
        classesTable = new JTable();
        classesTable.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        classesTable.setFont(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 12));
        classesTable.setModel(getClassListTableModel());
        classesTable.setRowHeight(20);
        classesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                if (classesTable.getSelectedRowCount() > 0) {
                    addAsRuleButton.setEnabled(true);
                } else {
                    addAsRuleButton.setEnabled(false);
                }

            }
        });
        TableColumn c = classesTable.getColumnModel().getColumn(0);
        c.setMinWidth(50);
        c.setMaxWidth(50);

        c = classesTable.getColumnModel().getColumn(1);
        c.setMinWidth(300);
        c.setCellRenderer(new DefaultTableCellRenderer() {
            Font f1 = new Font("Tahoma", java.awt.Font.PLAIN, 12);
            Font f2 = new Font("Tahoma", java.awt.Font.BOLD, 12);

            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                    boolean hasFocus, int row, int column) {
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

                if (isSelected) {
                    setFont(f2);
                } else {
                    setFont(f1);
                }
                if (classListTableModel.getRow(row).info.isInstrumented()) {
                    if (isSelected) {
                        setForeground(Color.YELLOW);
                        setBackground(Color.BLUE);
                    } else {
                        setBackground(Color.decode("#bbffbb"));
                        setForeground(Color.BLACK);
                    }
                } else {
                    if (isSelected) {
                        setForeground(Color.WHITE);
                        setBackground(Color.BLUE);
                    } else {
                        setBackground(Color.WHITE);
                        setForeground(Color.BLACK);
                    }
                }
                setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 4));
                return this;
            }
        });

    }
    return classesTable;
}

From source file:MainClass.java

public MainClass() {
    super("Row Header Test");
    setSize(300, 200);/*w w  w . j a v  a  2s .  c  o  m*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    TableModel tm = new AbstractTableModel() {
        String data[] = { "", "a", "b", "c", "d", "e" };

        String headers[] = { "Row #", "Column 1", "Column 2", "Column 3", "Column 4", "Column 5" };

        public int getColumnCount() {
            return data.length;
        }

        public int getRowCount() {
            return 1000;
        }

        public String getColumnName(int col) {
            return headers[col];
        }

        public Object getValueAt(int row, int col) {
            return data[col] + row;
        }
    };

    TableColumnModel cm = new DefaultTableColumnModel() {
        boolean first = true;

        public void addColumn(TableColumn tc) {
            if (first) {
                first = false;
                return;
            }
            tc.setMinWidth(150);
            super.addColumn(tc);
        }
    };

    TableColumnModel rowHeaderModel = new DefaultTableColumnModel() {
        boolean first = true;

        public void addColumn(TableColumn tc) {
            if (first) {
                tc.setMaxWidth(tc.getPreferredWidth());
                super.addColumn(tc);
                first = false;
            }
        }
    };

    JTable jt = new JTable(tm, cm);
    JTable headerColumn = new JTable(tm, rowHeaderModel);
    jt.createDefaultColumnsFromModel();
    headerColumn.createDefaultColumnsFromModel();

    jt.setSelectionModel(headerColumn.getSelectionModel());

    headerColumn.setBackground(Color.lightGray);
    headerColumn.setColumnSelectionAllowed(false);
    headerColumn.setCellSelectionEnabled(false);

    JViewport jv = new JViewport();
    jv.setView(headerColumn);
    jv.setPreferredSize(headerColumn.getMaximumSize());

    jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    JScrollPane jsp = new JScrollPane(jt);
    jsp.setRowHeader(jv);
    jsp.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, headerColumn.getTableHeader());
    getContentPane().add(jsp, BorderLayout.CENTER);
}

From source file:edu.ku.brc.af.ui.forms.formatters.DataObjFieldFormatMultiplePanel.java

/**
 * //from  w  w  w .j a  v a 2  s  .com
 */
private void setFormatSwitchTblColumnProperties() {
    // set details of 1st column (field values)
    TableColumnModel model = formatSwitchTbl.getColumnModel();
    TableColumn column = model.getColumn(model.getColumnIndex(FIELD_VALUE_COL));
    column.setMinWidth(20);
    column.setMaxWidth(300);
    column.setPreferredWidth(70);
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
    renderer.setHorizontalAlignment(SwingConstants.CENTER);
    column.setCellRenderer(renderer);

    // set details of 3rd column (ellipsis buttons)
    column = model.getColumn(model.getColumnIndex(ELLIPSIS_BUTTON_COL));
    column.setCellRenderer(new EditDataObjFormatButtonRenderer());
    column.setCellEditor(new EditDataObjFormatButtonEditor(createCheckBox()));
    column.setMinWidth(20);
    column.setMaxWidth(20);
    column.setPreferredWidth(20);
}

From source file:net.sf.keystore_explorer.gui.dialogs.extensions.DViewExtensions.java

private void initComponents() {
    ExtensionsTableModel extensionsTableModel = new ExtensionsTableModel();
    jtExtensions = new JKseTable(extensionsTableModel);

    TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(extensionsTableModel);
    sorter.setComparator(2, new ObjectIdComparator());
    jtExtensions.setRowSorter(sorter);/*from   ww w  .j a  v a  2  s .c  om*/

    jtExtensions.setShowGrid(false);
    jtExtensions.setRowMargin(0);
    jtExtensions.getColumnModel().setColumnMargin(0);
    jtExtensions.getTableHeader().setReorderingAllowed(false);
    jtExtensions.setAutoResizeMode(JKseTable.AUTO_RESIZE_ALL_COLUMNS);
    jtExtensions.setRowHeight(Math.max(18, jtExtensions.getRowHeight()));

    for (int i = 0; i < jtExtensions.getColumnCount(); i++) {
        TableColumn column = jtExtensions.getColumnModel().getColumn(i);
        column.setHeaderRenderer(
                new ExtensionsTableHeadRend(jtExtensions.getTableHeader().getDefaultRenderer()));
        column.setCellRenderer(new ExtensionsTableCellRend());
    }

    TableColumn criticalCol = jtExtensions.getColumnModel().getColumn(0);
    criticalCol.setResizable(false);
    criticalCol.setMinWidth(28);
    criticalCol.setMaxWidth(28);
    criticalCol.setPreferredWidth(28);

    ListSelectionModel selectionModel = jtExtensions.getSelectionModel();
    selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    selectionModel.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
                try {
                    CursorUtil.setCursorBusy(DViewExtensions.this);
                    updateExtensionValue();
                } finally {
                    CursorUtil.setCursorFree(DViewExtensions.this);
                }
            }
        }
    });

    jspExtensionsTable = PlatformUtil.createScrollPane(jtExtensions,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    jspExtensionsTable.getViewport().setBackground(jtExtensions.getBackground());

    jpExtensionsTable = new JPanel(new BorderLayout(5, 5));
    jpExtensionsTable.setPreferredSize(new Dimension(500, 200));
    jpExtensionsTable.add(jspExtensionsTable, BorderLayout.CENTER);

    jpExtensionValue = new JPanel(new BorderLayout(5, 5));

    jlExtensionValue = new JLabel(res.getString("DViewExtensions.jlExtensionValue.text"));

    jpExtensionValue.add(jlExtensionValue, BorderLayout.NORTH);

    jepExtensionValue = new JEditorPane();
    jepExtensionValue.setFont(new Font(Font.MONOSPACED, Font.PLAIN, LnfUtil.getDefaultFontSize()));
    jepExtensionValue.setEditable(false);
    jepExtensionValue.setToolTipText(res.getString("DViewExtensions.jtaExtensionValue.tooltip"));
    // JGoodies - keep uneditable color same as editable
    jepExtensionValue.putClientProperty("JTextArea.infoBackground", Boolean.TRUE);

    // for displaying URLs in extensions as clickable links
    jepExtensionValue.setContentType("text/html");
    jepExtensionValue.addHyperlinkListener(this);
    // use default font and foreground color from the component
    jepExtensionValue.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);

    jspExtensionValue = PlatformUtil.createScrollPane(jepExtensionValue,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    jpExtensionValueTextArea = new JPanel(new BorderLayout(5, 5));
    jpExtensionValueTextArea.setPreferredSize(new Dimension(500, 200));
    jpExtensionValueTextArea.add(jspExtensionValue, BorderLayout.CENTER);

    jpExtensionValue.add(jpExtensionValueTextArea, BorderLayout.CENTER);

    jbAsn1 = new JButton(res.getString("DViewExtensions.jbAsn1.text"));

    PlatformUtil.setMnemonic(jbAsn1, res.getString("DViewExtensions.jbAsn1.mnemonic").charAt(0));
    jbAsn1.setToolTipText(res.getString("DViewExtensions.jbAsn1.tooltip"));
    jbAsn1.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                CursorUtil.setCursorBusy(DViewExtensions.this);
                asn1DumpPressed();
            } finally {
                CursorUtil.setCursorFree(DViewExtensions.this);
            }
        }
    });

    jpExtensionValueAsn1 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    jpExtensionValueAsn1.add(jbAsn1);

    jpExtensionValue.add(jpExtensionValueAsn1, BorderLayout.SOUTH);

    jpExtensions = new JPanel(new GridLayout(2, 1, 5, 5));
    jpExtensions.setBorder(new CompoundBorder(new EmptyBorder(5, 5, 5, 5),
            new CompoundBorder(new EtchedBorder(), new EmptyBorder(5, 5, 5, 5))));

    jpExtensions.add(jpExtensionsTable);
    jpExtensions.add(jpExtensionValue);

    jbOK = new JButton(res.getString("DViewExtensions.jbOK.text"));
    jbOK.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            okPressed();
        }
    });

    jpOK = PlatformUtil.createDialogButtonPanel(jbOK, false);

    extensionsTableModel.load(extensions);

    if (extensionsTableModel.getRowCount() > 0) {
        jtExtensions.changeSelection(0, 0, false, false);
    }

    getContentPane().add(jpExtensions, BorderLayout.CENTER);
    getContentPane().add(jpOK, BorderLayout.SOUTH);

    setResizable(false);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent evt) {
            closeDialog();
        }
    });

    getRootPane().setDefaultButton(jbOK);

    pack();

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            jbOK.requestFocus();
        }
    });
}

From source file:com.diversityarrays.kdxplore.curate.TraitsAndInstancesPanel2.java

public TraitsAndInstancesPanel2(CurationContext cc, Font smallFont, TIStatsTableModel tistm,
        boolean anyInstanceNumbers, int nInvalidRules, String tAndIpanelLabel,
        CurationMenuProvider curationMenuProvider, Consumer<List<OutlierSelection>> outlierConsumer) {
    super(new BorderLayout());

    this.curationContext = cc;
    this.outlierConsumer = outlierConsumer;
    this.curationMenuProvider = curationMenuProvider;

    this.tiStatsModel = tistm;

    curationContext.addPropertyChangeListener(propertyChangeListener);

    traitInstanceStatsTable = new TraitInstanceStatsTable(tiStatsModel);

    traitInstanceStatsTable.addPropertyChangeListener("rowSorter", rowSorterChangeListener);
    traitInstanceStatsTable.setAutoCreateRowSorter(true);

    traitInstanceStatsTable.addMouseListener(new MouseAdapter() {
        @Override// ww w .j  a v  a  2 s . c o m
        public void mouseClicked(MouseEvent me) {
            int clickCount = me.getClickCount();

            if (SwingUtilities.isRightMouseButton(me) && 1 == clickCount) {
                me.consume();
                showContextMenu(me);
            } else if (SwingUtilities.isLeftMouseButton(me) && 2 == clickCount) {
                showTraitInstanceInfo(me);
            }
        }
    });

    Map<String, TableColumn[]> tableColumnsByChoice = createInstanceTableColumnsByChoice();
    TableColumnSelectionButton tcsb = new TableColumnSelectionButton(traitInstanceStatsTable,
            tableColumnsByChoice);

    StringCellRenderer scRenderer = new StringCellRenderer();
    scRenderer.setHorizontalAlignment(SwingConstants.CENTER);

    statDetailRenderer.setHorizontalAlignment(SwingConstants.CENTER);

    traitInstanceStatsTable.setDefaultRenderer(String.class, scRenderer);
    Transformer<TraitInstance, String> instanceNameTransformer = new Transformer<TraitInstance, String>() {
        @Override
        public String transform(TraitInstance ti) {
            return curationContext.makeTraitInstanceName(ti);
        }
    };
    TraitInstanceCellRenderer tiRenderer = new TraitInstanceCellRenderer(
            curationContext.getTraitColorProvider(), instanceNameTransformer);
    tiRenderer.setName("FOR-STATS-TABLE"); //$NON-NLS-1$
    traitInstanceStatsTable.setDefaultRenderer(TraitInstance.class, tiRenderer);
    traitInstanceStatsTable.setDefaultRenderer(Comparable.class, statDetailRenderer);

    TableColumnModel tcm = traitInstanceStatsTable.getColumnModel();
    Integer viewColumnIndex = tistm.getViewColumnIndex();
    if (viewColumnIndex != null) {
        TableColumn viewColumn = tcm.getColumn(viewColumnIndex);
        viewColumn.setMaxWidth(40);
        viewColumn.setCellRenderer(new OptionalCheckboxRenderer("No Values"));
    }

    if (nInvalidRules <= 0) {
        // Hide that column!
        int columnIndex = tistm.getValRuleErrorColumnIndex();
        columnIndex = traitInstanceStatsTable.convertColumnIndexToView(columnIndex);
        if (columnIndex >= 0) {
            TableColumn c = tcm.getColumn(columnIndex);
            tcm.removeColumn(c);
        }
    }

    TableColumn dataTypeTableColumn = traitInstanceStatsTable.getColumnModel()
            .getColumn(tistm.getTraitInstanceDatatypeColumnIndex());
    dataTypeTableColumn.setCellRenderer(new TraitDataTypeRenderer());

    Function<JTable, JScrollPane> scrollMaker = new Function<JTable, JScrollPane>() {
        @Override
        public JScrollPane apply(JTable t) {
            return new PromptScrollPane(t, "Select Trait in the Panel: " + tAndIpanelLabel);
        }
    };
    TitledTablePanelWithResizeControls ttp = new TitledTablePanelWithResizeControls("Trait Instances",
            traitInstanceStatsTable, smallFont, scrollMaker);
    ttp.scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    ttp.scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, tcsb);

    new CurationContextOptionsPopup(curationContext, ttp.separator);

    if (anyInstanceNumbers) {
        tcsb.setSelectedColumns(SimpleStatistics.GROUP_BASIC_STATS);
    } else {
        Set<Object> headerValues = new HashSet<>();
        for (TableColumn tc : tableColumnsByChoice.get(SimpleStatistics.GROUP_BASIC_STATS)) {
            headerValues.add(tc.getHeaderValue());
        }
        headerValues.remove(tistm.getInstanceHeading());
        tcsb.initialiseSelectedColumns(new Predicate<Object>() {
            @Override
            public boolean evaluate(Object hvalue) {
                return headerValues.contains(hvalue);
            }
        });
    }

    add(ttp, BorderLayout.CENTER);
}

From source file:com.microsoft.azure.hdinsight.spark.ui.SparkSubmissionContentPanel.java

private void updateTableColumn() {
    TableColumn hidden = jobConfigurationTable.getColumnModel().getColumn(InteractiveTableModel.HIDDEN_INDEX);
    hidden.setMinWidth(2);//from w ww.  j av a2  s .  c  o  m
    hidden.setPreferredWidth(2);
    hidden.setMaxWidth(2);
    hidden.setCellRenderer(new InteractiveRenderer(InteractiveTableModel.HIDDEN_INDEX));

    TableColumn keyColumn = jobConfigurationTable.getColumnModel().getColumn(InteractiveTableModel.KEY_INDEX);
    keyColumn.setCellRenderer(new InteractiveRenderer(InteractiveTableModel.KEY_INDEX));

    if (updateCallBack != null) {
        updateCallBack.run();
    }
}

From source file:RowHeaderTable.java

public RowHeaderTable() {
    super("Row Header Test");
    setSize(300, 200);/*from   ww  w  . j a  v a2s.  c o m*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    TableModel tm = new AbstractTableModel() {
        String data[] = { "", "a", "b", "c", "d", "e" };

        String headers[] = { "Row #", "Column 1", "Column 2", "Column 3", "Column 4", "Column 5" };

        public int getColumnCount() {
            return data.length;
        }

        public int getRowCount() {
            return 1000;
        }

        public String getColumnName(int col) {
            return headers[col];
        }

        // Synthesize some entries using the data values & the row #
        public Object getValueAt(int row, int col) {
            return data[col] + row;
        }
    };

    // Create a column model for the main table. This model ignores the
    // first
    // column added, and sets a minimum width of 150 pixels for all others.
    TableColumnModel cm = new DefaultTableColumnModel() {
        boolean first = true;

        public void addColumn(TableColumn tc) {
            // Drop the first column . . . that'll be the row header
            if (first) {
                first = false;
                return;
            }
            tc.setMinWidth(150); // just for looks, really...
            super.addColumn(tc);
        }
    };

    // Create a column model that will serve as our row header table. This
    // model picks a maximum width and only stores the first column.
    TableColumnModel rowHeaderModel = new DefaultTableColumnModel() {
        boolean first = true;

        public void addColumn(TableColumn tc) {
            if (first) {
                tc.setMaxWidth(tc.getPreferredWidth());
                super.addColumn(tc);
                first = false;
            }
            // Drop the rest of the columns . . . this is the header column
            // only
        }
    };

    JTable jt = new JTable(tm, cm);

    // Set up the header column and get it hooked up to everything
    JTable headerColumn = new JTable(tm, rowHeaderModel);
    jt.createDefaultColumnsFromModel();
    headerColumn.createDefaultColumnsFromModel();

    // Make sure that selections between the main table and the header stay
    // in sync (by sharing the same model)
    jt.setSelectionModel(headerColumn.getSelectionModel());

    // Make the header column look pretty
    //headerColumn.setBorder(BorderFactory.createEtchedBorder());
    headerColumn.setBackground(Color.lightGray);
    headerColumn.setColumnSelectionAllowed(false);
    headerColumn.setCellSelectionEnabled(false);

    // Put it in a viewport that we can control a bit
    JViewport jv = new JViewport();
    jv.setView(headerColumn);
    jv.setPreferredSize(headerColumn.getMaximumSize());

    // With out shutting off autoResizeMode, our tables won't scroll
    // correctly (horizontally, anyway)
    jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    // We have to manually attach the row headers, but after that, the
    // scroll
    // pane keeps them in sync
    JScrollPane jsp = new JScrollPane(jt);
    jsp.setRowHeader(jv);
    jsp.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, headerColumn.getTableHeader());
    getContentPane().add(jsp, BorderLayout.CENTER);
}