Search in sources :

Example 21 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project intellij-community by JetBrains.

the class SwingHelper method setNoBorderCellRendererFor.

public static void setNoBorderCellRendererFor(@NotNull TableColumn column) {
    final TableCellRenderer previous = column.getCellRenderer();
    column.setCellRenderer(new DefaultTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            Component component;
            if (previous != null) {
                component = previous.getTableCellRendererComponent(table, value, isSelected, false, row, column);
            } else {
                component = super.getTableCellRendererComponent(table, value, isSelected, false, row, column);
            }
            if (component instanceof JComponent) {
                ((JComponent) component).setBorder(null);
            }
            return component;
        }
    });
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 22 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project android by JetBrains.

the class IconPickerDialogTest method tableToString.

@NotNull
public static String tableToString(@NotNull JTable table, int startRow, int endRow, int startColumn, int endColumn, int cellWidth) {
    StringBuilder sb = new StringBuilder();
    String formatString = "%-" + Integer.toString(cellWidth) + "s";
    for (int row = Math.max(0, startRow); row < Math.min(endRow, table.getRowCount()); row++) {
        for (int column = Math.max(0, startColumn); column < Math.min(table.getColumnCount(), endColumn); column++) {
            Object value = table.getValueAt(row, column);
            TableCellRenderer renderer = table.getCellRenderer(row, column);
            Component component = renderer.getTableCellRendererComponent(table, value, false, false, row, column);
            DefaultTableCellRenderer label = (DefaultTableCellRenderer) component;
            assertThat(label.getText()).isEmpty();
            String cell = label.getAccessibleContext().getAccessibleName();
            if (cell.length() > cellWidth) {
                cell = cell.substring(0, cellWidth - 3) + "...";
            }
            sb.append(String.format(formatString, cell));
        }
        sb.append('\n');
    }
    return sb.toString();
}
Also used : DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project jabref by JabRef.

the class MainTable method getCellRenderer.

@Override
public TableCellRenderer getCellRenderer(int row, int column) {
    int score = -3;
    DefaultTableCellRenderer renderer = MainTable.defRenderer;
    if ((model.getSearchState() != MainTableDataModel.DisplayOption.FLOAT) || matches(row, SearchMatcher.INSTANCE)) {
        score++;
    }
    if ((model.getGroupingState() != MainTableDataModel.DisplayOption.FLOAT) || matches(row, GroupMatcher.INSTANCE)) {
        score += 2;
    }
    // a very grayed out one for entries with -2
    if (score < -1) {
        if (column == 0) {
            MainTable.veryGrayedOutNumberRenderer.setNumber(row);
            renderer = MainTable.veryGrayedOutNumberRenderer;
        } else {
            renderer = MainTable.veryGrayedOutRenderer;
        }
    } else if (score == -1) {
        if (column == 0) {
            MainTable.grayedOutNumberRenderer.setNumber(row);
            renderer = MainTable.grayedOutNumberRenderer;
        } else {
            renderer = MainTable.grayedOutRenderer;
        }
    } else if (column == 0) {
        if (isComplete(row)) {
            MainTable.compRenderer.setNumber(row);
            int marking = isMarked(row);
            if (marking > 0) {
                marking = Math.min(marking, EntryMarker.MARK_COLOR_LEVELS);
                renderer = MainTable.markedNumberRenderers.get(marking - 1);
                MainTable.markedNumberRenderers.get(marking - 1).setNumber(row);
            } else {
                renderer = MainTable.compRenderer;
            }
        } else {
            // Return a renderer with red background if the entry is incomplete.
            MainTable.incRenderer.setNumber(row);
            renderer = MainTable.incRenderer;
        }
    } else if (tableColorCodes || tableResolvedColorCodes) {
        CellRendererMode status = getCellStatus(row, column, tableResolvedColorCodes);
        if (status == CellRendererMode.REQUIRED) {
            renderer = MainTable.reqRenderer;
        } else if (status == CellRendererMode.OPTIONAL) {
            renderer = MainTable.optRenderer;
        } else if (status == CellRendererMode.RESOLVED) {
            renderer = MainTable.resolvedRenderer;
        }
    }
    // For MARKED feature:
    int marking = isMarked(row);
    if ((column != 0) && (marking > 0)) {
        marking = Math.min(marking, EntryMarker.MARK_COLOR_LEVELS);
        renderer = MainTable.markedRenderers.get(marking - 1);
    }
    return renderer;
}
Also used : Point(java.awt.Point) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 24 with DefaultTableCellRenderer

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

