Example usage for javax.swing JTable getTableHeader

List of usage examples for javax.swing JTable getTableHeader

Introduction

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

Prototype

public JTableHeader getTableHeader() 

Source Link

Document

Returns the tableHeader used by this JTable.

Usage

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

/**
 * // w w  w.j av  a  2  s. c  o m
 * @param columnNames
 *            nombres de las columnas de la tabla
 * @param filterOptions
 *            lista de opciones de un combobox. Si esta vacio entonces es un
 *            textfield
 * @param noFiltrarAction
 * @param filtrarAction
 */
public void generateTable(String[] columnNames, Object[][] filterOptions,
        AdminPanel.NoFiltrarAction noFiltrarAction, AdminPanel.FiltrarAction filtrarAction) {

    if (columnNames == null) {
        columnNames = new String[] {};
    }
    if (filterOptions == null) {
        filterOptions = new Object[][] {};
    }

    String filterString = "[";
    for (Object[] o : filterOptions) {
        filterString += Arrays.toString(o) + " ";
    }
    filterString += "]";

    log.debug("generateTable( columnNames = " + Arrays.toString(columnNames) + ", filterOptions = "
            + filterString + ")");

    tablePanel.removeAll();
    int columnNamesLength = columnNames.length;
    if (!getCanDelete())
        columnNamesLength++;
    MyTableModel dataModel = new MyTableModel(1, columnNamesLength + 2) {

        private static final long serialVersionUID = 1348355328684460769L;

        @Override
        public boolean isCellEditable(int row, int column) {
            return column != 0 && !invisibleFilterCols.contains(column);
        }
    };
    filters = new JTable(dataModel) {

        private static final long serialVersionUID = -8266991359840905405L;

        @Override
        public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
            Component c = super.prepareRenderer(renderer, row, column);

            if (isCellEditable(row, column) && column != getColumnCount() - 1) {
                if (c instanceof JTextField) {
                    ((JTextField) c).setBorder(new MatteBorder(1, 1, 1, 1, Color.BLACK));
                } else if (c instanceof JComboBox) {
                    ((JComboBox) c).setBorder(new MatteBorder(1, 1, 1, 1, Color.BLACK));
                } else if (c instanceof JLabel) {
                    ((JLabel) c).setBorder(new MatteBorder(1, 1, 1, 1, Color.BLACK));
                }
            }
            return c;
        }
    };
    filters.setSurrendersFocusOnKeystroke(true);
    filters.setShowGrid(false);
    filters.setRowHeight(22);
    filters.setOpaque(false);

    for (Integer i = 0; i < filterOptions.length; i++) {
        final Object[] items = filterOptions[i];
        if (items != null && items.length > 1) {
            setComboBoxEditor(i, items);
        } else {
            final DefaultCellEditor defaultCellEditor = new DefaultCellEditor(new JTextField());
            defaultCellEditor.setClickCountToStart(1);
            filters.getColumnModel().getColumn(i + 1).setCellEditor(defaultCellEditor);
        }
    }

    filters.setRowSelectionAllowed(false);
    filters.setDragEnabled(false);
    filters.setColumnSelectionAllowed(false);
    filters.setDefaultEditor(JButton.class, new JButtonCellEditor());

    filters.setDefaultRenderer(Object.class, new DefaultTableRenderer() {
        private static final long serialVersionUID = -4811729559786534118L;

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (invisibleFilterCols.contains(column))
                c = new JLabel("");
            return c;
        }

    });

    filters.setDefaultRenderer(JButton.class, new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            JButton b = (JButton) value;
            b.setBorderPainted(false);
            b.setContentAreaFilled(false);
            return b;
        }
    });
    filters.setDefaultRenderer(JLabel.class, new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            return (JLabel) value;
        }
    });
    filters.setDefaultEditor(JButton.class, new JButtonCellEditor());
    filters.getModel().setValueAt(new JLabel(""), 0, 0);
    JButton jButton2 = new JButton(noFiltrarAction);
    JButton jButton = new JButton(filtrarAction);
    jButton.setBorderPainted(false);
    jButton2.setBorderPainted(false);
    jButton.setContentAreaFilled(false);
    jButton2.setContentAreaFilled(false);
    if (jButton.getIcon() != null)
        jButton.setPreferredSize(
                new Dimension(jButton.getIcon().getIconWidth(), jButton.getIcon().getIconHeight()));
    if (jButton2.getIcon() != null)
        jButton2.setPreferredSize(
                new Dimension(jButton2.getIcon().getIconWidth(), jButton2.getIcon().getIconHeight()));

    filters.getModel().setValueAt(jButton, 0, columnNamesLength - 1);
    filters.getColumnModel().getColumn(columnNamesLength - 1).setMinWidth(jButton.getWidth() + 24);
    filters.getModel().setValueAt(jButton2, 0, columnNamesLength);
    filters.getColumnModel().getColumn(columnNamesLength).setMinWidth(jButton2.getWidth() + 14);
    cuenta.setHorizontalAlignment(JLabel.CENTER);
    cuenta.setText("?/?");
    filters.getModel().setValueAt(cuenta, 0, columnNamesLength + 1);

    tablePanel.add(filters, BorderLayout.NORTH);

    Vector<String> headers = new Vector<String>();
    headers.add("");
    headers.addAll(Arrays.asList(columnNames));
    MyTableModel model = new MyTableModel(headers, 0);
    table = new JTable(model) {

        private static final long serialVersionUID = 949284378605881770L;
        private int highLightedRow = -1;
        private Rectangle dirtyRegion = null;

        public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
            Component c = super.prepareRenderer(renderer, row, column);
            try {
                if (AdminPanel.this.myRendererColoring != null)
                    c.setBackground(AdminPanel.this.myRendererColoring
                            .getColor(AdminPanel.this.table.getValueAt(row, 1)));
            } catch (Throwable t) {
                log.error("Error al colorear la celda: " + t);
            }
            return c;
        }

        @Override
        protected void processMouseMotionEvent(MouseEvent e) {
            try {
                int row = rowAtPoint(e.getPoint());
                Graphics g = getGraphics();
                if (row == -1) {
                    highLightedRow = -1;
                }

                // row changed
                if (highLightedRow != row) {
                    if (null != dirtyRegion) {
                        paintImmediately(dirtyRegion);
                    }
                    for (int j = 0; j < getRowCount(); j++) {
                        if (row == j) {
                            // highlight
                            Rectangle firstRowRect = getCellRect(row, 0, false);
                            Rectangle lastRowRect = getCellRect(row, getColumnCount() - 1, false);
                            dirtyRegion = firstRowRect.union(lastRowRect);
                            g.setColor(new Color(0xff, 0xff, 0, 100));
                            g.fillRect((int) dirtyRegion.getX(), (int) dirtyRegion.getY(),
                                    (int) dirtyRegion.getWidth(), (int) dirtyRegion.getHeight());
                            highLightedRow = row;
                        }

                    }
                }
            } catch (Exception ex) {
            }
            super.processMouseMotionEvent(e);
        }
    };

    table.setRowHeight(22);

    table.setOpaque(false);
    // table.setAutoCreateRowSorter(true);

    table.setDragEnabled(false);
    table.getTableHeader().setReorderingAllowed(false);
    table.getTableHeader().setResizingAllowed(false);

    table.setDefaultEditor(JButton.class, new JButtonCellEditor());
    table.setDefaultRenderer(JButton.class, new TableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            JButton b = (JButton) value;
            if (b != null) {
                b.setBorderPainted(false);
                b.setContentAreaFilled(false);
            }
            return b;
        }
    });

    JScrollPane jScrollPane = new JScrollPane(table);
    jScrollPane.setOpaque(false);
    jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    jScrollPane.getViewport().setOpaque(false);
    tablePanel.add(jScrollPane, BorderLayout.CENTER);
}

