Example usage for javax.swing.table TableColumnModel getColumn

List of usage examples for javax.swing.table TableColumnModel getColumn

Introduction

In this page you can find the example usage for javax.swing.table TableColumnModel getColumn.

Prototype

public TableColumn getColumn(int columnIndex);

Source Link

Document

Returns the TableColumn object for the column at columnIndex.

Usage

From source file:org.datanucleus.ide.idea.ui.v10x.DNEConfigFormV10x.java

public void setData(@NotNull final GuiState data) {
    this.guiState = new GuiState(data);

    ////from   ww  w . java2 s  .c  om
    // Basic panels
    this.indexNotReadyPanel.setVisible(!data.isIndexReady());
    this.contentPanel.setVisible(data.isIndexReady());

    //
    // Enable enhancer checkbox
    this.enableEnhancerCheckBox.setSelected(data.isEnhancerEnabled());

    //
    // Persistence implementation selection
    final EnhancerSupportRegistry enhancerSupportRegistry = data.getEnhancerSupportRegistry();
    final Set<EnhancerSupport> supportedEnhancers = enhancerSupportRegistry.getSupportedEnhancers();
    if (this.persistenceImplComboBox.getItemCount() == 0) {
        for (final EnhancerSupport support : supportedEnhancers) {
            this.persistenceImplComboBox.addItem(support.getName());
        }
    }
    final EnhancerSupport enhancerSupport = data.getEnhancerSupport();
    this.persistenceImplComboBox.setSelectedItem(enhancerSupport.getName());
    if (supportedEnhancers.size() <= 1) {
        this.persistenceImplComboBox.setVisible(false);
    } else {
        this.persistenceImplComboBox.setVisible(true);
    }

    // just to be sure -> validate persistence settings from config file
    PersistenceApi persistenceApi = data.getApi();
    if (!enhancerSupport.isSupported(persistenceApi)) {
        persistenceApi = enhancerSupport.getDefaultPersistenceApi();
    }

    this.jDORadioButton.setSelected(PersistenceApi.JDO == persistenceApi);
    this.jPARadioButton.setSelected(PersistenceApi.JPA == persistenceApi);
    this.jDORadioButton.setEnabled(enhancerSupport.isSupported(PersistenceApi.JDO));
    this.jPARadioButton.setEnabled(enhancerSupport.isSupported(PersistenceApi.JPA));

    //
    // Metadata file extensions text field
    this.metadataExtensionTextField.setText(data.getMetaDataExtensions().trim());

    //
    // Compiler resource file extensions control
    final boolean metadataExtensionsEnabled = data.getMetaDataExtensions() != null
            && !data.getMetaDataExtensions().trim().isEmpty();
    this.addToCompilerResourceCheckBox.setSelected(data.isAddToCompilerResourcePatterns());
    this.addToCompilerResourceCheckBox.setEnabled(metadataExtensionsEnabled);

    //
    // Test classes inclusion
    this.includeTestClassesCheckBox.setSelected(data.isIncludeTestClasses());

    //
    // Panel displaying an info message if enhancer is not initialized

    this.infoPanel.setVisible(!data.isEnhancerInitialized());
    this.infoPanel.setEnabled(!data.isEnhancerInitialized());

    //
    // Table displaying affected modules if enhancer is initialized

    final TableModel affectedModulesRowModel = new AffectedModulesRowModel(data.getAffectedModules());
    // modules affected by class enhancement
    this.affectedModulesTable.setModel(affectedModulesRowModel);
    // set column appearance
    final TableColumnModel columnModel = this.affectedModulesTable.getColumnModel();
    final TableColumn firstColumn = columnModel.getColumn(0);
    firstColumn.setMinWidth(50);
    firstColumn.setMaxWidth(50);
    firstColumn.setPreferredWidth(50);
    this.affectedModulesTable.setDefaultEditor(Boolean.class, new BooleanTableCellEditor(false));
    setPreferredTableHeight(this.affectedModulesTable, this.affectedModulesTable.getRowCount());

    //
    // Table displaying affected files/classes/.. if enhancer is initialized

    final TableModel metadataOrClassFilesRowModel = new MetadataOrClassFilesRowModel(data.getMetadataFiles(),
            data.getAnnotatedClassFiles());
    // files affected by class enhancement
    this.metadataAndClassesTable.setModel(metadataOrClassFilesRowModel);
    // set column appearance
    this.metadataAndClassesTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    // adjust column sizes (after being rendered the first time - necessary for ColumnAdjuster to work)
    final ColumnAdjuster columnAdjuster = new ColumnAdjuster(this.metadataAndClassesTable);
    //columnAdjuster.setOnlyAdjustLarger(false);
    columnAdjuster.setDynamicAdjustment(true);
    columnAdjuster.adjustColumns();
    setPreferredTableHeight(this.metadataAndClassesTable, this.metadataAndClassesTable.getRowCount());

    this.metadataAndClassesTable.setVisible(data.isEnhancerInitialized());

    // only display detected classes if initialized
    this.metaDataAndClassesScrollPane.setVisible(data.isEnhancerInitialized());
}

