Example usage for javax.swing ListCellRenderer getListCellRendererComponent

List of usage examples for javax.swing ListCellRenderer getListCellRendererComponent

Introduction

In this page you can find the example usage for javax.swing ListCellRenderer getListCellRendererComponent.

Prototype

Component getListCellRendererComponent(JList<? extends E> list, E value, int index, boolean isSelected,
        boolean cellHasFocus);

Source Link

Document

Return a component that has been configured to display the specified value.

Usage

From source file:Main.java

/**
 * Returns true if the given point is within the actual bounds of the
 * JList item at index (not just inside the cell).
 *///from  w  ww  . j av  a  2s . c o  m
private static boolean pointIsInActualBounds(JList list, int index, Point point) {
    ListCellRenderer renderer = list.getCellRenderer();
    ListModel dataModel = list.getModel();
    Object value = dataModel.getElementAt(index);
    Component item = renderer.getListCellRendererComponent(list, value, index, false, false);
    Dimension itemSize = item.getPreferredSize();
    Rectangle cellBounds = list.getCellBounds(index, index);
    if (!item.getComponentOrientation().isLeftToRight()) {
        cellBounds.x += (cellBounds.width - itemSize.width);
    }
    cellBounds.width = itemSize.width;

    return cellBounds.contains(point);
}

From source file:Main.java

/**
 *
 * @param list/*from  w w  w.ja  v  a  2 s . c  o  m*/
 * @param index
 * @param point
 * @return
 */
public static boolean pointIsInActualBounds(JList list, int index, Point point) {
    ListCellRenderer renderer = list.getCellRenderer();
    ListModel dataModel = list.getModel();
    Object value = dataModel.getElementAt(index);
    Component item = renderer.getListCellRendererComponent(list, value, index, false, false);
    Dimension itemSize = item.getPreferredSize();
    Rectangle cellBounds = list.getCellBounds(index, index);

    if (!item.getComponentOrientation().isLeftToRight()) {
        cellBounds.x += (cellBounds.width - itemSize.width);
    }

    cellBounds.width = itemSize.width;

    return cellBounds.contains(point);
}