Example usage for javax.swing.table TableColumn setMinWidth

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

Introduction

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

Prototype

@BeanProperty(description = "The minimum width of the column.")
public void setMinWidth(int minWidth) 

Source Link

Document

Sets the TableColumn's minimum width to minWidth, adjusting the new minimum width if necessary to ensure that 0 <= minWidth <= maxWidth.

Usage

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);
    hidden.setPreferredWidth(2);/*from  w  w  w.j a  va2  s.c  o m*/
    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:com.github.fritaly.dualcommander.DirectoryBrowser.java

public DirectoryBrowser(UserPreferences preferences, File directory) {
    Validate.notNull(preferences, "The given user preferences are null");
    Validate.notNull(directory, "The given directory is null");
    Validate.isTrue(directory.exists(),//  w  w w  . ja  v  a 2  s  .  c  o  m
            String.format("The given directory '%s' doesn't exist", directory.getAbsolutePath()));
    Validate.isTrue(directory.isDirectory(),
            String.format("The given path '%s' doesn't denote a directory", directory.getAbsolutePath()));

    this.preferences = preferences;

    // Layout, columns & rows
    setLayout(new MigLayout("insets 0px", "[grow]", "[]1[grow]1[]"));

    this.tableModel = new FileTableModel(this);

    this.table = new JTable(tableModel);
    this.table.setBackground(Utils.getDefaultBackgroundColor());
    this.table.addKeyListener(this);
    this.table.addMouseListener(this);
    this.table.addFocusListener(this);
    this.table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    this.table.getSelectionModel().addListSelectionListener(this);

    // Listen to column event resize events
    final ColumnEventHelper eventHelper = new ColumnEventHelper(this);

    this.table.getColumnModel().addColumnModelListener(eventHelper);
    this.table.getTableHeader().addMouseListener(eventHelper);

    // Render the table headers with a bold font
    this.table.getTableHeader().setFont(Utils.getBoldFont(this.table.getTableHeader().getFont()));
    this.table.getTableHeader().setBackground(Utils.getDefaultBackgroundColor());
    this.table.getTableHeader().setDefaultRenderer(new TableHeaderRenderer());
    this.table.getTableHeader().addMouseListener(this);

    final TableColumn typeColumn = this.table.getColumn(FileTableModel.COLUMN_TYPE);
    typeColumn.setCellRenderer(new FileTypeRenderer());
    typeColumn.setResizable(false);
    typeColumn.setHeaderValue("");
    typeColumn.setMaxWidth(Icons.FOLDER_ICON.getIconWidth() + 5);

    final TableColumn fileColumn = this.table.getColumn(FileTableModel.COLUMN_NAME);
    fileColumn.setCellRenderer(new FileNameRenderer());
    fileColumn.setResizable(true);

    final TableColumn sizeColumn = this.table.getColumn(FileTableModel.COLUMN_SIZE);
    sizeColumn.setCellRenderer(new FileSizeRenderer());
    sizeColumn.setResizable(true);

    // Dynamically set the column to the correct size
    final TableColumn lastUpdateColumn = this.table.getColumn(FileTableModel.COLUMN_LAST_UPDATE);
    lastUpdateColumn.setCellRenderer(new LastUpdateRenderer());
    lastUpdateColumn.setResizable(false);
    lastUpdateColumn.setMaxWidth(Utils.getTimestampRenderWidth() + 5);
    lastUpdateColumn.setMinWidth(Utils.getTimestampRenderWidth() + 5);

    // Use a square border (not one with rounded corners)
    this.directoryButton.setBorder(Utils.createRaisedBevelBorder());
    this.directoryButton.setFont(Utils.getDefaultFont());
    this.directoryButton.setFocusable(false);
    this.directoryButton.setHorizontalAlignment(SwingConstants.LEFT);

    this.summary = new JLabel(" ");
    this.summary.setBorder(Utils.createRaisedBevelBorder());

    add(directoryButton, "grow, wrap");
    add(new JScrollPane(table), "grow, wrap");
    add(summary, "grow");

    // Set the directory (this will populate the table)
    setDirectory(directory);
}