From source file:org.executequery.gui.browser.ConnectionPanel.java

private void init() {

    // ---------------------------------
    // create the basic props panel

    // initialise the fields
    nameField = createTextField();//w w w .j a va 2  s .  co  m
    passwordField = createPasswordField();
    hostField = createTextField();
    portField = createNumberTextField();
    sourceField = createMatchedWidthTextField();
    userField = createTextField();
    urlField = createMatchedWidthTextField();

    nameField.addFocusListener(new ConnectionNameFieldListener(this));

    savePwdCheck = ActionUtilities.createCheckBox("Store Password", "setStorePassword");
    encryptPwdCheck = ActionUtilities.createCheckBox("Encrypt Password", "setEncryptPassword");

    savePwdCheck.addActionListener(this);
    encryptPwdCheck.addActionListener(this);

    // retrieve the drivers
    buildDriversList();

    // ---------------------------------
    // add the basic connection fields

    TextFieldPanel mainPanel = new TextFieldPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.insets = new Insets(10, 10, 10, 10);
    gbc.gridy = 0;
    gbc.gridx = 0;

    statusLabel = new DefaultFieldLabel();
    addLabelFieldPair(mainPanel, "Status:", statusLabel, "Current connection status", gbc);

    gbc.insets.bottom = 5;
    addLabelFieldPair(mainPanel, "Connection Name:", nameField, "A friendly name for this connection", gbc);

    addLabelFieldPair(mainPanel, "User Name:", userField, "Login user name", gbc);

    addLabelFieldPair(mainPanel, "Password:", passwordField, "Login password", gbc);

    JButton showPassword = new LinkButton("Show Password");
    showPassword.setActionCommand("showPassword");
    showPassword.addActionListener(this);

    JPanel passwordOptionsPanel = new JPanel(new GridBagLayout());
    addComponents(passwordOptionsPanel,
            new ComponentToolTipPair[] {
                    new ComponentToolTipPair(savePwdCheck,
                            "Store the password with the connection information"),
                    new ComponentToolTipPair(encryptPwdCheck, "Encrypt the password when saving"),
                    new ComponentToolTipPair(showPassword, "Show the password in plain text") });

    gbc.gridy++;
    gbc.gridx = 1;
    gbc.weightx = 1.0;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    mainPanel.add(passwordOptionsPanel, gbc);

    addLabelFieldPair(mainPanel, "Host Name:", hostField, "Server host name or IP address", gbc);

    addLabelFieldPair(mainPanel, "Port:", portField, "Database port number", gbc);

    addLabelFieldPair(mainPanel, "Data Source:", sourceField, "Data source name", gbc);

    addLabelFieldPair(mainPanel, "JDBC URL:", urlField, "The full JDBC URL for this connection (optional)",
            gbc);

    addDriverFields(mainPanel, gbc);

    connectButton = createButton("Connect", CONNECT_ACTION_COMMAND, 'T');
    disconnectButton = createButton("Disconnect", "disconnect", 'D');

    JPanel buttons = new JPanel(new GridBagLayout());
    gbc.gridy++;
    gbc.gridx = 0;
    gbc.insets.top = 5;
    gbc.insets.left = 0;
    gbc.insets.right = 10;
    gbc.gridwidth = 1;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.anchor = GridBagConstraints.NORTHEAST;
    gbc.fill = GridBagConstraints.NONE;
    buttons.add(connectButton, gbc);
    gbc.gridx++;
    gbc.weightx = 0;
    buttons.add(disconnectButton, gbc);

    gbc.insets.right = 0;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    mainPanel.add(buttons, gbc);

    // ---------------------------------
    // create the advanced panel

    model = new JdbcPropertiesTableModel();
    JTable table = new DefaultTable(model);
    table.getTableHeader().setReorderingAllowed(false);

    TableColumnModel tcm = table.getColumnModel();

    TableColumn column = tcm.getColumn(2);
    column.setCellRenderer(new DeleteButtonRenderer());
    column.setCellEditor(new DeleteButtonEditor(table, new JCheckBox()));
    column.setMaxWidth(24);
    column.setMinWidth(24);

    JScrollPane scroller = new JScrollPane(table);

    // advanced jdbc properties
    JPanel advPropsPanel = new JPanel(new GridBagLayout());
    advPropsPanel.setBorder(BorderFactory.createTitledBorder("JDBC Properties"));
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 1;
    gbc.insets.top = 0;
    gbc.insets.left = 10;
    gbc.insets.right = 10;
    gbc.weighty = 0;
    gbc.weightx = 1.0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    advPropsPanel.add(new DefaultFieldLabel("Enter any key/value pair properties for this connection"), gbc);
    gbc.gridy++;
    advPropsPanel.add(
            new DefaultFieldLabel("Refer to the relevant JDBC driver documentation for possible entries"), gbc);
    gbc.gridy++;
    gbc.insets.bottom = 10;
    gbc.weighty = 1.0;
    gbc.fill = GridBagConstraints.BOTH;
    advPropsPanel.add(scroller, gbc);

    // transaction isolation
    txApplyButton = WidgetFactory.createInlineFieldButton("Apply", "transactionLevelChanged");
    txApplyButton.setToolTipText("Apply this level to all open connections of this type");
    txApplyButton.setEnabled(false);
    txApplyButton.addActionListener(this);

    // add a dummy select value to the tx levels
    String[] txLevels = new String[Constants.TRANSACTION_LEVELS.length + 1];
    txLevels[0] = "Database Default";
    for (int i = 1; i < txLevels.length; i++) {
        txLevels[i] = Constants.TRANSACTION_LEVELS[i - 1];
    }
    txCombo = WidgetFactory.createComboBox(txLevels);

    JPanel advTxPanel = new JPanel(new GridBagLayout());
    advTxPanel.setBorder(BorderFactory.createTitledBorder("Transaction Isolation"));
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.insets.top = 0;
    gbc.insets.left = 10;
    gbc.insets.right = 10;
    gbc.insets.bottom = 5;
    gbc.weighty = 0;
    gbc.weightx = 1.0;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    advTxPanel.add(new DefaultFieldLabel("Default transaction isolation level for this connection"), gbc);
    gbc.gridy++;
    gbc.insets.bottom = 10;
    advTxPanel.add(
            new DefaultFieldLabel(
                    "Note: the selected isolation level " + "will apply to ALL open connections of this type."),
            gbc);
    gbc.gridy++;
    gbc.gridx = 0;
    gbc.gridwidth = 1;
    gbc.insets.top = 0;
    gbc.insets.left = 10;
    gbc.weightx = 0;
    advTxPanel.add(new DefaultFieldLabel("Isolation Level:"), gbc);
    gbc.gridx = 1;
    gbc.insets.left = 5;
    gbc.weightx = 1.0;
    gbc.insets.right = 5;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    advTxPanel.add(txCombo, gbc);
    gbc.gridx = 2;
    gbc.weightx = 0;
    gbc.insets.left = 0;
    gbc.insets.right = 10;
    advTxPanel.add(txApplyButton, gbc);

    JPanel advancedPanel = new JPanel(new BorderLayout());
    advancedPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    advancedPanel.add(advPropsPanel, BorderLayout.CENTER);
    advancedPanel.add(advTxPanel, BorderLayout.SOUTH);

    JScrollPane scrollPane = new JScrollPane(mainPanel);
    scrollPane.setBorder(null);

    sshTunnelConnectionPanel = new SSHTunnelConnectionPanel();

    tabPane = new JTabbedPane(JTabbedPane.BOTTOM);
    tabPane.addTab("Basic", scrollPane);
    tabPane.addTab("Advanced", advancedPanel);
    tabPane.addTab("SSH Tunnel", sshTunnelConnectionPanel);

    tabPane.addChangeListener(this);

    add(tabPane, BorderLayout.CENTER);

    EventMediator.registerListener(this);
}

