Search in sources :

Example 21 with JTableHeader

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

the class TableContentView method setShowIconInColumnHeader.

/**
 * Sets the property whether or not the icon in the column header
 * shall be shown. This typically represents the column's type icon
 * (the cell type contained in the column). Sometimes, this is not
 * desired (for instance in the data outport view).
 * @param show Whether or not this icon should be shown.
 */
public final void setShowIconInColumnHeader(final boolean show) {
    if (show != m_isShowIconInColumnHeader) {
        m_isShowIconInColumnHeader = show;
        JTableHeader header = getTableHeader();
        if (header == null) {
            return;
        }
        TableCellRenderer r = header.getDefaultRenderer();
        if (r instanceof ColumnHeaderRenderer) {
            ColumnHeaderRenderer cr = (ColumnHeaderRenderer) r;
            cr.setShowIcon(show);
        }
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) JTableHeader(javax.swing.table.JTableHeader)

Example 22 with JTableHeader

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

the class TableRowHeaderView 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)

Example 23 with JTableHeader

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

the class PreviewTableContentView method onMouseClickInHeader.

/**
 * {@inheritDoc}
 */
@Override
protected void onMouseClickInHeader(final MouseEvent e) {
    JTableHeader header = getTableHeader();
    // get column in which event occurred
    int column = header.columnAtPoint(e.getPoint());
    if (column < 0) {
        return;
    }
    int modelIndex = convertColumnIndexToModel(column);
    firePropertyChange(PROPERTY_SPEC_CHANGED, null, modelIndex);
}
Also used : JTableHeader(javax.swing.table.JTableHeader)

Example 24 with JTableHeader

use of javax.swing.table.JTableHeader in project vcell by virtualcell.

the class JSortTable method initSortHeader.

private void initSortHeader() {
    JTableHeader header = getTableHeader();
    if (header != null) {
        header.removeMouseListener(this);
        header.addMouseListener(this);
        for (int i = 0; i < getColumnCount(); i++) {
            header.getColumnModel().getColumn(i).setHeaderRenderer(new SortTableHeaderRenderer(getTableHeader().getDefaultRenderer()));
        }
    }
}
Also used : JTableHeader(javax.swing.table.JTableHeader)

Example 25 with JTableHeader

use of javax.swing.table.JTableHeader in project vcell by virtualcell.

the class SortTableHeaderRenderer method getTableCellRendererComponent.

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
    Component c = defaultTableCellRender.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
    JLabel label = null;
    if (c instanceof JLabel) {
        label = (JLabel) c;
    } else {
        label = new JLabel();
        label.setText(value.toString());
        Border border = null;
        if (hasFocus) {
            border = UIManager.getBorder("TableHeader.focusCellBorder");
        }
        if (border == null) {
            border = UIManager.getBorder("TableHeader.cellBorder");
        }
        if (table != null) {
            JTableHeader header = table.getTableHeader();
            if (header != null) {
                Color fgColor = null;
                Color bgColor = null;
                if (hasFocus) {
                    fgColor = UIManager.getColor("TableHeader.focusCellForeground");
                    bgColor = UIManager.getColor("TableHeader.focusCellBackground");
                }
                if (fgColor == null) {
                    fgColor = header.getForeground();
                }
                if (bgColor == null) {
                    bgColor = header.getBackground();
                }
                label.setForeground(fgColor);
                label.setBackground(bgColor);
                label.setFont(header.getFont());
            }
        }
    }
    boolean ascending = false;
    Icon icon = NOSORTING_ICON;
    if (table instanceof JSortTable) {
        int columnIndex = -1;
        JSortTable sortTable = (JSortTable) table;
        SortPreference sortPreference = ((SortTableModel) sortTable.getModel()).getSortPreference();
        int modelIndex = sortPreference.getSortedColumnIndex();
        if (modelIndex >= 0) {
            for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) {
                if (table.getColumnModel().getColumn(i).getModelIndex() == modelIndex) {
                    columnIndex = i;
                    break;
                }
            }
            ascending = sortPreference.isSortedColumnAscending();
            if (col == columnIndex) {
                icon = ascending ? ASCENDING_ICON : DECENDING_ICON;
            }
        }
    }
    label.setHorizontalTextPosition(JLabel.LEFT);
    label.setIcon(icon);
    return label;
}
Also used : Color(java.awt.Color) JLabel(javax.swing.JLabel) JTableHeader(javax.swing.table.JTableHeader) Icon(javax.swing.Icon) Component(java.awt.Component) Border(javax.swing.border.Border)

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