Java Code Examples for sun.swing.DefaultLookup#getBorder()

The following examples show how to use sun.swing.DefaultLookup#getBorder() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultListCellRenderer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private Border getNoFocusBorder() {
    Border border = DefaultLookup.getBorder(this, ui, "List.cellNoFocusBorder");
    if (System.getSecurityManager() != null) {
        if (border != null) return border;
        return SAFE_NO_FOCUS_BORDER;
    } else {
        if (border != null &&
                (noFocusBorder == null ||
                noFocusBorder == DEFAULT_NO_FOCUS_BORDER)) {
            return border;
        }
        return noFocusBorder;
    }
}
 
Example 2
Source File: DefaultListCellRenderer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private Border getNoFocusBorder() {
    Border border = DefaultLookup.getBorder(this, ui, "List.cellNoFocusBorder");
    if (System.getSecurityManager() != null) {
        if (border != null) return border;
        return SAFE_NO_FOCUS_BORDER;
    } else {
        if (border != null &&
                (noFocusBorder == null ||
                noFocusBorder == DEFAULT_NO_FOCUS_BORDER)) {
            return border;
        }
        return noFocusBorder;
    }
}
 
Example 3
Source File: DefaultListCellRenderer.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private Border getNoFocusBorder() {
    Border border = DefaultLookup.getBorder(this, ui, "List.cellNoFocusBorder");
    if (System.getSecurityManager() != null) {
        if (border != null) return border;
        return SAFE_NO_FOCUS_BORDER;
    } else {
        if (border != null &&
                (noFocusBorder == null ||
                noFocusBorder == DEFAULT_NO_FOCUS_BORDER)) {
            return border;
        }
        return noFocusBorder;
    }
}
 
Example 4
Source File: DefaultListCellRenderer.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private Border getNoFocusBorder() {
    Border border = DefaultLookup.getBorder(this, ui, "List.cellNoFocusBorder");
    if (System.getSecurityManager() != null) {
        if (border != null) return border;
        return SAFE_NO_FOCUS_BORDER;
    } else {
        if (border != null &&
                (noFocusBorder == null ||
                noFocusBorder == DEFAULT_NO_FOCUS_BORDER)) {
            return border;
        }
        return noFocusBorder;
    }
}
 
Example 5
Source File: DefaultTableCellRenderer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private Border getNoFocusBorder() {
    Border border = DefaultLookup.getBorder(this, ui, "Table.cellNoFocusBorder");
    if (System.getSecurityManager() != null) {
        if (border != null) return border;
        return SAFE_NO_FOCUS_BORDER;
    } else if (border != null) {
        if (noFocusBorder == null || noFocusBorder == DEFAULT_NO_FOCUS_BORDER) {
            return border;
        }
    }
    return noFocusBorder;
}
 
Example 6
Source File: DefaultListCellRenderer.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private Border getNoFocusBorder() {
    Border border = DefaultLookup.getBorder(this, ui, "List.cellNoFocusBorder");
    if (System.getSecurityManager() != null) {
        if (border != null) return border;
        return SAFE_NO_FOCUS_BORDER;
    } else {
        if (border != null &&
                (noFocusBorder == null ||
                noFocusBorder == DEFAULT_NO_FOCUS_BORDER)) {
            return border;
        }
        return noFocusBorder;
    }
}
 
Example 7
Source File: DefaultTableCellRenderer.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private Border getNoFocusBorder() {
    Border border = DefaultLookup.getBorder(this, ui, "Table.cellNoFocusBorder");
    if (System.getSecurityManager() != null) {
        if (border != null) return border;
        return SAFE_NO_FOCUS_BORDER;
    } else if (border != null) {
        if (noFocusBorder == null || noFocusBorder == DEFAULT_NO_FOCUS_BORDER) {
            return border;
        }
    }
    return noFocusBorder;
}
 