From source file:org.executequery.gui.importexport.ImportExportPanelThree.java

private void prepareTable() {
    TableColumnModel tcm = table.getColumnModel();
    TableColumn col = tcm.getColumn(0);
    col.setPreferredWidth(140);/*from  w  w w .j  av  a2 s  .c  o  m*/

    col = tcm.getColumn(1);
    col.setPreferredWidth(255);

    if (browseButtonCellRenderer == null) {

        browseButtonCellRenderer = new BrowseButtonRenderer();
    }

    if (browseButtonCellEditor == null) {

        browseButtonCellEditor = new BrowseButtonEditor(new JCheckBox());
    }

    col = tcm.getColumn(2);
    col.setCellRenderer(browseButtonCellRenderer);
    col.setCellEditor(browseButtonCellEditor);
    col.setPreferredWidth(80);
}

From source file:org.gitools.ui.app.analysis.groupcomparison.wizard.GroupComparisonGroupingPage.java

public GroupComparisonGroupingPage(Heatmap heatmap, DimensionGroupEnum groupingType) {
    super();/*from w  w  w .  j a  va 2 s.  c  om*/

    this.heatmap = heatmap;
    this.groupingType = groupingType;

    setLogo(IconUtils.getImageIconResourceScaledByHeight(IconNames.LOGO_METHOD, 96));

    layerCb.setModel(new DefaultComboBoxModel(heatmap.getLayers().getIds()));
    layerCb.setSelectedItem(heatmap.getLayers().getTopLayer().getId());

    groupsTable.setModel(tableModel);

    setTitle("Group selection");
    TableColumnModel columnModel = groupsTable.getColumnModel();
    columnModel.getColumn(2).setPreferredWidth(50);
    columnModel.getColumn(2).setCellEditor(new SpinnerCellEditor(new SpinnerNumberModel()));
    columnModel.getColumn(2).getCellEditor().addCellEditorListener(new CellEditorListener() {
        @Override
        public void editingStopped(ChangeEvent e) {
            tableModel.fireTableDataChanged();
        }

        @Override
        public void editingCanceled(ChangeEvent e) {
            tableModel.fireTableDataChanged();
        }
    });
    groupsTable.setRowHeight(25);

    groupsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            updateControls();
        }
    });

    removeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            removeSelected();
        }
    });

    addButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (getSelectedGroupingType().equals(DimensionGroupEnum.Annotation)) {
                //TODO: create Dialog with removedItems
            } else if (getSelectedGroupingType().equals(DimensionGroupEnum.Free)) {
                createFreeGroup();
            } else if (getSelectedGroupingType().equals(DimensionGroupEnum.Value)) {
                createValueGroup();
            }
            updateControls();
        }
    });

    dimensionCb.setModel(new DefaultComboBoxModel(new String[] { "Columns", "Rows" }));

    mergeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            performMerge();
        }
    });
    splitButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            performSplit();
        }
    });
    dimensionCb.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            initGroups();
        }
    });

    ActionListener listener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            initGroups();
        }
    };
    annotationRadioButton.addActionListener(listener);
    valueRadioButton.addActionListener(listener);
    noConstraintRadioButton.addActionListener(listener);

    ActionListener nullConversionListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            updateControls();
        }
    };
    nullDiscardRadioButton.addActionListener(nullConversionListener);
    nullConversionRadioButton.addActionListener(nullConversionListener);

    nullConversionTextArea.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void insertUpdate(DocumentEvent e) {
            updateControls();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            updateControls();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            updateControls();
        }
    });

    updateControls();

    layerCb.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            updateControls();
        }
    });
}

