Search in sources :

Example 16 with JTableHeader

use of javax.swing.table.JTableHeader in project intellij-plugins by JetBrains.

the class EditableTreeTable method updateColumnSizes.

// copied from TableView
public void updateColumnSizes() {
    final JTableHeader header = getTableHeader();
    final TableCellRenderer defaultRenderer = header == null ? null : header.getDefaultRenderer();
    ColumnInfo[] columns = ((ListTreeTableModelOnColumns) getTableModel()).getColumnInfos();
    for (int i = 0; i < columns.length; i++) {
        final ColumnInfo columnInfo = columns[i];
        final TableColumn column = getColumnModel().getColumn(i);
        final Component headerComponent = defaultRenderer == null ? null : defaultRenderer.getTableCellRendererComponent(this, column.getHeaderValue(), false, false, 0, 0);
        final Dimension headerSize = headerComponent == null ? JBUI.emptySize() : headerComponent.getPreferredSize();
        final String maxStringValue;
        final String preferredValue;
        if (columnInfo.getWidth(this) > 0) {
            int width = columnInfo.getWidth(this);
            column.setMaxWidth(width);
            column.setPreferredWidth(width);
            column.setMinWidth(width);
        } else if ((maxStringValue = columnInfo.getMaxStringValue()) != null) {
            int width = getFontMetrics(getFont()).stringWidth(maxStringValue) + columnInfo.getAdditionalWidth();
            width = Math.max(width, headerSize.width);
            column.setPreferredWidth(width);
            column.setMaxWidth(width);
        } else if ((preferredValue = columnInfo.getPreferredStringValue()) != null) {
            int width = getFontMetrics(getFont()).stringWidth(preferredValue) + columnInfo.getAdditionalWidth();
            width = Math.max(width, headerSize.width);
            column.setPreferredWidth(width);
        }
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) JTableHeader(javax.swing.table.JTableHeader) ColumnInfo(com.intellij.util.ui.ColumnInfo) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent) TableColumn(javax.swing.table.TableColumn)

Example 17 with JTableHeader

use of javax.swing.table.JTableHeader in project sling by apache.

the class RequestListSelectionListener method valueChanged.

