Search in sources :

Example 26 with DefaultTableCellRenderer

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

the class UserParametersGui method getMaximalRequiredColumnWidth.

/**
     * Compute max width between width of the largest column at columnIndex and headerWidth
     * @param columnIndex Column index
     * @param headerWidth Header width based on Font
     */
private int getMaximalRequiredColumnWidth(int columnIndex, int headerWidth) {
    int maxWidth = headerWidth;
    TableColumn column = paramTable.getColumnModel().getColumn(columnIndex);
    TableCellRenderer cellRenderer = column.getCellRenderer();
    if (cellRenderer == null) {
        cellRenderer = new DefaultTableCellRenderer();
    }
    for (int row = 0; row < paramTable.getModel().getRowCount(); row++) {
        Component rendererComponent = cellRenderer.getTableCellRendererComponent(paramTable, paramTable.getModel().getValueAt(row, columnIndex), false, false, row, columnIndex);
        double valueWidth = rendererComponent.getPreferredSize().getWidth();
        maxWidth = (int) Math.max(maxWidth, valueWidth);
    }
    return maxWidth;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 27 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project processdash by dtuma.

the class TeamMemberListTable method prepareRenderer.

@Override
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
    Component result = super.prepareRenderer(renderer, row, column);
    if (result instanceof DefaultTableCellRenderer) {
        if (row == getSelectedRow() && column == getSelectedColumn())
            ;
        else if (isCellEditable(row, column))
            result.setBackground(getBackground());
        else
            result.setBackground(unmodifiableCellBackground);
    }
    return result;
}
Also used : Component(java.awt.Component) JComponent(javax.swing.JComponent) JTextComponent(javax.swing.text.JTextComponent) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Aggregations

DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)27 TableCellRenderer (javax.swing.table.TableCellRenderer)12 Component (java.awt.Component)10 TableColumn (javax.swing.table.TableColumn)10 JComponent (javax.swing.JComponent)7 DefaultTableModel (javax.swing.table.DefaultTableModel)7 Project (com.intellij.openapi.project.Project)3 JTable (javax.swing.JTable)3 JTableHeader (javax.swing.table.JTableHeader)3 JBTable (com.intellij.ui.table.JBTable)2 AbstractTableCellEditor (com.intellij.util.ui.AbstractTableCellEditor)2 java.awt (java.awt)2 MouseEvent (java.awt.event.MouseEvent)2 ArrayList (java.util.ArrayList)2 EventObject (java.util.EventObject)2 javax.swing (javax.swing)2 TableColumnModel (javax.swing.table.TableColumnModel)2 TableModel (javax.swing.table.TableModel)2 Nullable (org.jetbrains.annotations.Nullable)2 AttributesTableModel (com.android.tools.idea.editors.theme.attributes.AttributesTableModel)1