Example 8
Source File: DefaultTableCellRenderer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private Border getNoFocusBorder() {
    Border border = DefaultLookup.getBorder(this, ui, "Table.cellNoFocusBorder");
    if (System.getSecurityManager() != null) {
        if (border != null) return border;
        return SAFE_NO_FOCUS_BORDER;
    } else if (border != null) {
        if (noFocusBorder == null || noFocusBorder == DEFAULT_NO_FOCUS_BORDER) {
            return border;
        }
    }
    return noFocusBorder;
}
 
Example 9
Source File: DefaultTableCellRenderer.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private Border getNoFocusBorder() {
    Border border = DefaultLookup.getBorder(this, ui, "Table.cellNoFocusBorder");
    if (System.getSecurityManager() != null) {
        if (border != null) return border;
        return SAFE_NO_FOCUS_BORDER;
    } else if (border != null) {
        if (noFocusBorder == null || noFocusBorder == DEFAULT_NO_FOCUS_BORDER) {
            return border;
        }
    }
    return noFocusBorder;
}
 
Example 10
Source File: DefaultTableCellRenderer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private Border getNoFocusBorder() {
    Border border = DefaultLookup.getBorder(this, ui, "Table.cellNoFocusBorder");
    if (System.getSecurityManager() != null) {
        if (border != null) return border;
        return SAFE_NO_FOCUS_BORDER;
    } else if (border != null) {
        if (noFocusBorder == null || noFocusBorder == DEFAULT_NO_FOCUS_BORDER) {
            return border;
        }
    }
    return noFocusBorder;
}
 
Example 11
Source File: DefaultListCellRenderer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public Component getListCellRendererComponent(
    JList<?> list,
    Object value,
    int index,
    boolean isSelected,
    boolean cellHasFocus)
{
    setComponentOrientation(list.getComponentOrientation());

    Color bg = null;
    Color fg = null;

    JList.DropLocation dropLocation = list.getDropLocation();
    if (dropLocation != null
            && !dropLocation.isInsert()
            && dropLocation.getIndex() == index) {

        bg = DefaultLookup.getColor(this, ui, "List.dropCellBackground");
        fg = DefaultLookup.getColor(this, ui, "List.dropCellForeground");

        isSelected = true;
    }

    if (isSelected) {
        setBackground(bg == null ? list.getSelectionBackground() : bg);
        setForeground(fg == null ? list.getSelectionForeground() : fg);
    }
    else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }

    if (value instanceof Icon) {
        setIcon((Icon)value);
        setText("");
    }
    else {
        setIcon(null);
        setText((value == null) ? "" : value.toString());
    }

    setEnabled(list.isEnabled());
    setFont(list.getFont());

    Border border = null;
    if (cellHasFocus) {
        if (isSelected) {
            border = DefaultLookup.getBorder(this, ui, "List.focusSelectedCellHighlightBorder");
        }
        if (border == null) {
            border = DefaultLookup.getBorder(this, ui, "List.focusCellHighlightBorder");
        }
    } else {
        border = getNoFocusBorder();
    }
    setBorder(border);

    return this;
}
 
Example 12
Source File: DefaultListCellRenderer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public Component getListCellRendererComponent(
    JList<?> list,
    Object value,
    int index,
    boolean isSelected,
    boolean cellHasFocus)
{
    setComponentOrientation(list.getComponentOrientation());

    Color bg = null;
    Color fg = null;

    JList.DropLocation dropLocation = list.getDropLocation();
    if (dropLocation != null
            && !dropLocation.isInsert()
            && dropLocation.getIndex() == index) {

        bg = DefaultLookup.getColor(this, ui, "List.dropCellBackground");
        fg = DefaultLookup.getColor(this, ui, "List.dropCellForeground");

        isSelected = true;
    }

    if (isSelected) {
        setBackground(bg == null ? list.getSelectionBackground() : bg);
        setForeground(fg == null ? list.getSelectionForeground() : fg);
    }
    else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }

    if (value instanceof Icon) {
        setIcon((Icon)value);
        setText("");
    }
    else {
        setIcon(null);
        setText((value == null) ? "" : value.toString());
    }

    setEnabled(list.isEnabled());
    setFont(list.getFont());

    Border border = null;
    if (cellHasFocus) {
        if (isSelected) {
            border = DefaultLookup.getBorder(this, ui, "List.focusSelectedCellHighlightBorder");
        }
        if (border == null) {
            border = DefaultLookup.getBorder(this, ui, "List.focusCellHighlightBorder");
        }
    } else {
        border = getNoFocusBorder();
    }
    setBorder(border);

    return this;
}
 