From source file:net.pms.newgui.NavigationShareTab.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private void updateSharedFolders() {
    List<Path> folders = configuration.getSharedFolders();
    Vector<Vector<?>> newDataVector = new Vector<>();
    if (!folders.isEmpty()) {
        List<Path> foldersMonitored = configuration.getMonitoredFolders();
        for (Path folder : folders) {
            Vector rowVector = new Vector();
            rowVector.add(folder.toString());
            rowVector.add(Boolean.valueOf(foldersMonitored.contains(folder)));
            newDataVector.add(rowVector);
        }/*  ww  w  . j  a  v  a 2  s.  c  om*/
    }
    folderTableModel.setDataVector(newDataVector, FOLDERS_COLUMN_NAMES);
    TableColumn column = sharedFolders.getColumnModel().getColumn(0);
    column.setMinWidth(600);
}

From source file:es.emergya.ui.plugins.AdminPanel.java

/**
 * Cambia los datos que muestra la tabla al array que se le pase.
 * /*from   w w w .ja v a  2 s  . c o  m*/
 * Se aconseja que sean: * {@link Boolean} para valores si/no *
 * {@link AbstractAction} o subclases para botones * Numeros *
 * {@link String} para todo lo demas
 * 
 * @param data
 */
public void setTableData(final Object[][] data) {
    final Object[][] newData = new Object[data.length][];

    SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() {

        private MyTableModel model;

        @Override
        protected Object doInBackground() throws Exception {
            if (data == null) {
                return null;
            }
            model = (MyTableModel) table.getModel();

            synchronized (seleccion) {
                for (int i = 0; i < model.getRowCount(); i++) {
                    if ((Boolean) model.getValueAt(i, 0)) {
                        seleccion.add(model.getValueAt(i, columnToReselect));
                    }
                }
            }

            synchronized (seleccion) {
                for (int i = 0; i < data.length; i++) {
                    newData[i] = new Object[data[0].length + 1];
                    newData[i][0] = new Boolean(Authentication.isAuthenticated()
                            && seleccion.contains(data[i][columnToReselect - 1]));
                    for (int j = 0; j < data[i].length; j++) {
                        newData[i][j + 1] = data[i][j];
                    }
                }
            }
            return null;
        }

        protected void done() {
            model.updateRows(newData);

            if (!initialized) {
                table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
                for (Integer i : colsWidth.keySet()) {
                    try {
                        final TableColumn column = table.getColumnModel().getColumn(i);
                        final TableColumn filtro = filters.getColumnModel().getColumn(i);
                        column.setPreferredWidth(colsWidth.get(i));
                        column.setMinWidth(colsWidth.get(i));
                        column.setMaxWidth(colsWidth.get(i));
                        filtro.setPreferredWidth(colsWidth.get(i));
                        filtro.setMinWidth(colsWidth.get(i));
                        filtro.setMaxWidth(colsWidth.get(i));

                    } catch (Throwable t) {
                        log.error("Error al resizar las columnas: " + t);
                    }
                }

                TableColumn col = table.getColumnModel().getColumn(0);
                TableColumn fil = filters.getColumnModel().getColumn(0);
                log.trace("Resizando CheckBox");
                col.setMaxWidth(49);
                fil.setMaxWidth(49);

                int defaultWidth = 54;
                for (int i = 1; i < table.getColumnModel().getColumnCount() - 2; i++) {
                    col = table.getColumnModel().getColumn(i);
                    fil = filters.getColumnModel().getColumn(i);

                    final Class<?> columnClass = ((MyTableModel) table.getModel()).getColumnClass(i);
                    if (columnClass == JButton.class) {
                        log.trace("Resizando JButton");
                        col.setMaxWidth(defaultWidth);
                        fil.setMaxWidth(defaultWidth);
                    } else if (columnClass == Boolean.class) {
                        log.trace("Resizando CheckBox");
                        col.setMaxWidth(49);
                        fil.setMaxWidth(49);
                    }
                }

                if (getCanDelete()) {
                    col = table.getColumnModel().getColumn(table.getColumnModel().getColumnCount() - 2);
                    col.setMaxWidth(defaultWidth);
                    col.setPreferredWidth(defaultWidth);
                    col = table.getColumnModel().getColumn(table.getColumnModel().getColumnCount() - 1);
                    col.setMaxWidth(defaultWidth);
                    col.setPreferredWidth(defaultWidth);
                } else {
                    col = table.getColumnModel().getColumn(table.getColumnModel().getColumnCount() - 1);
                    col.setMaxWidth(defaultWidth * 2);
                    col.setPreferredWidth(defaultWidth * 2);
                }
                int max = filters.getColumnModel().getColumnCount() - 1;
                filters.getColumnModel().getColumn(max).setMaxWidth(61);
                filters.getColumnModel().getColumn(max - 1).setMaxWidth(32);
                filters.getColumnModel().getColumn(max - 2).setMaxWidth(32);
                initialized = true;
            }
        }
    };
    sw.execute();
}