From source file:op.tools.SYSTools.java

public static void packColumn(JTable table, int vColIndex, int margin) {
    TableModel model = table.getModel();
    DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
    TableColumn col = colModel.getColumn(vColIndex);
    int width = 0;

    // Get width of column header
    TableCellRenderer renderer = col.getHeaderRenderer();
    if (renderer == null) {
        renderer = table.getTableHeader().getDefaultRenderer();
    }//  www  . j  a  v a2 s .c  o  m
    Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
    width = comp.getPreferredSize().width;

    // Get maximum width of column data
    for (int r = 0; r < table.getRowCount(); r++) {
        renderer = table.getCellRenderer(r, vColIndex);
        comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, vColIndex), false, false, r,
                vColIndex);
        width = Math.max(width, comp.getPreferredSize().width);
    }

    // Add margin
    width += 2 * margin;
    // Set the width
    col.setPreferredWidth(width);

    OPDE.debug("packColumn/3: col=" + vColIndex + "  width=" + width);
}

From source file:org.apache.cayenne.modeler.editor.AbstractCallbackMethodsTab.java

private void addButtonAtHeader(JTable table, JButton button, ActionListener buttonListener,
        ImageIcon buttonIcon) {// w w  w .java 2s  .co m
    PanelBuilder builder = new PanelBuilder(new FormLayout("left:10dlu, 2dlu", "center:10dlu"));
    CellConstraints cc = new CellConstraints();

    button.setIcon(buttonIcon);
    button.setOpaque(false);
    button.setBorderPainted(false);
    button.setContentAreaFilled(false);
    button.addActionListener(buttonListener);

    builder.add(button, cc.xy(1, 1));

    JPanel buttonPanel = builder.getPanel();
    buttonPanel.setOpaque(false);

    JTableHeader header = table.getTableHeader();
    header.setLayout(new BorderLayout());
    header.setReorderingAllowed(false);
    header.setPreferredSize(new Dimension(150, 20));
    header.add(buttonPanel, BorderLayout.EAST);
}