Example 13
Source File: DefaultListCellRenderer.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public Component getListCellRendererComponent(
    JList<?> list,
    Object value,
    int index,
    boolean isSelected,
    boolean cellHasFocus)
{
    setComponentOrientation(list.getComponentOrientation());

    Color bg = null;
    Color fg = null;

    JList.DropLocation dropLocation = list.getDropLocation();
    if (dropLocation != null
            && !dropLocation.isInsert()
            && dropLocation.getIndex() == index) {

        bg = DefaultLookup.getColor(this, ui, "List.dropCellBackground");
        fg = DefaultLookup.getColor(this, ui, "List.dropCellForeground");

        isSelected = true;
    }

    if (isSelected) {
        setBackground(bg == null ? list.getSelectionBackground() : bg);
        setForeground(fg == null ? list.getSelectionForeground() : fg);
    }
    else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }

    if (value instanceof Icon) {
        setIcon((Icon)value);
        setText("");
    }
    else {
        setIcon(null);
        setText((value == null) ? "" : value.toString());
    }

    setEnabled(list.isEnabled());
    setFont(list.getFont());

    Border border = null;
    if (cellHasFocus) {
        if (isSelected) {
            border = DefaultLookup.getBorder(this, ui, "List.focusSelectedCellHighlightBorder");
        }
        if (border == null) {
            border = DefaultLookup.getBorder(this, ui, "List.focusCellHighlightBorder");
        }
    } else {
        border = getNoFocusBorder();
    }
    setBorder(border);

    return this;
}
 
Example 14
Source File: DefaultTableCellRenderer.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
/**
 *
 * Returns the default table cell renderer.
 * <p>
 * During a printing operation, this method will be called with
 * <code>isSelected</code> and <code>hasFocus</code> values of
 * <code>false</code> to prevent selection and focus from appearing
 * in the printed output. To do other customization based on whether
 * or not the table is being printed, check the return value from
 * {@link javax.swing.JComponent#isPaintingForPrint()}.
 *
 * @param table  the <code>JTable</code>
 * @param value  the value to assign to the cell at
 *                  <code>[row, column]</code>
 * @param isSelected true if cell is selected
 * @param hasFocus true if cell has focus
 * @param row  the row of the cell to render
 * @param column the column of the cell to render
 * @return the default table cell renderer
 * @see javax.swing.JComponent#isPaintingForPrint()
 */
public Component getTableCellRendererComponent(JTable table, Object value,
                      boolean isSelected, boolean hasFocus, int row, int column) {
    if (table == null) {
        return this;
    }

    Color fg = null;
    Color bg = null;

    JTable.DropLocation dropLocation = table.getDropLocation();
    if (dropLocation != null
            && !dropLocation.isInsertRow()
            && !dropLocation.isInsertColumn()
            && dropLocation.getRow() == row
            && dropLocation.getColumn() == column) {

        fg = DefaultLookup.getColor(this, ui, "Table.dropCellForeground");
        bg = DefaultLookup.getColor(this, ui, "Table.dropCellBackground");

        isSelected = true;
    }

    if (isSelected) {
        super.setForeground(fg == null ? table.getSelectionForeground()
                                       : fg);
        super.setBackground(bg == null ? table.getSelectionBackground()
                                       : bg);
    } else {
        Color background = unselectedBackground != null
                                ? unselectedBackground
                                : table.getBackground();
        if (background == null || background instanceof javax.swing.plaf.UIResource) {
            Color alternateColor = DefaultLookup.getColor(this, ui, "Table.alternateRowColor");
            if (alternateColor != null && row % 2 != 0) {
                background = alternateColor;
            }
        }
        super.setForeground(unselectedForeground != null
                                ? unselectedForeground
                                : table.getForeground());
        super.setBackground(background);
    }

    setFont(table.getFont());

    if (hasFocus) {
        Border border = null;
        if (isSelected) {
            border = DefaultLookup.getBorder(this, ui, "Table.focusSelectedCellHighlightBorder");
        }
        if (border == null) {
            border = DefaultLookup.getBorder(this, ui, "Table.focusCellHighlightBorder");
        }
        setBorder(border);

        if (!isSelected && table.isCellEditable(row, column)) {
            Color col;
            col = DefaultLookup.getColor(this, ui, "Table.focusCellForeground");
            if (col != null) {
                super.setForeground(col);
            }
            col = DefaultLookup.getColor(this, ui, "Table.focusCellBackground");
            if (col != null) {
                super.setBackground(col);
            }
        }
    } else {
        setBorder(getNoFocusBorder());
    }

    setValue(value);

    return this;
}
 