From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowserAdvancedFilter.java

private void initContentSearchTable() {
    contentSearchTable/*from   w  ww.  ja  v a2 s  .c  om*/
            .setModel(new DefaultTableModel(new Object[][] {}, new String[] { "Content Type", "Contains" }) {
                public boolean isCellEditable(int rowIndex, int columnIndex) {
                    return true;
                }
            });

    contentSearchTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    contentSearchTable.setDragEnabled(false);
    contentSearchTable.setSortable(false);
    contentSearchTable.getTableHeader().setReorderingAllowed(false);

    contentSearchTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            deleteContentSearchButton.setEnabled(getSelectedRow(contentSearchTable) != -1);
        }
    });

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        contentSearchTable.setHighlighters(HighlighterFactory
                .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR));
    }

    TableColumn column = contentSearchTable.getColumnModel().getColumn(0);
    column.setCellRenderer(new MirthComboBoxTableCellRenderer(ContentType.getDisplayValues()));
    column.setCellEditor(new MirthComboBoxTableCellEditor(contentSearchTable, ContentType.getDisplayValues(), 1,
            false, null));
    column.setMinWidth(CONTENT_TYPE_COLUMN_WIDTH);
    column.setMaxWidth(CONTENT_TYPE_COLUMN_WIDTH);

    deleteContentSearchButton.setEnabled(false);
}

From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowserAdvancedFilter.java

private void initMetaDataSearchTable() {
    metaDataSearchTable.setModel(new DefaultTableModel(new Object[][] {},
            new String[] { "Metadata", "Operator", "Value", "Ignore Case" }) {
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            if (columnIndex == 3 && cachedMetaDataColumns.get(getValueAt(rowIndex, 0))
                    .getType() != MetaDataColumnType.STRING) {
                return false;
            }//w w  w  .j  a  va  2  s .c  o  m

            return true;
        }

        @Override
        public void setValueAt(Object value, int row, int column) {
            int metaDataColumnIndex = findColumn("Metadata");
            int operatorColumnIndex = findColumn("Operator");
            int valueColumnIndex = findColumn("Value");
            int ignoreCaseColumnIndex = findColumn("Ignore Case");

            if (column == valueColumnIndex) {
                MetaDataColumn metaDataColumn = cachedMetaDataColumns.get(getValueAt(row, metaDataColumnIndex));

                if (StringUtils.isNotEmpty((String) value)) {
                    try {
                        metaDataColumn.getType().castValue(value);
                    } catch (MetaDataColumnException e) {
                        parent.alertError(parent,
                                "Invalid value for column type " + metaDataColumn.getType().toString());
                        return;
                    }
                }
            } else if (column == metaDataColumnIndex) {
                if (!value.equals(getValueAt(row, metaDataColumnIndex))) {
                    MetaDataSearchOperator operator = MetaDataSearchOperator.EQUAL;

                    super.setValueAt(operator, row, operatorColumnIndex);

                    MetaDataColumn metaDataColumn = cachedMetaDataColumns.get(value);
                    if (metaDataColumn.getType() != MetaDataColumnType.STRING) {
                        super.setValueAt(Boolean.FALSE, row, ignoreCaseColumnIndex);
                    }
                }

                super.setValueAt("", row, valueColumnIndex);
            }
            super.setValueAt(value, row, column);
        }
    });

    metaDataSearchTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    metaDataSearchTable.setDragEnabled(false);
    metaDataSearchTable.setSortable(false);
    metaDataSearchTable.getTableHeader().setReorderingAllowed(false);

    addMetaDataSearchButton.setEnabled(!messageBrowser.getMetaDataColumns().isEmpty());

    metaDataSearchTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            deleteMetaDataSearchButton.setEnabled(getSelectedRow(metaDataSearchTable) != -1);
        }
    });

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        metaDataSearchTable.setHighlighters(HighlighterFactory
                .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR));
    }

    List<MetaDataColumn> metaDataColumns = messageBrowser.getMetaDataColumns();
    cachedMetaDataColumns.clear();

    String[] metaDataNames = new String[metaDataColumns.size()];
    for (int i = 0; i < metaDataColumns.size(); i++) {
        String columnName = metaDataColumns.get(i).getName();
        metaDataNames[i] = columnName;
        cachedMetaDataColumns.put(columnName, metaDataColumns.get(i));
    }

    MirthComboBoxTableCellEditor metaDataEditor = new MirthComboBoxTableCellEditor(metaDataSearchTable,
            metaDataNames, 1, false, null);
    metaDataEditor.getComboBox().setAutoResizeDropdown(true);

    TableColumn metaDataColumn = metaDataSearchTable.getColumnModel().getColumn(0);
    metaDataColumn.setCellRenderer(new MirthComboBoxTableCellRenderer(metaDataNames));
    metaDataColumn.setCellEditor(metaDataEditor);
    metaDataColumn.setMinWidth(METADATA_NAME_COLUMN_WIDTH);
    metaDataColumn.setMaxWidth(METADATA_NAME_COLUMN_WIDTH * 2);
    metaDataColumn.setPreferredWidth(METADATA_NAME_COLUMN_WIDTH);

    // Need to create this custom editor since the combo box values are dynamic based on metadata column type. 
    MirthComboBoxTableCellEditor operatorEditor = new MirthComboBoxTableCellEditor(metaDataSearchTable,
            MetaDataSearchOperator.values(), 1, false, null) {

        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
                int column) {

            MetaDataColumn metaDataColumn = cachedMetaDataColumns.get(table.getValueAt(row, 0));

            comboBox.setModel(new DefaultComboBoxModel(
                    MetaDataSearchOperator.valuesForColumnType(metaDataColumn.getType())));

            return super.getTableCellEditorComponent(table, value, isSelected, row, column);
        }

    };

    TableColumn operatorColumn = metaDataSearchTable.getColumnModel().getColumn(1);
    operatorColumn.setCellRenderer(new MirthComboBoxTableCellRenderer(MetaDataSearchOperator.values()));
    operatorColumn.setCellEditor(operatorEditor);
    operatorColumn.setMinWidth(METADATA_OPERATOR_COLUMN_WIDTH);
    operatorColumn.setMaxWidth(METADATA_OPERATOR_COLUMN_WIDTH);

    TableColumn caseColumn = metaDataSearchTable.getColumnModel().getColumn(3);
    caseColumn.setMinWidth(METADATA_CASE_COLUMN_WIDTH);
    caseColumn.setMaxWidth(METADATA_CASE_COLUMN_WIDTH);

    deleteMetaDataSearchButton.setEnabled(false);
}

