Search in sources :

Example 86 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project adempiere by adempiere.

the class POSDefaultCellEditor method getTableCellEditorComponent.

@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
    delegate.setValue(value);
    if (editorComponent instanceof JButton) {
        //in order to avoid a "flashing" effect when clicking a checkbox
        //in a table, it is important for the editor to have as a border
        //the same border that the renderer has, and have as the background
        //the same color as the renderer has. This is primarily only
        //needed for JCheckBox since this editor doesn't fill all the
        //visual space of the table cell, unlike a text field.
        TableCellRenderer renderer = table.getCellRenderer(row, column);
        Component c = renderer.getTableCellRendererComponent(table, value, isSelected, true, row, column);
        if (c != null) {
            editorComponent.setOpaque(true);
            editorComponent.setBackground(c.getBackground());
            if (c instanceof JComponent) {
                editorComponent.setBorder(((JComponent) c).getBorder());
            }
        } else {
            editorComponent.setOpaque(false);
        }
    }
    return editorComponent;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) JButton(javax.swing.JButton) JComponent(javax.swing.JComponent) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Example 87 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project pcgen by PCGen.

the class AutoSizingColumnModel method setColumnPreferredWidth.

/**
	 * Set preffered column width
	 * @param aColumn
	 */
public void setColumnPreferredWidth(TableColumn aColumn) {
    if (m_table != null) {
        TableCellRenderer renderer = null;
        int rowCount = m_table.getRowCount();
        int headerWidth = 0;
        int contentsWidth = 0;
        if (aColumn.getHeaderRenderer() != null) {
            renderer = aColumn.getHeaderRenderer();
        } else {
            renderer = m_table.getTableHeader().getDefaultRenderer();
        }
        if (renderer != null) {
            headerWidth = renderer.getTableCellRendererComponent(m_table, aColumn.getHeaderValue(), false, false, 0, 0).getPreferredSize().width;
        }
        renderer = m_table.getDefaultRenderer(m_table.getModel().getColumnClass(getColumnCount()));
        if (renderer != null && getColumnCount() > 0) {
            for (int row = 0; row < rowCount; row++) {
                contentsWidth = Math.max(contentsWidth, renderer.getTableCellRendererComponent(m_table, m_table.getModel().getValueAt(row, getColumnCount()), false, false, row, 0).getPreferredSize().width);
            }
        }
        aColumn.setPreferredWidth(Math.max(headerWidth, contentsWidth) + getColumnMargin() + COLUMN_WIDTH_PADDING);
    } else {
        aColumn.setPreferredWidth(150);
    }
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer)

Example 88 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project jdk8u_jdk by JetBrains.

the class SwingUtilities2 method pointOutsidePrefSize.

/**
     * Returns true if the given point is outside the preferredSize of the
     * item at the given row of the table.  (Column must be 0).
     * Does not check the "Table.isFileList" property. That should be checked
     * before calling this method.
     * This is used to make WindowsL&F JFileChooser act like native dialogs.
     */
public static boolean pointOutsidePrefSize(JTable table, int row, int column, Point p) {
    if (table.convertColumnIndexToModel(column) != 0 || row == -1) {
        return true;
    }
    TableCellRenderer tcr = table.getCellRenderer(row, column);
    Object value = table.getValueAt(row, column);
    Component cell = tcr.getTableCellRendererComponent(table, value, false, false, row, column);
    Dimension itemSize = cell.getPreferredSize();
    Rectangle cellBounds = table.getCellRect(row, column, false);
    cellBounds.width = itemSize.width;
    cellBounds.height = itemSize.height;
    // ASSUME: mouse x,y will never be < cell's x,y
    assert (p.x >= cellBounds.x && p.y >= cellBounds.y);
    return p.x > cellBounds.x + cellBounds.width || p.y > cellBounds.y + cellBounds.height;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) JTextComponent(javax.swing.text.JTextComponent)

Example 89 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project jmeter by apache.

the class GuiUtils method fixSize.

/**
     * Fix the size of a column according to the header text.
     * 
     * @param column to be resized
     * @param table containing the column
     */
public static void fixSize(TableColumn column, JTable table) {
    TableCellRenderer rndr;
    rndr = column.getHeaderRenderer();
    if (rndr == null) {
        rndr = table.getTableHeader().getDefaultRenderer();
    }
    Component c = rndr.getTableCellRendererComponent(table, column.getHeaderValue(), false, false, -1, column.getModelIndex());
    int width = c.getPreferredSize().width + 10;
    column.setMaxWidth(width);
    column.setPreferredWidth(width);
    column.setResizable(false);
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Example 90 with TableCellRenderer

use of javax.swing.table.TableCellRenderer in project jmeter by apache.

the class HeaderAsPropertyRendererWrapper method setupDefaultRenderer.

/**
     * @param table  {@link JTable}
     * @param columnsMsgParameters Double dimension array of column message parameters
     */
public static void setupDefaultRenderer(JTable table, Object[][] columnsMsgParameters) {
    TableCellRenderer defaultRenderer = table.getTableHeader().getDefaultRenderer();
    HeaderAsPropertyRendererWrapper newRenderer = new HeaderAsPropertyRendererWrapper(defaultRenderer, columnsMsgParameters);
    table.getTableHeader().setDefaultRenderer(newRenderer);
}
Also used : DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) TableCellRenderer(javax.swing.table.TableCellRenderer)

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