From source file:org.ecoinformatics.seek.datasource.eml.eml2.Eml200DataSource.java

public void preview() {

    String displayText = "PREVIEW NOT IMPLEMENTED FOR THIS ACTOR";
    JFrame frame = new JFrame(this.getName() + " Preview");
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    JPanel panel = new JPanel(new BorderLayout());
    JScrollPane scrollPane = null;
    JTable jtable = null;

    try {//from w  w  w .j  a  v  a2  s.c o  m

        // set everything up (datawise)
        this.initialize();

        // check the entity - different displays for different formats
        // Compressed file
        if (this._selectedTableEntity.getHasGZipDataFile() || this._selectedTableEntity.getHasTarDataFile()
                || this._selectedTableEntity.getHasZipDataFile()) {
            displayText = "Selected entity is a compressed file.  \n"
                    + "Preview not implemented for output format: " + this.dataOutputFormat.getExpression();
            if (this._dataOutputFormat instanceof Eml200DataOutputFormatUnzippedFileName) {
                Eml200DataOutputFormatUnzippedFileName temp = (Eml200DataOutputFormatUnzippedFileName) this._dataOutputFormat;
                displayText = "Files: \n";
                for (int i = 0; i < temp.getTargetFilePathInZip().length; i++) {
                    displayText += temp.getTargetFilePathInZip()[i] + "\n";
                }
            }

        }
        // SPATIALRASTERENTITY or SPATIALVECTORENTITY are "image entities"
        // as far as the parser is concerned
        else if (this._selectedTableEntity.getIsImageEntity()) {
            // use the content of the cache file
            displayText = new String(this.getSelectedCachedDataItem().getData());
        }
        // TABLEENTITY
        else {
            // holds the rows for the table on disk with some in memory
            String vectorTempDir = DotKeplerManager.getInstance().getCacheDirString();
            // + "vector"
            // + File.separator;
            PersistentVector rowData = new PersistentVector(vectorTempDir);

            // go through the rows and add them to the persistent vector
            // model
            Vector row = this.gotRowVectorFromSource();
            while (!row.isEmpty()) {
                rowData.addElement(row);
                row = this.gotRowVectorFromSource();
            }
            // the column headers for the table
            Vector columns = this.getColumns();

            /*
             * with java 6, there is a more built-in sorting mechanism that
             * does not require the custom table sorter class
             */
            TableModel tableModel = new PersistentTableModel(rowData, columns);
            TableSorter tableSorter = new TableSorter(tableModel);
            jtable = new JTable(tableSorter) {
                // make this table read-only by overriding the default
                // implementation
                public boolean isCellEditable(int row, int col) {
                    return false;
                }
            };
            // sets up the listeners for sorting and such
            tableSorter.setTableHeader(jtable.getTableHeader());
            // set up the listener to trash persisted data when done
            frame.addWindowListener(new PersistentTableModelWindowListener((PersistentTableModel) tableModel));
        }
    } catch (Exception e) {
        displayText = "Problem encountered while generating preview: \n" + e.getMessage();
        log.error(displayText);
        e.printStackTrace();
    }

    // make sure there is a jtable, otherwise show just a text version of
    // the data
    if (jtable != null) {
        jtable.setVisible(true);
        // jtable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        scrollPane = new JScrollPane(jtable);
    } else {
        JTextArea textArea = new JTextArea();
        textArea.setColumns(80);
        textArea.setText(displayText);
        textArea.setVisible(true);
        scrollPane = new JScrollPane(textArea);
    }
    scrollPane.setVisible(true);
    panel.setOpaque(true);
    panel.add(scrollPane, BorderLayout.CENTER);
    frame.setContentPane(panel);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

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

private void init() {

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

    // initialise the fields
    nameField = createTextField();/*from   w ww.ja v  a 2  s .  c o 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.browser.TableDataTab.java

private Object setTableResultsPanel(DatabaseObject databaseObject) {

    tableDataChanges.clear();/*  w ww .  j  a va 2 s  . c  o m*/
    primaryKeyColumns.clear();
    foreignKeyColumns.clear();

    this.databaseObject = databaseObject;
    try {

        initialiseModel();
        tableModel.setCellsEditable(false);
        tableModel.removeTableModelListener(this);

        if (isDatabaseTable()) {

            DatabaseTable databaseTable = asDatabaseTable();
            if (databaseTable.hasPrimaryKey()) {

                primaryKeyColumns = databaseTable.getPrimaryKeyColumnNames();
                canEditTableLabel.setText("This table has a primary key(s) and data may be edited here");
            }

            if (databaseTable.hasForeignKey()) {

                foreignKeyColumns = databaseTable.getForeignKeyColumnNames();
            }

            if (primaryKeyColumns.isEmpty()) {

                canEditTableLabel.setText("This table has no primary keys defined and is not editable here");
            }

            canEditTableNotePanel.setVisible(alwaysShowCanEditNotePanel);
        }

        if (!isDatabaseTable()) {

            canEditTableNotePanel.setVisible(false);
        }

        Log.debug("Retrieving data for table - " + databaseObject.getName());

        ResultSet resultSet = databaseObject.getData(true);
        tableModel.createTable(resultSet);
        if (table == null) {

            createResultSetTable();
        }
        tableModel.setNonEditableColumns(primaryKeyColumns);

        TableSorter sorter = new TableSorter(tableModel);
        table.setModel(sorter);
        sorter.setTableHeader(table.getTableHeader());

        if (isDatabaseTable()) {

            SortableHeaderRenderer renderer = new SortableHeaderRenderer(sorter) {

                private ImageIcon primaryKeyIcon = GUIUtilities
                        .loadIcon(BrowserConstants.PRIMARY_COLUMNS_IMAGE);
                private ImageIcon foreignKeyIcon = GUIUtilities
                        .loadIcon(BrowserConstants.FOREIGN_COLUMNS_IMAGE);

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

                    DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) super.getTableCellRendererComponent(
                            table, value, isSelected, hasFocus, row, column);

                    Icon keyIcon = iconForValue(value);
                    if (keyIcon != null) {

                        Icon icon = renderer.getIcon();
                        if (icon != null) {

                            BufferedImage image = new BufferedImage(
                                    icon.getIconWidth() + keyIcon.getIconWidth() + 2,
                                    Math.max(keyIcon.getIconHeight(), icon.getIconHeight()),
                                    BufferedImage.TYPE_INT_ARGB);

                            Graphics graphics = image.getGraphics();
                            keyIcon.paintIcon(null, graphics, 0, 0);
                            icon.paintIcon(null, graphics, keyIcon.getIconWidth() + 2, 5);

                            setIcon(new ImageIcon(image));

                        } else {

                            setIcon(keyIcon);
                        }

                    }

                    return renderer;
                }

                private ImageIcon iconForValue(Object value) {

                    if (value != null) {

                        String name = value.toString();
                        if (primaryKeyColumns.contains(name)) {

                            return primaryKeyIcon;

                        } else if (foreignKeyColumns.contains(name)) {

                            return foreignKeyIcon;
                        }

                    }

                    return null;
                }

            };
            sorter.setTableHeaderRenderer(renderer);

        }

        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

        scroller.getViewport().add(table);
        removeAll();

        add(canEditTableNotePanel, canEditTableNoteConstraints);
        add(scroller, scrollerConstraints);

        if (displayRowCount && SystemProperties.getBooleanProperty("user", "browser.query.row.count")) {

            add(rowCountPanel, rowCountPanelConstraints);
            rowCountField.setText(String.valueOf(sorter.getRowCount()));
        }

    } catch (DataSourceException e) {

        if (!cancelled) {

            addErrorLabel(e);

        } else {

            addCancelledLabel();
        }

    } finally {

        tableModel.addTableModelListener(this);
    }

    setTableProperties();
    validate();
    repaint();

    return "done";
}

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

