Search in sources :

Example 31 with JTableHeader

use of javax.swing.table.JTableHeader in project bb4-games by bb4.

the class PlayerHeadCellRenderer method getTableCellRendererComponent.

/**
 * This method gets called each time a column header is rendered.
 * @param row always -1
 * @param isSelected always false.
 * @param hasFocus always false.
 */
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    // Inherit the colors and font from the header component
    if (table != null) {
        JTableHeader header = table.getTableHeader();
        if (header != null) {
            setForeground(Outcome.PLAYER1_WON.getColor().darker());
            setBackground(Color.WHITE);
            setFont(header.getFont());
        }
    }
    setText((value == null) ? "" : value.toString());
    setToolTipText(getText());
    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    setHorizontalAlignment(JLabel.CENTER);
    this.setFont(FONT);
    return this;
}
Also used : JTableHeader(javax.swing.table.JTableHeader)

Example 32 with JTableHeader

use of javax.swing.table.JTableHeader in project bb4-games by bb4.

the class ResultHeaderCellRenderer method getTableCellRendererComponent.

/**
 * This method gets called each time a column header is rendered.
 * @param value column header value of column 'vColIndex'
 * @param row always -1
 * @param isSelected always false.
 * @param hasFocus always false.
 */
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    // Inherit the colors and font from the header component
    if (table != null) {
        JTableHeader header = table.getTableHeader();
        if (header != null) {
            setForeground(Outcome.PLAYER2_WON.getColor().darker());
            setBackground(Color.WHITE);
            setFont(header.getFont());
        }
    }
    if (value instanceof TextAndIcon) {
        setIcon(((TextAndIcon) value).icon);
        setText(((TextAndIcon) value).text);
    } else {
        setText((value == null) ? "" : value.toString());
        setIcon(null);
    }
    setToolTipText(getText());
    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    setHorizontalAlignment(JLabel.CENTER);
    this.setFont(FONT);
    return this;
}
Also used : JTableHeader(javax.swing.table.JTableHeader)

Example 33 with JTableHeader

use of javax.swing.table.JTableHeader in project opennars by opennars.

the class TableHelper method layoutColumns.

public static void layoutColumns(JTable p_Table, boolean p_OnlyVisibleRows) {
    int column = 0;
    TableColumn c = null;
    int firstRow = p_OnlyVisibleRows ? getFirstVisibleRow(p_Table) : 0;
    int lastRow = p_OnlyVisibleRows ? getLastVisibleRow(p_Table) : (p_Table.getModel().getRowCount() - 1);
    Dimension intercellSpacing = p_Table.getIntercellSpacing();
    JTableHeader tableHeader = p_Table.getTableHeader();
    for (java.util.Enumeration columns = tableHeader.getColumnModel().getColumns(); columns.hasMoreElements(); column++) {
        c = (TableColumn) columns.nextElement();
        Component component = (c.getHeaderRenderer() != null) ? c.getHeaderRenderer().getTableCellRendererComponent(p_Table, c.getHeaderValue(), false, false, -1, column) : tableHeader.getDefaultRenderer().getTableCellRendererComponent(p_Table, c.getHeaderValue(), false, false, -1, column);
        int width = Math.max(c.getWidth(), component.getPreferredSize().width);
        if (firstRow >= 0) {
            for (int i = firstRow, d = lastRow; i <= d; i++) {
                width = Math.max(width, p_Table.getCellRenderer(i, column).getTableCellRendererComponent(p_Table, p_Table.getModel().getValueAt(i, column), false, false, i, column).getPreferredSize().width + intercellSpacing.width);
            }
        }
        c.setPreferredWidth(width);
        c.setWidth(width);
    }
}
Also used : JTableHeader(javax.swing.table.JTableHeader) Dimension(java.awt.Dimension) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn) Point(java.awt.Point)

Example 34 with JTableHeader

use of javax.swing.table.JTableHeader in project chatty by chatty.

the class ExtendableDefaultTableHeaderCellRenderer method getTableCellRendererComponent.

/**
 * Returns the default table header cell renderer.
 * <P>
 * If the column is sorted, the approapriate icon is retrieved from the
 * current Look and Feel, and a border appropriate to a table header cell is
 * applied.
 * <P>
 * Subclasses may overide this method to provide custom content or
 * formatting.
 *
 * @param table the <code>JTable</code>.
 * @param value the value to assign to the header cell
 * @param isSelected This parameter is ignored.
 * @param hasFocus This parameter is ignored.
 * @param row This parameter is ignored.
 * @param column the column of the header cell to render
 * @return the default table header cell renderer
 */
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    JTableHeader tableHeader = table.getTableHeader();
    if (tableHeader != null) {
        setForeground(tableHeader.getForeground());
    }
    setIcon(getIcon(table, column));
    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    return this;
}
Also used : JTableHeader(javax.swing.table.JTableHeader)

Example 35 with JTableHeader

use of javax.swing.table.JTableHeader in project pmd by pmd.

the class GUI method makeMatchList.

private JComponent makeMatchList() {
    resultsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            populateResultArea();
        }
    });
    resultsTable.registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            copyMatchListSelectionsToClipboard();
        }
    }, "Copy", COPY_KEY_STROKE, JComponent.WHEN_FOCUSED);
    resultsTable.registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            deleteMatchlistSelections();
        }
    }, "Del", DELETE_KEY_STROKE, JComponent.WHEN_FOCUSED);
    int[] alignments = new int[matchColumns.length];
    for (int i = 0; i < alignments.length; i++) {
        alignments[i] = matchColumns[i].alignment();
    }
    resultsTable.setDefaultRenderer(Object.class, new AlignmentRenderer(alignments));
    final JTableHeader header = resultsTable.getTableHeader();
    header.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            sortOnColumn(header.columnAtPoint(new Point(e.getX(), e.getY())));
        }
    });
    return new JScrollPane(resultsTable);
}
Also used : JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) MouseAdapter(java.awt.event.MouseAdapter) JTableHeader(javax.swing.table.JTableHeader) Point(java.awt.Point) Point(java.awt.Point) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener)

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