Search in sources :

Example 51 with TableCellRenderer

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

the class StyleTable method createPlainTableHeaderRenderer.

/**
 * Create plain table header cell renderer
 */
public static TableCellRenderer createPlainTableHeaderRenderer(final Color color) {
    return new TableCellRenderer() {

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            JLabel comp = new JLabel(value.toString(), JLabel.LEFT);
            comp.setBackground(color);
            comp.setOpaque(true);
            comp.setBorder(new EmptyBorder(1, 5, 1, 1));
            return comp;
        }
    };
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) JTable(javax.swing.JTable) JLabel(javax.swing.JLabel) EmptyBorder(javax.swing.border.EmptyBorder)

Example 52 with TableCellRenderer

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

the class ResultDisplayPanel method getRestultTable.

public JTable getRestultTable() {
    if (table == null) {
        table = new JTable();
        // set table model
        tableModel = getBestParameterTableModel();
        // set table model
        table.setModel(tableModel);
        table.setCellSelectionEnabled(true);
        table.addMouseListener(evtHandler);
        // set table renderer
        // double precision 6 digits
        TableCellRenderer tableRenderer = new NumericTableCellRenderer();
        for (int i = 0; i < tableModel.getColumnCount(); i++) {
            TableColumn column = table.getColumnModel().getColumn(i);
            column.setCellRenderer(tableRenderer);
        }
    }
    return table;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) JTable(javax.swing.JTable) TableColumn(javax.swing.table.TableColumn)

Example 53 with TableCellRenderer

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

the class GroupableTableHeader method createPlainTableHeaderRenderer.

public static TableCellRenderer createPlainTableHeaderRenderer(final Color color) {
    return new TableCellRenderer() {

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            JLabel comp = new JLabel(value.toString(), JLabel.LEFT);
            comp.setForeground(Color.black);
            comp.setBackground(color);
            comp.setOpaque(true);
            comp.setBorder(new LineBorder(Color.WHITE, 1));
            comp.setFont(VirtualFrapLoader.defaultFont);
            comp.setHorizontalAlignment(SwingConstants.CENTER);
            return comp;
        }
    };
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) JTable(javax.swing.JTable) LineBorder(javax.swing.border.LineBorder) JLabel(javax.swing.JLabel)

Example 54 with TableCellRenderer

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

the class GroupableTableHeaderUI method getHeaderHeight.

/**
 * Calculate and return the height of the header.
 * @return Header Height
 */
private int getHeaderHeight() {
    int height = 0;
    GroupableTableColumnModel columnModel = (GroupableTableColumnModel) header.getColumnModel();
    for (int column = 0; column < columnModel.getColumnCount(); column++) {
        TableColumn aColumn = columnModel.getColumn(column);
        TableCellRenderer renderer = aColumn.getHeaderRenderer();
        if (renderer == null) {
            renderer = header.getDefaultRenderer();
        }
        Component comp = renderer.getTableCellRendererComponent(header.getTable(), aColumn.getHeaderValue(), false, false, -1, column);
        int cHeight = comp.getPreferredSize().height;
        Iterator<ColumnGroup> iter = columnModel.getColumnGroups(aColumn);
        if (iter != null) {
            while (iter.hasNext()) {
                ColumnGroup cGroup = (ColumnGroup) iter.next();
                cHeight += cGroup.getSize(header.getTable()).height;
            }
        }
        height = Math.max(height, cHeight);
    }
    return height;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) JComponent(javax.swing.JComponent) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn)

Example 55 with TableCellRenderer

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

the class GroupableTableHeaderUI method paintCell.

/**
 * Paint group column cell.
 * @param g Graphics context
 * @param cellRect Rectangle that the cell with be painted in
 * @param cGroup Current column group
 */
private void paintCell(Graphics g, Rectangle cellRect, ColumnGroup cGroup) {
    TableCellRenderer renderer = cGroup.getHeaderRenderer();
    Component component = renderer.getTableCellRendererComponent(header.getTable(), cGroup.getHeaderValue(), false, false, -1, -1);
    rendererPane.add(component);
    rendererPane.paintComponent(g, component, header, cellRect.x, cellRect.y, cellRect.width, cellRect.height, true);
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Aggregations

TableCellRenderer (javax.swing.table.TableCellRenderer)122 TableColumn (javax.swing.table.TableColumn)50 Component (java.awt.Component)47 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)24 JComponent (javax.swing.JComponent)20 JTable (javax.swing.JTable)20 TableColumnModel (javax.swing.table.TableColumnModel)18 JLabel (javax.swing.JLabel)17 JTableHeader (javax.swing.table.JTableHeader)17 MouseEvent (java.awt.event.MouseEvent)11 ColumnInfo (com.intellij.util.ui.ColumnInfo)8 ActionEvent (java.awt.event.ActionEvent)8 JButton (javax.swing.JButton)8 DefaultTableColumnModel (javax.swing.table.DefaultTableColumnModel)8 MouseAdapter (java.awt.event.MouseAdapter)7 TableCellEditor (javax.swing.table.TableCellEditor)7 TableModel (javax.swing.table.TableModel)7 ActionListener (java.awt.event.ActionListener)6 List (java.util.List)6 JPanel (javax.swing.JPanel)6