From source file:org.isatools.isacreator.gui.formelements.SubForm.java

public void updateTables() {
    TableColumnModel scrollColumnModel = scrollTable.getColumnModel();

    if (scrollColumnModel.getColumnCount() > 0) {

        for (int i = 0; i < numFrozenColumns; i++) {
            scrollColumnModel.removeColumn(scrollColumnModel.getColumn(0));
        }//from  www. jav  a2  s  . c  om

        TableColumnModel lockedColumnModel = lockedTable.getColumnModel();

        while (lockedTable.getColumnCount() > numFrozenColumns) {
            lockedColumnModel.removeColumn(lockedColumnModel.getColumn(numFrozenColumns));
        }

        for (int i = 0; i < scrollTable.getColumnCount(); i++) {
            scrollColumnModel.getColumn(i).setPreferredWidth(100);
        }

        lockedTable.getColumnModel().getColumn(0).setPreferredWidth(250);
        lockedTable.setPreferredScrollableViewportSize(lockedTable.getPreferredSize());

        setHeaderProperties(scrollTable, scrollTableHeaderRenderer);
        setHeaderProperties(lockedTable, lockedTableHeaderRenderer);

    }
}

From source file:org.isatools.isacreator.spreadsheet.Spreadsheet.java

/**
 * Setup the JTable with its desired characteristics
 *//*  w  w  w . j av a 2  s . c o m*/
