Example usage for javax.swing.table TableColumn setPreferredWidth

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

Introduction

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

Prototype

@BeanProperty(description = "The preferred width of the column.")
public void setPreferredWidth(int preferredWidth) 

Source Link

Document

Sets this column's preferred width to preferredWidth.

Usage

From source file:org.datanucleus.ide.idea.ui.DNEConfigForm.java

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

    ///*from w  ww  . j a v a2  s.  co  m*/
    // 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();
    this.persistenceImplComboBox.removeAllItems();
    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());

    if (enhancerSupport.getVersion() == EnhancerSupportVersion.V1_1_X) {
        this.depProjectModuleRadioButton.setSelected(!data.isDependenciesManual());
        this.depManualRadioButton.setSelected(data.isDependenciesManual());
        this.depManualRadioButton.setEnabled(true);
        this.depManualUnsupportedLabel.setVisible(false);
    } else {
        this.depProjectModuleRadioButton.setSelected(true);
        this.depManualRadioButton.setSelected(false);
        this.depManualRadioButton.setEnabled(false);
        this.depManualUnsupportedLabel.setVisible(true);
    }

    this.dependenciesAddDeletePanel.resetDependencyList(enhancerSupport.getId(), persistenceApi,
            data.getDependencies());
}

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

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

    ////w ww .  ja v  a2  s .  co m
    // 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.dc.file.search.ui.DashboardForm.java

private void initCommentResultsTable() {
    txtCommentThread.setText("");
    Object[][] initData = {};// www.  j  a  v  a 2s  .  co  m
    DefaultTableModel commentModel = new DefaultTableModel(initData, commentColumnNames);
    tblComments.setModel(commentModel);
    tblComments.setRowHeight(32);

    TableColumn commentRatingColumn = tblComments.getColumnModel().getColumn(COMMENT_RATING_COL_INDEX);
    commentRatingColumn.setCellRenderer(new StarRatingsRenderer(tblComments, StarRatingsType.COMMENT));
    commentRatingColumn.setCellEditor(new StarRatingsEditor(tblComments, StarRatingsType.COMMENT));
    commentRatingColumn.setPreferredWidth(30);

    TableColumn commentReply = tblComments.getColumnModel().getColumn(COMMENT_REPLY_COL_INDEX);
    commentReply.setCellRenderer(new ButtonRenderer(tblComments));
    commentReply.setCellEditor(new ButtonEditor(tblComments));

    tblComments.getSelectionModel().addListSelectionListener(event -> {
        if (tblComments.getSelectedRow() >= 0) {
            txtCommentThread.setText("");
            DFile dFile = resultFiles.get(selectedFile);
            String commentId = tblComments.getValueAt(tblComments.getSelectedRow(), 0).toString();
            Comment parentComment = null;
            List<Comment> comments = dFile.getComments();
            for (Comment c : comments) {
                if (c.getCommentId().equals(commentId)) {
                    parentComment = c;
                    break;
                }
            }
            if (parentComment == null) {
                return;
            }
            StringBuilder stringBuilder = new StringBuilder();
            for (Comment replyComment : parentComment.getReplies()) {
                stringBuilder.append(replyComment.getUserName());
                stringBuilder.append(": ");
                stringBuilder.append(replyComment.getText());
                stringBuilder.append("\n----------------------------------\n");
            }
            txtCommentThread.setText(stringBuilder.toString());
        }
    });
}

From source file:org.dc.file.search.ui.DashboardForm.java

private void initSearchResultsTable() {
    Object[][] initData = {};/*  w  w w.j  av a 2 s .  c  om*/
    DefaultTableModel searchModel = new DefaultTableModel(initData, searchColumnNames);
    tblSearchResults.setModel(searchModel);
    tblSearchResults.setRowHeight(32);

    tblSearchResults.getColumnModel().getColumn(PEER_COL_INDEX).setPreferredWidth(30);
    tblSearchResults.getColumnModel().getColumn(HOP_COUNT_COL_INDEX).setPreferredWidth(20);
    tblSearchResults.getColumnModel().getColumn(FILE_COL_INDEX).setPreferredWidth(20);

    TableColumn starRatingsColumn = tblSearchResults.getColumnModel().getColumn(STAR_RATINGS_COL_INDEX);
    starRatingsColumn.setCellRenderer(new StarRatingsRenderer(tblSearchResults, StarRatingsType.FILE));
    starRatingsColumn.setCellEditor(new StarRatingsEditor(tblSearchResults, StarRatingsType.FILE));
    starRatingsColumn.setPreferredWidth(30);

    tblSearchResults.getSelectionModel().addListSelectionListener(event -> {
        if (tblSearchResults.getSelectedRow() >= 0) {
            updateCommentTable();
        }
    });
}