Example 15
Source File: DefaultListCellRenderer.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public Component getListCellRendererComponent(
    JList<?> list,
    Object value,
    int index,
    boolean isSelected,
    boolean cellHasFocus)
{
    setComponentOrientation(list.getComponentOrientation());

    Color bg = null;
    Color fg = null;

    JList.DropLocation dropLocation = list.getDropLocation();
    if (dropLocation != null
            && !dropLocation.isInsert()
            && dropLocation.getIndex() == index) {

        bg = DefaultLookup.getColor(this, ui, "List.dropCellBackground");
        fg = DefaultLookup.getColor(this, ui, "List.dropCellForeground");

        isSelected = true;
    }

    if (isSelected) {
        setBackground(bg == null ? list.getSelectionBackground() : bg);
        setForeground(fg == null ? list.getSelectionForeground() : fg);
    }
    else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }

    if (value instanceof Icon) {
        setIcon((Icon)value);
        setText("");
    }
    else {
        setIcon(null);
        setText((value == null) ? "" : value.toString());
    }

    setEnabled(list.isEnabled());
    setFont(list.getFont());

    Border border = null;
    if (cellHasFocus) {
        if (isSelected) {
            border = DefaultLookup.getBorder(this, ui, "List.focusSelectedCellHighlightBorder");
        }
        if (border == null) {
            border = DefaultLookup.getBorder(this, ui, "List.focusCellHighlightBorder");
        }
    } else {
        border = getNoFocusBorder();
    }
    setBorder(border);

    return this;
}
 