private void setupTable() {
    table = new CustomTable(spreadsheetModel);
    table.setShowGrid(true);
    table.setGridColor(Color.BLACK);
    table.setShowVerticalLines(true);
    table.setShowHorizontalLines(true);
    table.setGridColor(UIHelper.LIGHT_GREEN_COLOR);
    table.setRowSelectionAllowed(true);
    table.setColumnSelectionAllowed(true);
    table.setAutoCreateColumnsFromModel(false);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.getSelectionModel().addListSelectionListener(this);
    table.getColumnModel().getSelectionModel().addListSelectionListener(this);
    table.getTableHeader().setReorderingAllowed(true);
    table.getColumnModel().addColumnModelListener(this);
    try {
        table.setDefaultRenderer(Class.forName("java.lang.Object"), new SpreadsheetCellRenderer());
    } catch (ClassNotFoundException e) {
        // ignore this error
    }

    table.addMouseListener(this);
    table.getTableHeader().addMouseMotionListener(new MouseMotionListener() {
        public void mouseDragged(MouseEvent event) {
        }

        public void mouseMoved(MouseEvent event) {
            // display a tooltip when user hovers over a column. tooltip is derived
            // from the description of a field from the TableReferenceObject.
            JTable table = ((JTableHeader) event.getSource()).getTable();
            TableColumnModel colModel = table.getColumnModel();
            int colIndex = colModel.getColumnIndexAtX(event.getX());

            // greater than 1 to account for the row no. being the first col
            if (colIndex >= 1) {
                TableColumn tc = colModel.getColumn(colIndex);
                if (tc != null) {
                    try {
                        table.getTableHeader().setToolTipText(getFieldDescription(tc));
                    } catch (Exception e) {
                        // ignore this error
                    }
                }
            }
        }
    });

    //table.getColumnModel().addColumnModelListener(this);
    InputMap im = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);

    //  Override the default tab behaviour
    //  Tab to the next editable cell. When no editable cells goto next cell.
    final Action previousTabAction = table.getActionMap().get(im.get(tab));
    Action newTabAction = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            // maintain previous tab action procedure
            previousTabAction.actionPerformed(e);

            JTable table = (JTable) e.getSource();
            int row = table.getSelectedRow();
            int originalRow = row;
            int column = table.getSelectedColumn();
            int originalColumn = column;

            while (!table.isCellEditable(row, column)) {
                previousTabAction.actionPerformed(e);
                row = table.getSelectedRow();
                column = table.getSelectedColumn();

                //  Back to where we started, get out.
                if ((row == originalRow) && (column == originalColumn)) {
                    break;
                }
            }

            if (table.editCellAt(row, column)) {
                table.getEditorComponent().requestFocusInWindow();
            }
        }
    };

    table.getActionMap().put(im.get(tab), newTabAction);
    TableColumnModel model = table.getColumnModel();

    String previousColumnName = null;
    for (int columnIndex = 0; columnIndex < tableReferenceObject.getHeaders().size(); columnIndex++) {
        if (!model.getColumn(columnIndex).getHeaderValue().toString()
                .equals(TableReferenceObject.ROW_NO_TEXT)) {
            model.getColumn(columnIndex).setHeaderRenderer(columnRenderer);
            model.getColumn(columnIndex).setPreferredWidth(spreadsheetFunctions
                    .calcColWidths(model.getColumn(columnIndex).getHeaderValue().toString()));
            // add appropriate cell editor for cell.
            spreadsheetFunctions.addCellEditor(model.getColumn(columnIndex), previousColumnName);
            previousColumnName = model.getColumn(columnIndex).getHeaderValue().toString();
        } else {
            model.getColumn(columnIndex).setHeaderRenderer(new RowNumberCellRenderer());
        }
    }

    JTableHeader header = table.getTableHeader();
    header.setBackground(UIHelper.BG_COLOR);
    header.addMouseListener(new HeaderListener(header, columnRenderer));

    table.addNotify();
}