From source file:org.ecoinformatics.seek.ecogrid.ServicesDisplayPanel.java

private void initColumnWidth() {
    TableColumn column = null;
    for (int i = 0; i < tableModel.getColumnCount(); i++) {
        column = table.getColumnModel().getColumn(i);
        column.setPreferredWidth(CELLPREFERREDWIDTH);
        // column.setMaxWidth(CELLMAXWIDTH);
        // column.setMinWidth(CELLMINIWIDTH);
    } // for/*from w w w  .j  av  a  2 s  . c  o  m*/
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.s3.Cockpit.java

/**
 * Lists the buckets in the user's S3 account and refreshes the GUI to display
 * these buckets. Any buckets or objects already listed in the GUI are cleared first.
 *///from w w w . j  av  a 2s . co m
private void listAllBuckets() {
    // Remove current bucket and object data from models.
    cachedBuckets.clear();
    bucketsTable.clearSelection();
    bucketTableModel.removeAllBuckets();
    objectTableModel.removeAllObjects();
    final Cockpit myself = this;

    // This is all very convoluted. This was necessary so we can display the status dialog box.
    runInBackgroundThread(new Runnable() {
        public void run() {
            if (!cloudFrontMembershipChecked) {
                // Check whether the user is signed-up for CloudFront.
                startProgressDialog("Checking for CloudFront account membership");
                try {
                    cloudFrontService = new CloudFrontService(s3ServiceMulti.getAWSCredentials(),
                            APPLICATION_DESCRIPTION, myself, null, null);
                    cloudFrontService.listDistributions();
                } catch (CloudFrontServiceException e) {
                    stopProgressDialog();

                    if ("OptInRequired".equals(e.getErrorCode())) {
                        log.debug("Your AWS account is not subscribed to the Amazon CloudFront service, "
                                + "you will not be able to manage distributions");
                    }
                    cloudFrontService = null;
                } finally {
                    stopProgressDialog();

                    try {
                        SwingUtilities.invokeAndWait(new Runnable() {
                            public void run() {
                                cloudFrontMembershipChecked = true;

                                // Update the bucket table to show, or not show, distributions
                                bucketTableModel = new BucketTableModel(cloudFrontService != null);
                                bucketTableModelSorter = new TableSorter(bucketTableModel);
                                bucketsTable.setModel(bucketTableModelSorter);
                                bucketTableModelSorter.setTableHeader(bucketsTable.getTableHeader());

                                if (cloudFrontService != null) {
                                    // Set column width for Cloud Front distributions indicator.
                                    TableColumn distributionFlagColumn = bucketsTable.getColumnModel()
                                            .getColumn(1);
                                    int distributionFlagColumnWidth = 18;
                                    distributionFlagColumn.setPreferredWidth(distributionFlagColumnWidth);
                                    distributionFlagColumn.setMaxWidth(distributionFlagColumnWidth);
                                    distributionFlagColumn.setMinWidth(0);
                                }

                                manageDistributionsMenuItem.setEnabled(cloudFrontService != null);

                            }
                        });
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }

            startProgressDialog("Listing buckets for " + s3ServiceMulti.getAWSCredentials().getAccessKey());
            try {
                final S3Bucket[] buckets = s3ServiceMulti.getS3Service().listAllBuckets();

                // Lookup user's CloudFront distributions.
                Distribution[] distributions = new Distribution[] {};
                if (cloudFrontService != null) {
                    updateProgressDialog(
                            "Listing distributions for " + cloudFrontService.getAWSCredentials().getAccessKey(),
                            "", 0);
                    distributions = cloudFrontService.listDistributions();
                }
                final Distribution[] finalDistributions = distributions;

                runInDispatcherThreadImmediately(new Runnable() {
                    public void run() {
                        for (int i = 0; i < buckets.length; i++) {
                            // Determine whether each bucket has one or more CloudFront distributions.
                            boolean bucketHasDistribution = false;
                            for (int j = 0; j < finalDistributions.length; j++) {
                                if (finalDistributions[j].getOrigin()
                                        .equals(buckets[i].getName() + ".s3.amazonaws.com")) {
                                    bucketHasDistribution = true;
                                }
                            }

                            bucketTableModel.addBucket(buckets[i], bucketHasDistribution);

                            if (i == 0) {
                                ownerFrame.setTitle(
                                        APPLICATION_TITLE + " : " + buckets[i].getOwner().getDisplayName());
                            }
                        }
                    }
                });
            } catch (final Exception e) {
                stopProgressDialog();

                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        logoutEvent();

                        String message = "Unable to list your buckets in S3, please log in again";
                        log.error(message, e);
                        ErrorDialog.showDialog(ownerFrame, null, message, e);

                        loginEvent(null);
                    }
                });
            } finally {
                stopProgressDialog();
            }
        };
    });
}

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