public void valueChanged(ListSelectionEvent e) {
    if (!e.getValueIsAdjusting()) {
        ListSelectionModel lsm = (ListSelectionModel) e.getSource();
        int idx = lsm.getMinSelectionIndex();
        if (idx >= 0) {
            try {
                idx = table.getRowSorter().convertRowIndexToModel(idx);
                TableModel tm = ((RequestTrackerFile) table.getModel()).getData(idx);
                if (dataField == null) {
                    dataField = new JTable();
                    dataField.setAutoCreateRowSorter(true);
                    dataField.setGridColor(Color.GRAY);
                    dataField.setShowGrid(true);
                    dataField.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                    dataField.setRowSelectionAllowed(true);
                    dataField.setTableHeader(new JTableHeader(dataField.getColumnModel()));
                    dataField.setFont(new Font("Monospaced", dataField.getFont().getStyle(), dataField.getFont().getSize()));
                    dataField.setShowHorizontalLines(false);
                    //                        dataField.setIntercellSpacing(new Dimension(3, 5));
                    JDialog d = new JDialog(this.parent);
                    d.add(new JScrollPane(dataField));
                    d.addWindowListener(new WindowAdapter() {

                        @Override
                        public void windowClosing(WindowEvent e) {
                            dataField = null;
                        }
                    });
                    // setup location and size and ensure updating preferences
                    Util.setupComponentLocationSize(d, REQUEST_X, REQUEST_Y, REQUEST_WIDTH, REQUEST_HEIGHT, (int) screenSize.getWidth() / 4, (int) screenSize.getHeight() / 4, (int) screenSize.getWidth() / 2, (int) screenSize.getHeight() / 2);
                    d.setVisible(true);
                }
                dataField.setModel(tm);
                Util.setupColumnWidths(dataField.getColumnModel(), REQUEST_COLS);
            } catch (IOException e1) {
            // ignore
            }
        }
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) ListSelectionModel(javax.swing.ListSelectionModel) JTableHeader(javax.swing.table.JTableHeader) WindowAdapter(java.awt.event.WindowAdapter) IOException(java.io.IOException) Font(java.awt.Font) JTable(javax.swing.JTable) WindowEvent(java.awt.event.WindowEvent) TableModel(javax.swing.table.TableModel) JDialog(javax.swing.JDialog)

Example 18 with JTableHeader

use of javax.swing.table.JTableHeader in project knime-core by knime.

the class RankCorrelationComputeNodeView method changeRenderer.

private void changeRenderer(final String renderer) {
    TableContentView tcv = m_tableView.getContentTable();
    tcv.changeRenderer(DoubleCell.TYPE, renderer);
    Component c = m_tableView.getCorner(ScrollPaneConstants.UPPER_LEFT_CORNER);
    LegendCornerAll cornerRenderer = null;
    if (c instanceof JTableHeader) {
        JTableHeader corner = (JTableHeader) c;
        TableCellRenderer ren = corner.getDefaultRenderer();
        if (ren instanceof LegendCornerAll) {
            cornerRenderer = (LegendCornerAll) ren;
        }
    }
    if (cornerRenderer != null) {
        if (renderer.equals(ColorRender.DESCRIPTION)) {
            cornerRenderer.setPaintLegend(true);
            // no need to set column header height, done by label UI
            tcv.setColumnWidth(15);
            TableCellRenderer r = m_tableView.getContentTable().getTableHeader().getDefaultRenderer();
            if (r instanceof JLabel) {
                ((JLabel) r).setUI(new VerticalLabelUI());
            }
        } else {
            cornerRenderer.setPaintLegend(false);
            m_tableView.setColumnHeaderViewHeight(16);
            tcv.setColumnWidth(75);
            TableCellRenderer r = m_tableView.getContentTable().getTableHeader().getDefaultRenderer();
            if (r instanceof JLabel) {
                ((JLabel) r).updateUI();
            }
        }
    }
    m_currentRendererID = renderer;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JTableHeader(javax.swing.table.JTableHeader) JLabel(javax.swing.JLabel) TableContentView(org.knime.core.node.tableview.TableContentView) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Example 19 with JTableHeader

use of javax.swing.table.JTableHeader in project knime-core by knime.

the class TableContentView method setWrapColumnHeader.

// hiliteSelected()
/**
 * Should the column header names be wrapped if they are too long. Default is false.
 * @param value New value. If set, it makes sense to also set
 * {@link TableView#setColumnHeaderResizingAllowed(boolean)} to true.
 * @since 2.8
 */
public final void setWrapColumnHeader(final boolean value) {
    if (value != m_isWrapHeader) {
        m_isWrapHeader = value;
        JTableHeader header = getTableHeader();
        if (header == null) {
            return;
        }
        TableCellRenderer r = header.getDefaultRenderer();
        if (r instanceof ColumnHeaderRenderer) {
            ColumnHeaderRenderer cr = (ColumnHeaderRenderer) r;
            cr.setWrapHeader(value);
        }
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) JTableHeader(javax.swing.table.JTableHeader)

Example 20 with JTableHeader

use of javax.swing.table.JTableHeader in project knime-core by knime.

the class TableContentView method setFont.

/**
 * {@inheritDoc}
 */
@Override
public void setFont(final Font font) {
    super.setFont(font);
    JTableHeader th = getTableHeader();
    if (th != null) {
        th.setFont(font);
    }
}
Also used : JTableHeader(javax.swing.table.JTableHeader)

Aggregations

JTableHeader (javax.swing.table.JTableHeader)123 JTable (javax.swing.JTable)31 TableColumn (javax.swing.table.TableColumn)27 TableCellRenderer (javax.swing.table.TableCellRenderer)25 TableColumnModel (javax.swing.table.TableColumnModel)24 Component (java.awt.Component)21 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)19 JScrollPane (javax.swing.JScrollPane)17 MouseEvent (java.awt.event.MouseEvent)15 JLabel (javax.swing.JLabel)15 Color (java.awt.Color)11 MouseAdapter (java.awt.event.MouseAdapter)11 JPanel (javax.swing.JPanel)11 DefaultTableModel (javax.swing.table.DefaultTableModel)10 BorderLayout (java.awt.BorderLayout)9 Dimension (java.awt.Dimension)9 Point (java.awt.Point)9 JButton (javax.swing.JButton)8 JComponent (javax.swing.JComponent)8 JPopupMenu (javax.swing.JPopupMenu)7