/**
 * Setup the JTable with its desired characteristics
 *//*from  w w w  . j  a va 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.jets3t.gui.ItemPropertiesDialog.java

/**
 * Initialise the GUI elements to display the given item.
 *
 * @param s3Item/*from   www  .jav  a2s  .c  o  m*/
 * the S3Bucket or an S3Object whose details will be displayed
 */
private void initGui(boolean isObjectBased) {
    // Initialise skins factory.
    skinsFactory = SkinsFactory.getInstance(applicationProperties);

    // Set Skinned Look and Feel.
    LookAndFeel lookAndFeel = skinsFactory.createSkinnedMetalTheme("SkinnedLookAndFeel");
    try {
        UIManager.setLookAndFeel(lookAndFeel);
    } catch (UnsupportedLookAndFeelException e) {
        log.error("Unable to set skinned LookAndFeel", e);
    }

    this.setResizable(true);
    this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    JPanel commonPropertiesContainer = skinsFactory.createSkinnedJPanel("ItemPropertiesCommonPanel");
    commonPropertiesContainer.setLayout(new GridBagLayout());
    JPanel metadataContainer = skinsFactory.createSkinnedJPanel("ItemPropertiesMetadataPanel");
    metadataContainer.setLayout(new GridBagLayout());
    JPanel grantsContainer = skinsFactory.createSkinnedJPanel("ItemPropertiesGrantsPanel");
    grantsContainer.setLayout(new GridBagLayout());

    if (!isObjectBased) {
        // Display bucket details.
        JLabel bucketNameLabel = skinsFactory.createSkinnedJHtmlLabel("BucketNameLabel");
        bucketNameLabel.setText("Bucket name:");
        bucketNameTextField = skinsFactory.createSkinnedJTextField("BucketNameTextField");
        bucketNameTextField.setEditable(false);
        JLabel bucketLocationLabel = skinsFactory.createSkinnedJHtmlLabel("BucketLocationLabel");
        bucketLocationLabel.setText("Location:");
        bucketLocationTextField = skinsFactory.createSkinnedJTextField("BucketLocationTextField");
        bucketLocationTextField.setEditable(false);
        JLabel bucketCreationDateLabel = skinsFactory.createSkinnedJHtmlLabel("BucketCreationDateLabel");
        bucketCreationDateLabel.setText("Creation date:");
        bucketCreationDateTextField = skinsFactory.createSkinnedJTextField("BucketCreationDateTextField");
        bucketCreationDateTextField.setEditable(false);
        ownerNameLabel = skinsFactory.createSkinnedJHtmlLabel("OwnerNameLabel");
        ownerNameLabel.setText("Owner name:");
        ownerNameTextField = skinsFactory.createSkinnedJTextField("OwnerNameTextField");
        ownerNameTextField.setEditable(false);
        ownerIdLabel = skinsFactory.createSkinnedJHtmlLabel("OwnerIdLabel");
        ownerIdLabel.setText("Owner ID:");
        ownerIdTextField = skinsFactory.createSkinnedJTextField("OwnerIdTextField");
        ownerIdTextField.setEditable(false);

        bucketIsRequesterPaysLabel = skinsFactory.createSkinnedJHtmlLabel("BucketIsRequesterPaysLabel");
        bucketIsRequesterPaysLabel.setText("Requester Pays?");
        bucketIsRequesterPaysCheckBox = skinsFactory.createSkinnedJCheckBox("BucketIsRequesterPaysCheckBox");
        bucketIsRequesterPaysCheckBox.setEnabled(false);

        int row = 0;
        commonPropertiesContainer.add(bucketNameLabel, new GridBagConstraints(0, row, 1, 1, 0, 0,
                GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0));
        commonPropertiesContainer.add(bucketNameTextField, new GridBagConstraints(1, row, 1, 1, 1, 0,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

        commonPropertiesContainer.add(bucketLocationLabel, new GridBagConstraints(0, ++row, 1, 1, 0, 0,
                GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0));
        commonPropertiesContainer.add(bucketLocationTextField, new GridBagConstraints(1, row, 1, 1, 1, 0,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

        commonPropertiesContainer.add(bucketCreationDateLabel, new GridBagConstraints(0, ++row, 1, 1, 0, 0,
                GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0));
        commonPropertiesContainer.add(bucketCreationDateTextField, new GridBagConstraints(1, row, 1, 1, 1, 0,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

        commonPropertiesContainer.add(bucketIsRequesterPaysLabel, new GridBagConstraints(0, ++row, 1, 1, 0, 0,
                GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0));
        commonPropertiesContainer.add(bucketIsRequesterPaysCheckBox, new GridBagConstraints(1, row, 1, 1, 0, 0,
                GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));

        commonPropertiesContainer.add(ownerNameLabel, new GridBagConstraints(0, ++row, 1, 1, 0, 0,
                GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0));
        commonPropertiesContainer.add(ownerNameTextField, new GridBagConstraints(1, row, 1, 1, 1, 0,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

        commonPropertiesContainer.add(ownerIdLabel, new GridBagConstraints(0, ++row, 1, 1, 0, 0,
                GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0));
        commonPropertiesContainer.add(ownerIdTextField, new GridBagConstraints(1, row, 1, 1, 1, 0,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

    } else {
        // Display object details.
        JLabel objectKeyLabel = skinsFactory.createSkinnedJHtmlLabel("ObjectKeyLabel");
        objectKeyLabel.setText("Object key:");
        objectKeyTextField = skinsFactory.createSkinnedJTextField("ObjectKeyTextField");
        objectKeyTextField.setEditable(false);
        JLabel objectContentTypeLabel = skinsFactory.createSkinnedJHtmlLabel("ContentTypeLabel");
        objectContentTypeLabel.setText("Content type:");
        objectContentTypeTextField = skinsFactory.createSkinnedJTextField("ContentTypeTextField");
        objectContentTypeTextField.setEditable(false);
        JLabel objectContentLengthLabel = skinsFactory.createSkinnedJHtmlLabel("ObjectContentLengthLabel");
        objectContentLengthLabel.setText("Size:");
        objectContentLengthTextField = skinsFactory.createSkinnedJTextField("ObjectContentLengthTextField");
        objectContentLengthTextField.setEditable(false);
        JLabel objectLastModifiedLabel = skinsFactory.createSkinnedJHtmlLabel("ObjectLastModifiedLabel");
        objectLastModifiedLabel.setText("Last modified:");
        objectLastModifiedTextField = skinsFactory.createSkinnedJTextField("ObjectLastModifiedTextField");
        objectLastModifiedTextField.setEditable(false);
        JLabel objectETagLabel = skinsFactory.createSkinnedJHtmlLabel("ObjectETagLabel");
        objectETagLabel.setText("ETag:");
        objectETagTextField = skinsFactory.createSkinnedJTextField("ObjectETagTextField");
        objectETagTextField.setEditable(false);
        JLabel bucketNameLabel = skinsFactory.createSkinnedJHtmlLabel("BucketNameLabel");
        bucketNameLabel.setText("Bucket name:");
        bucketNameTextField = skinsFactory.createSkinnedJTextField("BucketNameTextField");
        bucketNameTextField.setEditable(false);
        ownerNameLabel = skinsFactory.createSkinnedJHtmlLabel("OwnerNameLabel");
        ownerNameLabel.setText("Owner name:");
        ownerNameTextField = skinsFactory.createSkinnedJTextField("OwnerNameTextField");
        ownerNameTextField.setEditable(false);
        ownerIdLabel = skinsFactory.createSkinnedJHtmlLabel("OwnerIdLabel");
        ownerIdLabel.setText("Owner ID:");
        ownerIdTextField = skinsFactory.createSkinnedJTextField("OwnerIdTextField");
        ownerIdTextField.setEditable(false);

        commonPropertiesContainer.add(objectKeyLabel, new GridBagConstraints(0, 0, 1, 1, 0, 0,
                GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0));
        commonPropertiesContainer.add(objectKeyTextField, new GridBagConstraints(1, 0, 1, 1, 1, 0,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

        commonPropertiesContainer.add(objectContentTypeLabel, new GridBagConstraints(0, 1, 1, 1, 0, 0,
                GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0));
        commonPropertiesContainer.add(objectContentTypeTextField, new GridBagConstraints(1, 1, 1, 1, 1, 0,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

        commonPropertiesContainer.add(objectContentLengthLabel, new GridBagConstraints(0, 2, 1, 1, 0, 0,
                GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0));
        commonPropertiesContainer.add(objectContentLengthTextField, new GridBagConstraints(1, 2, 1, 1, 1, 0,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

        commonPropertiesContainer.add(objectLastModifiedLabel, new GridBagConstraints(0, 3, 1, 1, 0, 0,
                GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0));
        commonPropertiesContainer.add(objectLastModifiedTextField, new GridBagConstraints(1, 3, 1, 1, 1, 0,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

        commonPropertiesContainer.add(objectETagLabel, new GridBagConstraints(0, 4, 1, 1, 0, 0,
                GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0));
        commonPropertiesContainer.add(objectETagTextField, new GridBagConstraints(1, 4, 1, 1, 1, 0,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

        commonPropertiesContainer.add(bucketNameLabel, new GridBagConstraints(0, 5, 1, 1, 0, 0,
                GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0));
        commonPropertiesContainer.add(bucketNameTextField, new GridBagConstraints(1, 5, 1, 1, 1, 0,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

        commonPropertiesContainer.add(ownerNameLabel, new GridBagConstraints(0, 7, 1, 1, 0, 0,
                GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0));
        commonPropertiesContainer.add(ownerNameTextField, new GridBagConstraints(1, 7, 1, 1, 1, 0,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

        commonPropertiesContainer.add(ownerIdLabel, new GridBagConstraints(0, 8, 1, 1, 0, 0,
                GridBagConstraints.EAST, GridBagConstraints.NONE, insetsDefault, 0, 0));
        commonPropertiesContainer.add(ownerIdTextField, new GridBagConstraints(1, 8, 1, 1, 1, 0,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

        // Build metadata table.
        objectMetadataTableModel = new DefaultTableModel(new Object[] { "Name", "Value" }, 0) {
            private static final long serialVersionUID = -3762866886166776851L;

            @Override
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };
        TableSorter metadataTableSorter = new TableSorter(objectMetadataTableModel);
        JTable metadataTable = skinsFactory.createSkinnedJTable("MetadataTable");
        metadataTable.setModel(metadataTableSorter);
        metadataTableSorter.setTableHeader(metadataTable.getTableHeader());
        metadataContainer.add(new JScrollPane(metadataTable), new GridBagConstraints(0, 0, 1, 1, 1, 1,
                GridBagConstraints.CENTER, GridBagConstraints.BOTH, insetsDefault, 0, 0));
    }

    // Build grants table.
    grantsTableModel = new DefaultTableModel(new Object[] { "Grantee", "Permission" }, 0) {
        private static final long serialVersionUID = -5882427163845726770L;

        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    TableSorter grantsTableSorter = new TableSorter(grantsTableModel);
    grantsTable = skinsFactory.createSkinnedJTable("GrantsTable");
    grantsTable.setModel(grantsTableSorter);
    grantsTableSorter.setTableHeader(grantsTable.getTableHeader());
    grantsContainer.add(new JScrollPane(grantsTable), new GridBagConstraints(0, 0, 1, 1, 1, 1,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH, insetsDefault, 0, 0));

    // OK Button.
    JButton okButton = skinsFactory.createSkinnedJButton("ItemPropertiesOKButton");
    okButton.setText("Finished");
    okButton.setActionCommand("OK");
    okButton.addActionListener(this);

    // Set default ENTER button.
    this.getRootPane().setDefaultButton(okButton);

    // Put it all together.
    int row = 0;
    JPanel container = skinsFactory.createSkinnedJPanel("ItemPropertiesPanel");
    container.setLayout(new GridBagLayout());
    container.add(commonPropertiesContainer, new GridBagConstraints(0, row++, 1, 1, 1, 0,
            GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));
    if (isObjectBased) {

        if (includeMetadata) {
            JHtmlLabel metadataLabel = skinsFactory.createSkinnedJHtmlLabel("MetadataLabel");
            metadataLabel.setText("<html><b>Metadata</b></html>");
            metadataLabel.setHorizontalAlignment(JLabel.CENTER);
            container.add(metadataLabel, new GridBagConstraints(0, row++, 1, 1, 1, 0, GridBagConstraints.CENTER,
                    GridBagConstraints.HORIZONTAL, insetsVerticalSpace, 0, 0));
            container.add(metadataContainer, new GridBagConstraints(0, row++, 1, 1, 1, 1,
                    GridBagConstraints.CENTER, GridBagConstraints.BOTH, insetsZero, 0, 0));
        }

        // Object previous and next buttons, if we have multiple objects.
        previousObjectButton = skinsFactory.createSkinnedJButton("ItemPropertiesPreviousButton");
        previousObjectButton.setText("Previous");
        previousObjectButton.addActionListener(this);
        previousObjectButton.setEnabled(false);
        nextObjectButton = skinsFactory.createSkinnedJButton("ItemPropertiesNextButton");
        nextObjectButton.setText("Next");
        nextObjectButton.addActionListener(this);
        nextObjectButton.setEnabled(false);
        currentObjectLabel = skinsFactory.createSkinnedJHtmlLabel("ItemPropertiesCurrentObjectLabel");
        currentObjectLabel.setHorizontalAlignment(JLabel.CENTER);

        nextPreviousPanel = skinsFactory.createSkinnedJPanel("ItemPropertiesNextPreviousPanel");
        nextPreviousPanel.setLayout(new GridBagLayout());
        nextPreviousPanel.add(previousObjectButton, new GridBagConstraints(0, 0, 1, 1, 0, 0,
                GridBagConstraints.WEST, GridBagConstraints.NONE, insetsZero, 0, 0));
        nextPreviousPanel.add(currentObjectLabel, new GridBagConstraints(1, 0, 1, 1, 1, 0,
                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));
        nextPreviousPanel.add(nextObjectButton, new GridBagConstraints(2, 0, 1, 1, 0, 0,
                GridBagConstraints.EAST, GridBagConstraints.NONE, insetsZero, 0, 0));

        container.add(nextPreviousPanel, new GridBagConstraints(0, row, 1, 1, 1, 0, GridBagConstraints.CENTER,
                GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));
        row++;
    } else {
        JHtmlLabel grantsLabel = skinsFactory.createSkinnedJHtmlLabel("GrantsLabel");
        grantsLabel.setText("<html><b>Permissions</b></html>");
        grantsLabel.setHorizontalAlignment(JLabel.CENTER);
        container.add(grantsLabel, new GridBagConstraints(0, row++, 1, 1, 1, 0, GridBagConstraints.CENTER,
                GridBagConstraints.HORIZONTAL, insetsVerticalSpace, 0, 0));
        container.add(grantsContainer, new GridBagConstraints(0, row++, 1, 1, 1, 1, GridBagConstraints.CENTER,
                GridBagConstraints.BOTH, insetsZero, 0, 0));
    }
    container.add(okButton, new GridBagConstraints(0, row++, 3, 1, 0, 0, GridBagConstraints.CENTER,
            GridBagConstraints.NONE, insetsZero, 0, 0));
    this.getContentPane().add(container);

    this.pack();
    if (isObjectBased) {
        this.setSize(400, (includeMetadata ? 550 : 400));
    }
    this.setLocationRelativeTo(this.getOwner());
}

From source file:org.lockss.devtools.plugindef.EDPInspectorTableModel.java

public void setColumnSize(JTable table, int col) {
    TableColumn column = null;//from  ww  w . j a  v a2  s  . c om
    Component comp = null;
    int headerWidth = 0;
    int cellWidth = 0;
    String longestStr = "";
    String curString = "";

    for (int row = 0; row < inspectorEntries.length; row++) {
        curString = data[row][col].toString();
        if (curString.length() > longestStr.length()) {
            longestStr = curString;
        }
    }
    TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer();

    column = table.getColumnModel().getColumn(col);

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

    comp = table.getDefaultRenderer(getColumnClass(col)).getTableCellRendererComponent(table, longestStr, false,
            false, 0, col);
    cellWidth = comp.getPreferredSize().width;

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

From source file:org.nuclos.client.ui.collect.result.ResultController.java

/**
 * TODO: Make this protected again./* ww  w.j av a 2 s .c o  m*/
 */
public void setModel(CollectableTableModel<Clct> tblmodel) {
    final ResultPanel<Clct> panel = getResultPanel();
    final JTable resultTable = panel.getResultTable();
    resultTable.setModel(tblmodel);
    ((ToolTipsTableHeader) resultTable.getTableHeader()).setExternalModel(tblmodel);
    if (tblmodel instanceof SortableTableModel) {
        ((SortableTableModel) tblmodel).addSortingListener(newResultTablePreferencesUpdateListener());
    }
}