From source file:org.ngrinder.recorder.ui.RecordingControlPanel.java

protected JTable createFilterTables(ConnectionFilter connectionFilter) {
    final FilterTableModel dm = new FilterTableModel(connectionFilter);
    JTable jTable = new JTable(dm);
    TableColumnModel columnModel = jTable.getColumnModel();
    setColumnWidth(columnModel.getColumn(0), 30, 30, 30);
    setColumnWidth(columnModel.getColumn(2), 30, 50, 30);
    jTable.setRowSorter(new TableRowSorter<TableModel>(dm));
    createUpdateCheckScheduledTask(dm);//from   ww  w  .  j a  va 2 s  .c o  m
    return jTable;
}

From source file:org.openconcerto.task.TodoListPanel.java

private void setIconForColumn(int i, ImageIcon icon) {

    TableCellRenderer renderer = new JComponentTableCellRenderer(icon);
    TableColumnModel columnModel = this.t.getColumnModel();
    TableColumn column = columnModel.getColumn(i);
    column.setHeaderRenderer(renderer);//from   w w w . j a  va2  s.  c  om
    column.setMaxWidth(icon.getIconWidth() + 16);
    column.setMinWidth(icon.getIconWidth() + 8);
}

From source file:org.opendatakit.briefcase.ui.FormTransferTable.java