From source file:com.emental.mindraider.ui.outline.OutlineJPanel.java

/**
 * Creates notebook outline.//from  www  .  ja va2  s. c o m
 */
private OutlineJPanel() {
    setDoubleBuffered(true);
    setLayout(new BorderLayout());

    /*
     * toolbar
     */

    JToolBar toolbar = createToolbar();

    /*
     * tree
     */

    // tree table itself
    outlineTableTree = OutlineTreeInstance.getInstance();
    outlineTableTreeModel = new NotebookOutlineModel(outlineTableTree.getOutlineRoot());
    treeTable = new JTreeTable(outlineTableTreeModel);
    treeTable.tree.addTreeSelectionListener(new TreeSelectionListenerImplementation());
    // add key listener
    treeTable.addKeyListener(new KeyListenerImplementation());

    // label column
    TableColumn tableColumn = treeTable
            .getColumn(NotebookOutlineModel.columnNames[NotebookOutlineModel.COLUMN_LABEL]);
    tableColumn.setMaxWidth(LABEL_COLUMN_MAX_WIDTH);
    tableColumn.setMinWidth(0);
    tableColumn.setPreferredWidth(LABEL_COLUMN_PREFERRED_WIDTH);
    // date column
    tableColumn = treeTable.getColumn(NotebookOutlineModel.columnNames[NotebookOutlineModel.COLUMN_CREATED]);
    tableColumn.setMaxWidth(DATE_COLUMN_MAX_WIDTH);
    tableColumn.setMinWidth(0);
    tableColumn.setPreferredWidth(DATE_COLUMN_PREFERRED_WIDTH);
    // and the rest will be annotation
    JScrollPane treeTableScrollPane = new JScrollPane(treeTable);

    // outline treetabble + toolbar panel
    JPanel treeAndToolbarPanel = new JPanel(new BorderLayout());
    treeAndToolbarPanel.add(toolbar, BorderLayout.NORTH);
    treeAndToolbarPanel.add(treeTableScrollPane, BorderLayout.CENTER);

    /*
     * outline / list tabbed pane
     */

    outlineAndTreeTabbedPane = new JTabbedPane(JTabbedPane.BOTTOM);
    outlineAndTreeTabbedPane.add(treeAndToolbarPanel, "Outline");
    outlineSorterJPanel = new OutlineSorterJPanel();
    outlineAndTreeTabbedPane.add(outlineSorterJPanel, "Sorter");
    outlineArchiveJPanel = new OutlineArchiveJPanel();
    outlineAndTreeTabbedPane.add(outlineArchiveJPanel, "Archive");

    /*
     * concept sidebar
     */

    conceptJPanel = (ConceptJPanel) MindRaiderSpringContext.getCtx().getBean("conceptPanel");

    /*
     * vertical split of notebook outline and RDF graph
     */

    treeAndSpidersSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    treeAndSpidersSplit.setContinuousLayout(true);
    treeAndSpidersSplit.setOneTouchExpandable(true);
    treeAndSpidersSplit.setDividerLocation(200);
    treeAndSpidersSplit.setLastDividerLocation(150);
    treeAndSpidersSplit.setDividerSize(6);
    treeAndSpidersSplit.add(outlineAndTreeTabbedPane);

    // spiders & tags visual navigation
    spidersAndTagsTabs = new JTabbedPane(JTabbedPane.BOTTOM);
    if (MindRaider.profile.isEnableSpiders()) {
        // notebook mind map
        spidersAndTagsTabs.addTab("Mind Map", MindRaider.spidersGraph.getPanel()); // TODO bundle
    }
    // global tags
    spidersAndTagsTabs.addTab("Tag Cloud", MindRaider.tagCustodian.getPanel()); // TODO bundle
    // global mind map
    //spidersAndTagsTabs.addTab("Global Mind Map",new JPanel()); // TODO bundle

    // lazy spiders rendering
    spidersAndTagsTabs.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent changeEvent) {
            JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent.getSource();
            if (sourceTabbedPane.getSelectedIndex() == 0) {
                MindRaider.spidersGraph.renderModel();
            }
        }
    });

    if (!new ConfigurationBean().isDefaultTabMindMap()) {
        spidersAndTagsTabs.setSelectedIndex(1);
    }

    MindRaider.tagCustodian.redraw();

    // add spiders panel
    treeAndSpidersSplit.add(spidersAndTagsTabs);

    /*
     * horizontal split of outline/graph slit and concept sidebar
     */

    rightSiderbarSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treeAndSpidersSplit, conceptJPanel);
    rightSiderbarSplitPane.setOneTouchExpandable(true);
    rightSiderbarSplitPane.setContinuousLayout(true);
    rightSiderbarSplitPane.setDividerLocation(500);
    rightSiderbarSplitPane.setLastDividerLocation(500);
    rightSiderbarSplitPane.setDividerSize(6);

    add(rightSiderbarSplitPane);
}