Example 16
Source File: DefaultTableCellRenderer.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 *
 * Returns the default table cell renderer.
 * <p>
 * During a printing operation, this method will be called with
 * <code>isSelected</code> and <code>hasFocus</code> values of
 * <code>false</code> to prevent selection and focus from appearing
 * in the printed output. To do other customization based on whether
 * or not the table is being printed, check the return value from
 * {@link javax.swing.JComponent#isPaintingForPrint()}.
 *
 * @param table  the <code>JTable</code>
 * @param value  the value to assign to the cell at
 *                  <code>[row, column]</code>
 * @param isSelected true if cell is selected
 * @param hasFocus true if cell has focus
 * @param row  the row of the cell to render
 * @param column the column of the cell to render
 * @return the default table cell renderer
 * @see javax.swing.JComponent#isPaintingForPrint()
 */
public Component getTableCellRendererComponent(JTable table, Object value,
                      boolean isSelected, boolean hasFocus, int row, int column) {
    if (table == null) {
        return this;
    }

    Color fg = null;
    Color bg = null;

    JTable.DropLocation dropLocation = table.getDropLocation();
    if (dropLocation != null
            && !dropLocation.isInsertRow()
            && !dropLocation.isInsertColumn()
            && dropLocation.getRow() == row
            && dropLocation.getColumn() == column) {

        fg = DefaultLookup.getColor(this, ui, "Table.dropCellForeground");
        bg = DefaultLookup.getColor(this, ui, "Table.dropCellBackground");

        isSelected = true;
    }

    if (isSelected) {
        super.setForeground(fg == null ? table.getSelectionForeground()
                                       : fg);
        super.setBackground(bg == null ? table.getSelectionBackground()
                                       : bg);
    } else {
        Color background = unselectedBackground != null
                                ? unselectedBackground
                                : table.getBackground();
        if (background == null || background instanceof javax.swing.plaf.UIResource) {
            Color alternateColor = DefaultLookup.getColor(this, ui, "Table.alternateRowColor");
            if (alternateColor != null && row % 2 != 0) {
                background = alternateColor;
            }
        }
        super.setForeground(unselectedForeground != null
                                ? unselectedForeground
                                : table.getForeground());
        super.setBackground(background);
    }

    setFont(table.getFont());

    if (hasFocus) {
        Border border = null;
        if (isSelected) {
            border = DefaultLookup.getBorder(this, ui, "Table.focusSelectedCellHighlightBorder");
        }
        if (border == null) {
            border = DefaultLookup.getBorder(this, ui, "Table.focusCellHighlightBorder");
        }
        setBorder(border);

        if (!isSelected && table.isCellEditable(row, column)) {
            Color col;
            col = DefaultLookup.getColor(this, ui, "Table.focusCellForeground");
            if (col != null) {
                super.setForeground(col);
            }
            col = DefaultLookup.getColor(this, ui, "Table.focusCellBackground");
            if (col != null) {
                super.setBackground(col);
            }
        }
    } else {
        setBorder(getNoFocusBorder());
    }

    setValue(value);

    return this;
}
 
Example 17
Source File: DefaultTableCellRenderer.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 *
 * Returns the default table cell renderer.
 * <p>
 * During a printing operation, this method will be called with
 * <code>isSelected</code> and <code>hasFocus</code> values of
 * <code>false</code> to prevent selection and focus from appearing
 * in the printed output. To do other customization based on whether
 * or not the table is being printed, check the return value from
 * {@link javax.swing.JComponent#isPaintingForPrint()}.
 *
 * @param table  the <code>JTable</code>
 * @param value  the value to assign to the cell at
 *                  <code>[row, column]</code>
 * @param isSelected true if cell is selected
 * @param hasFocus true if cell has focus
 * @param row  the row of the cell to render
 * @param column the column of the cell to render
 * @return the default table cell renderer
 * @see javax.swing.JComponent#isPaintingForPrint()
 */
public Component getTableCellRendererComponent(JTable table, Object value,
                      boolean isSelected, boolean hasFocus, int row, int column) {
    if (table == null) {
        return this;
    }

    Color fg = null;
    Color bg = null;

    JTable.DropLocation dropLocation = table.getDropLocation();
    if (dropLocation != null
            && !dropLocation.isInsertRow()
            && !dropLocation.isInsertColumn()
            && dropLocation.getRow() == row
            && dropLocation.getColumn() == column) {

        fg = DefaultLookup.getColor(this, ui, "Table.dropCellForeground");
        bg = DefaultLookup.getColor(this, ui, "Table.dropCellBackground");

        isSelected = true;
    }

    if (isSelected) {
        super.setForeground(fg == null ? table.getSelectionForeground()
                                       : fg);
        super.setBackground(bg == null ? table.getSelectionBackground()
                                       : bg);
    } else {
        Color background = unselectedBackground != null
                                ? unselectedBackground
                                : table.getBackground();
        if (background == null || background instanceof javax.swing.plaf.UIResource) {
            Color alternateColor = DefaultLookup.getColor(this, ui, "Table.alternateRowColor");
            if (alternateColor != null && row % 2 != 0) {
                background = alternateColor;
            }
        }
        super.setForeground(unselectedForeground != null
                                ? unselectedForeground
                                : table.getForeground());
        super.setBackground(background);
    }

    setFont(table.getFont());

    if (hasFocus) {
        Border border = null;
        if (isSelected) {
            border = DefaultLookup.getBorder(this, ui, "Table.focusSelectedCellHighlightBorder");
        }
        if (border == null) {
            border = DefaultLookup.getBorder(this, ui, "Table.focusCellHighlightBorder");
        }
        setBorder(border);

        if (!isSelected && table.isCellEditable(row, column)) {
            Color col;
            col = DefaultLookup.getColor(this, ui, "Table.focusCellForeground");
            if (col != null) {
                super.setForeground(col);
            }
            col = DefaultLookup.getColor(this, ui, "Table.focusCellBackground");
            if (col != null) {
                super.setBackground(col);
            }
        }
    } else {
        setBorder(getNoFocusBorder());
    }

    setValue(value);

    return this;
}
 
Example 18
Source File: DefaultTableCellRenderer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 *
 * Returns the default table cell renderer.
 * <p>
 * During a printing operation, this method will be called with
 * <code>isSelected</code> and <code>hasFocus</code> values of
 * <code>false</code> to prevent selection and focus from appearing
 * in the printed output. To do other customization based on whether
 * or not the table is being printed, check the return value from
 * {@link javax.swing.JComponent#isPaintingForPrint()}.
 *
 * @param table  the <code>JTable</code>
 * @param value  the value to assign to the cell at
 *                  <code>[row, column]</code>
 * @param isSelected true if cell is selected
 * @param hasFocus true if cell has focus
 * @param row  the row of the cell to render
 * @param column the column of the cell to render
 * @return the default table cell renderer
 * @see javax.swing.JComponent#isPaintingForPrint()
 */
public Component getTableCellRendererComponent(JTable table, Object value,
                      boolean isSelected, boolean hasFocus, int row, int column) {
    if (table == null) {
        return this;
    }

    Color fg = null;
    Color bg = null;

    JTable.DropLocation dropLocation = table.getDropLocation();
    if (dropLocation != null
            && !dropLocation.isInsertRow()
            && !dropLocation.isInsertColumn()
            && dropLocation.getRow() == row
            && dropLocation.getColumn() == column) {

        fg = DefaultLookup.getColor(this, ui, "Table.dropCellForeground");
        bg = DefaultLookup.getColor(this, ui, "Table.dropCellBackground");

        isSelected = true;
    }

    if (isSelected) {
        super.setForeground(fg == null ? table.getSelectionForeground()
                                       : fg);
        super.setBackground(bg == null ? table.getSelectionBackground()
                                       : bg);
    } else {
        Color background = unselectedBackground != null
                                ? unselectedBackground
                                : table.getBackground();
        if (background == null || background instanceof javax.swing.plaf.UIResource) {
            Color alternateColor = DefaultLookup.getColor(this, ui, "Table.alternateRowColor");
            if (alternateColor != null && row % 2 != 0) {
                background = alternateColor;
            }
        }
        super.setForeground(unselectedForeground != null
                                ? unselectedForeground
                                : table.getForeground());
        super.setBackground(background);
    }

    setFont(table.getFont());

    if (hasFocus) {
        Border border = null;
        if (isSelected) {
            border = DefaultLookup.getBorder(this, ui, "Table.focusSelectedCellHighlightBorder");
        }
        if (border == null) {
            border = DefaultLookup.getBorder(this, ui, "Table.focusCellHighlightBorder");
        }
        setBorder(border);

        if (!isSelected && table.isCellEditable(row, column)) {
            Color col;
            col = DefaultLookup.getColor(this, ui, "Table.focusCellForeground");
            if (col != null) {
                super.setForeground(col);
            }
            col = DefaultLookup.getColor(this, ui, "Table.focusCellBackground");
            if (col != null) {
                super.setBackground(col);
            }
        }
    } else {
        setBorder(getNoFocusBorder());
    }

    setValue(value);

    return this;
}
 
Example 19
Source File: DefaultListCellRenderer.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public Component getListCellRendererComponent(
    JList<?> list,
    Object value,
    int index,
    boolean isSelected,
    boolean cellHasFocus)
{
    setComponentOrientation(list.getComponentOrientation());

    Color bg = null;
    Color fg = null;

    JList.DropLocation dropLocation = list.getDropLocation();
    if (dropLocation != null
            && !dropLocation.isInsert()
            && dropLocation.getIndex() == index) {

        bg = DefaultLookup.getColor(this, ui, "List.dropCellBackground");
        fg = DefaultLookup.getColor(this, ui, "List.dropCellForeground");

        isSelected = true;
    }

    if (isSelected) {
        setBackground(bg == null ? list.getSelectionBackground() : bg);
        setForeground(fg == null ? list.getSelectionForeground() : fg);
    }
    else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }

    if (value instanceof Icon) {
        setIcon((Icon)value);
        setText("");
    }
    else {
        setIcon(null);
        setText((value == null) ? "" : value.toString());
    }

    setEnabled(list.isEnabled());
    setFont(list.getFont());

    Border border = null;
    if (cellHasFocus) {
        if (isSelected) {
            border = DefaultLookup.getBorder(this, ui, "List.focusSelectedCellHighlightBorder");
        }
        if (border == null) {
            border = DefaultLookup.getBorder(this, ui, "List.focusCellHighlightBorder");
        }
    } else {
        border = getNoFocusBorder();
    }
    setBorder(border);

    return this;
}
 
Example 20
Source File: DefaultTableCellRenderer.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 *
 * Returns the default table cell renderer.
 * <p>
 * During a printing operation, this method will be called with
 * <code>isSelected</code> and <code>hasFocus</code> values of
 * <code>false</code> to prevent selection and focus from appearing
 * in the printed output. To do other customization based on whether
 * or not the table is being printed, check the return value from
 * {@link javax.swing.JComponent#isPaintingForPrint()}.
 *
 * @param table  the <code>JTable</code>
 * @param value  the value to assign to the cell at
 *                  <code>[row, column]</code>
 * @param isSelected true if cell is selected
 * @param hasFocus true if cell has focus
 * @param row  the row of the cell to render
 * @param column the column of the cell to render
 * @return the default table cell renderer
 * @see javax.swing.JComponent#isPaintingForPrint()
 */
public Component getTableCellRendererComponent(JTable table, Object value,
                      boolean isSelected, boolean hasFocus, int row, int column) {
    if (table == null) {
        return this;
    }

    Color fg = null;
    Color bg = null;

    JTable.DropLocation dropLocation = table.getDropLocation();
    if (dropLocation != null
            && !dropLocation.isInsertRow()
            && !dropLocation.isInsertColumn()
            && dropLocation.getRow() == row
            && dropLocation.getColumn() == column) {

        fg = DefaultLookup.getColor(this, ui, "Table.dropCellForeground");
        bg = DefaultLookup.getColor(this, ui, "Table.dropCellBackground");

        isSelected = true;
    }

    if (isSelected) {
        super.setForeground(fg == null ? table.getSelectionForeground()
                                       : fg);
        super.setBackground(bg == null ? table.getSelectionBackground()
                                       : bg);
    } else {
        Color background = unselectedBackground != null
                                ? unselectedBackground
                                : table.getBackground();
        if (background == null || background instanceof javax.swing.plaf.UIResource) {
            Color alternateColor = DefaultLookup.getColor(this, ui, "Table.alternateRowColor");
            if (alternateColor != null && row % 2 != 0) {
                background = alternateColor;
            }
        }
        super.setForeground(unselectedForeground != null
                                ? unselectedForeground
                                : table.getForeground());
        super.setBackground(background);
    }

    setFont(table.getFont());

    if (hasFocus) {
        Border border = null;
        if (isSelected) {
            border = DefaultLookup.getBorder(this, ui, "Table.focusSelectedCellHighlightBorder");
        }
        if (border == null) {
            border = DefaultLookup.getBorder(this, ui, "Table.focusCellHighlightBorder");
        }
        setBorder(border);

        if (!isSelected && table.isCellEditable(row, column)) {
            Color col;
            col = DefaultLookup.getColor(this, ui, "Table.focusCellForeground");
            if (col != null) {
                super.setForeground(col);
            }
            col = DefaultLookup.getColor(this, ui, "Table.focusCellBackground");
            if (col != null) {
                super.setBackground(col);
            }
        }
    } else {
        setBorder(getNoFocusBorder());
    }

    setValue(value);

    return this;
}