public FormTransferTable(JButton btnSelectOrClearAllForms, FormStatus.TransferType transferType,
        JButton btnTransfer) {/*from   ww  w  .  j  av a2 s.  c  o m*/
    super(new FormTransferTableModel(btnSelectOrClearAllForms, transferType, btnTransfer));
    AnnotationProcessor.process(this);// if not using AOP
    // set the button column renderer to a custom renderer
    getColumn(getColumnName(FormTransferTableModel.BUTTON_COLUMN)).setCellRenderer(new JTableButtonRenderer());
    addMouseListener(new JTableButtonMouseListener());

    TableColumnModel columns = this.getColumnModel();
    // determine width of "Selected" column header
    TableCellRenderer headerRenderer = this.getTableHeader().getDefaultRenderer();
    Component comp = headerRenderer.getTableCellRendererComponent(null, columns.getColumn(0).getHeaderValue(),
            false, false, 0, 0);
    int headerWidth = comp.getPreferredSize().width;
    columns.getColumn(0).setMinWidth(headerWidth);
    columns.getColumn(0).setMaxWidth(headerWidth);
    columns.getColumn(0).setPreferredWidth(headerWidth);

    // create a detail button (that we'll throw away)
    // so we can get the needed column and row dimensions.
    comp = new DetailButton(null);
    int buttonWidth = comp.getPreferredSize().width;
    int buttonHeight = comp.getPreferredSize().height;
    columns.getColumn(FormTransferTableModel.BUTTON_COLUMN).setMinWidth(buttonWidth);
    columns.getColumn(FormTransferTableModel.BUTTON_COLUMN).setMaxWidth(buttonWidth);
    columns.getColumn(FormTransferTableModel.BUTTON_COLUMN).setPreferredWidth(buttonWidth);

    // set the row height to be big enough to include a button and have space above and below it
    setRowHeight(buttonHeight); // btn used is arbitrary...

    // and scale the others to be wider...
    columns.getColumn(1).setPreferredWidth(5 * headerWidth);
    columns.getColumn(2).setPreferredWidth(5 * headerWidth);
    this.setFillsViewportHeight(true);
}

From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.FileSelectionTable.java

/** Formats the table model. */
private void formatTableModel() {
    final TableColumnModel tcm = table.getColumnModel();

    int index = 0;
    this.columnHeadings.clear();
    this.columnTooltips.clear();

    this.fileIndex = index++;
    this.columnHeadings.add(FILE_TEXT);
    this.columnTooltips.add(TOOLTIP_FILE);
    tcm.getColumn(this.fileIndex).setCellRenderer(new FileTableRendererFileColumn());

    if (model.isSingleGroup()) {
        this.groupIndex = null;
    } else {/*  w w  w.  j a v a 2s.c  o  m*/
        this.groupIndex = index++;
        this.columnHeadings.add(GROUP_TEXT);
        this.columnTooltips.add(TOOLTIP_GROUP);
    }

    if (model.canImportAs()) {
        this.ownerIndex = index++;
        this.columnHeadings.add(OWNER_TEXT);
        this.columnTooltips.add(TOOLTIP_OWNER);
    } else {
        this.ownerIndex = null;
    }

    this.containerIndex = index++;
    this.columnHeadings.add(CONTAINER_PROJECT_TEXT);
    this.columnTooltips.add(TOOLTIP_CONTAINER);
    tcm.getColumn(this.containerIndex).setCellRenderer(new FileTableRendererContainerColumn());

    this.folderAsDatasetIndex = index++;
    this.columnHeadings.add(FAD_TEXT);
    this.columnTooltips.add(TOOLTIP_FAD);
    setColumnAsBoolean(tcm.getColumn(this.folderAsDatasetIndex));

    this.sizeIndex = index++;
    this.columnHeadings.add(SIZE_TEXT);
    this.columnTooltips.add(TOOLTIP_SIZE);

    table.setTableHeader(new TooltipTableHeader(tcm, columnTooltips));

    final TableCellRenderer renderer = new MultilineHeaderSelectionRenderer();
    while (--index >= 0) {
        setHeaderRenderer(tcm, index, renderer);
    }

    table.getTableHeader().resizeAndRepaint();
    table.getTableHeader().setReorderingAllowed(false);
}