private void prepareTable() {
    TableColumnModel tcm = table.getColumnModel();
    TableColumn col = tcm.getColumn(0);
    col.setPreferredWidth(140);

    col = tcm.getColumn(1);//from   w ww.  j  a  v  a  2s.c  o  m
    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.executequery.gui.resultset.ResultSetTable.java

public void setTableColumnWidth(int columnWidth) {

    TableColumnModel tcm = getColumnModel();
    if (columnWidth != 75) {

        TableColumn col = null;
        for (Enumeration<TableColumn> i = tcm.getColumns(); i.hasMoreElements();) {
            col = i.nextElement();//from   w  w w.ja  va 2s. c  om
            col.setWidth(columnWidth);
            col.setPreferredWidth(columnWidth);
        }

    }
}

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

/**
 * Adds a column to the table with a specified name
 *
 * @param headerLabel - name of column to be added
 *//*from   w  w w. j a  va 2s. c  om*/
public TableColumn addColumn(Object headerLabel, boolean required) {
    SpreadsheetModel model = (SpreadsheetModel) spreadsheet.getTable().getModel();
    TableColumn newColumn = new TableColumn(spreadsheet.getTable().getModel().getColumnCount());
    newColumn.setHeaderValue(headerLabel);
    newColumn.setPreferredWidth(calcColWidths(headerLabel.toString()));
    newColumn.setHeaderRenderer(spreadsheet.columnRenderer);

    // add a cell editor (if available to the column)
    addCellEditor(newColumn);

    model.addToColumns(headerLabel.toString());
    model.addColumn(headerLabel.toString());

    spreadsheet.getTable().addColumn(newColumn);

    addFieldToRequiredCellRendererIfVisible(required, newColumn.getModelIndex());

    model.fireTableStructureChanged();
    model.fireTableDataChanged();

    if (spreadsheet.getTable().getRowCount() > 0) {
        spreadsheet.getTable().setValueAt(
                spreadsheet.getTableReferenceObject().getDefaultValue(headerLabel.toString()), 0,
                spreadsheet.getTable().getColumnCount() - 1);
        copyColumnDownwards(0, spreadsheet.getTable().getColumnCount() - 1);
        spreadsheet.getTableReferenceObject().getDefaultValue(headerLabel.toString());
    }

    spreadsheet.getTable().addNotify();

    return newColumn;
}

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

/**
 * Add a column after the currently selected column
 *
 * @param headerLabel             - name of column to add.
 * @param fixedVal                - initial value to populate column with, if any.
 * @param currentlySelectedColumn - place in table to add the column after.
 *//*from ww w  .ja v a2s .c om*/
public TableColumn addColumnAfterPosition(Object headerLabel, String fixedVal, boolean required,
        int currentlySelectedColumn) {

    if (currentlySelectedColumn == -1) {
        currentlySelectedColumn = (spreadsheet.getTable().getSelectedColumn() == -1)
                ? (spreadsheet.getTable().getColumnCount() - 1)
                : spreadsheet.getTable().getSelectedColumn();
    }

    SpreadsheetModel model = (SpreadsheetModel) spreadsheet.getTable().getModel();

    int columnCount = spreadsheet.getTable().getModel().getColumnCount();

    TableColumn col = new TableColumn(columnCount);
    col.setHeaderValue(headerLabel);
    col.setPreferredWidth(calcColWidths(headerLabel.toString()));
    col.setHeaderRenderer(spreadsheet.columnRenderer);

    addFieldToRequiredCellRendererIfVisible(required, columnCount);

    addCellEditor(col);

    model.addToColumns(headerLabel.toString());
    model.addColumn(col);

    spreadsheet.getTable().addColumn(col);

    model.fireTableStructureChanged();
    model.fireTableDataChanged();

    // now move the column into its correct position
    int stopValue = headerLabel.toString().equals("Unit")
            ? (spreadsheet.previouslyAddedCharacteristicPosition + 1)
            : (currentlySelectedColumn + 1);

    for (int i = spreadsheet.getTable().getColumnCount() - 1; i > stopValue; i--) {
        spreadsheet.getTable().getColumnModel().moveColumn(i - 1, i);
    }

    addDependentColumn(headerLabel, currentlySelectedColumn, col);

    if (headerLabel.toString().contains("Characteristics") || headerLabel.toString().contains("Factor")
            || headerLabel.toString().contains("Parameter")) {
        spreadsheet.previouslyAddedCharacteristicPosition = stopValue;
    }

    propagateDefaultValue(fixedVal, stopValue);

    spreadsheet.getTable().addNotify();

    return col;
}