the class ResultTable method autoSize.

/**************************************************************************
	 *	Size Columns
	 */
private void autoSize() {
    log.config("");
    //
    //	making sure it fits in a column
    final int SLACK = 8;
    //	max size of a column
    final int MAXSIZE = 300;
    //
    TableColumnModel tcm = getColumnModel();
    //  For all columns
    for (int col = 0; col < tcm.getColumnCount(); col++) {
        TableColumn tc = tcm.getColumn(col);
        //  log.config( "Column=" + col, tc.getHeaderValue());
        int width = 0;
        //	Header
        TableCellRenderer renderer = tc.getHeaderRenderer();
        if (renderer == null)
            renderer = new DefaultTableCellRenderer();
        Component comp = renderer.getTableCellRendererComponent(this, tc.getHeaderValue(), false, false, 0, 0);
        //	log.fine( "Hdr - preferred=" + comp.getPreferredSize().width + ", width=" + comp.getWidth());
        width = comp.getPreferredSize().width + SLACK;
        //	Cells
        //  first 30 rows
        int maxRow = Math.min(30, getRowCount());
        for (int row = 0; row < maxRow; row++) {
            renderer = getCellRenderer(row, col);
            comp = renderer.getTableCellRendererComponent(this, getValueAt(row, col), false, false, row, col);
            int rowWidth = comp.getPreferredSize().width + SLACK;
            width = Math.max(width, rowWidth);
        }
        //	Width not greater ..
        width = Math.min(MAXSIZE, width);
        tc.setPreferredWidth(width);
    //	log.fine( "width=" + width);
    }
//	for all columns
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) TableColumnModel(javax.swing.table.TableColumnModel) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 25 with DefaultTableCellRenderer

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

the class MiniTable method autoSize.

/**
	 *	Size Columns.
	 *  Uses Mimimum Column Size
	 */
public void autoSize() {
    if (!autoResize)
        return;
    long start = System.currentTimeMillis();
    //
    //	making sure it fits in a column
    final int SLACK = 8;
    //	max size of a column
    final int MAXSIZE = 300;
    //
    TableModel model = this.getModel();
    int size = model.getColumnCount();
    //	for all columns
    for (int col = 0; col < size; col++) {
        //  Column & minimum width
        TableColumn tc = this.getColumnModel().getColumn(col);
        int width = 0;
        if (m_minWidth.size() > col)
            width = ((Integer) m_minWidth.get(col)).intValue();
        //  log.config( "Column=" + col + " " + column.getHeaderValue());
        //	Header
        TableCellRenderer renderer = tc.getHeaderRenderer();
        if (renderer == null)
            renderer = new DefaultTableCellRenderer();
        Component comp = renderer.getTableCellRendererComponent(this, tc.getHeaderValue(), false, false, 0, 0);
        //	log.fine( "Hdr - preferred=" + comp.getPreferredSize().width + ", width=" + comp.getWidth());
        width = Math.max(width, comp.getPreferredSize().width + SLACK);
        //	Cells
        //  first 30 rows
        int maxRow = Math.min(30, getRowCount());
        for (int row = 0; row < maxRow; row++) {
            renderer = getCellRenderer(row, col);
            comp = renderer.getTableCellRendererComponent(this, getValueAt(row, col), false, false, row, col);
            if (comp != null) {
                int rowWidth = comp.getPreferredSize().width + SLACK;
                width = Math.max(width, rowWidth);
            }
        }
        //	Width not greater ..
        width = Math.min(MAXSIZE, width);
        tc.setPreferredWidth(width);
    //	log.fine( "width=" + width);
    }
    //	for all columns
    log.finer("Cols=" + size + " - " + (System.currentTimeMillis() - start) + "ms");
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) Component(java.awt.Component) JComponent(javax.swing.JComponent) TableColumn(javax.swing.table.TableColumn) TableModel(javax.swing.table.TableModel) DefaultTableModel(javax.swing.table.DefaultTableModel) 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