From source file:display.containers.FileManager.java

private void setColumnWidth(int column, int width) {
    TableColumn tableColumn = table.getColumnModel().getColumn(column);
    if (width < 0) {
        // use the preferred width of the header..
        JLabel label = new JLabel((String) tableColumn.getHeaderValue());
        Dimension preferred = label.getPreferredSize();
        // altered 10->14 as per camickr comment.
        width = (int) preferred.getWidth() + 14;
    }/*from w w w .  j a  v a2  s.co  m*/
    tableColumn.setPreferredWidth(width);
    tableColumn.setMaxWidth(width);
    tableColumn.setMinWidth(width);
}

From source file:org.jets3t.apps.cockpit.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.
 *///ww  w. j  av a  2  s .  c o  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);
                    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();
                    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);
                }
            }

            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:net.sourceforge.pmd.cpd.GUI.java

private void setListDataFrom(List<Match> matches) {

    resultsTable.setModel(tableModelFrom(matches));

    TableColumnModel colModel = resultsTable.getColumnModel();
    TableColumn column;
    int width;//from www . j a  v a2  s  .  c o  m

    for (int i = 0; i < matchColumns.length; i++) {
        if (matchColumns[i].width() > 0) {
            column = colModel.getColumn(i);
            width = matchColumns[i].width();
            column.setPreferredWidth(width);
            column.setMinWidth(width);
            column.setMaxWidth(width);
        }
    }
}