1499
1500 /**
1501 * Returns the tooltip text to be used for the given event. This overrides
1502 * {@code JComponent}'s {@code getToolTipText} to first check the cell
1503 * renderer component for the cell over which the event occurred, returning
1504 * its tooltip text, if any. This implementation allows you to specify
1505 * tooltip text on the cell level, by using {@code setToolTipText} on your
1506 * cell renderer component.
1507 * <p>
1508 * <strong>Note:</strong> For <code>JList</code> to properly display the
1509 * tooltips of its renderers in this manner, <code>JList</code> must be a
1510 * registered component with the <code>ToolTipManager</code>. This registration
1511 * is done automatically in the constructor. However, if at a later point
1512 * <code>JList</code> is unregistered, by way of a call to
1513 * {@code setToolTipText(null)}, tips from the renderers will no longer display.
1514 *
1515 * @param event the {@code MouseEvent} to fetch the tooltip text for
1516 * @see JComponent#setToolTipText
1517 * @see JComponent#getToolTipText
1518 */
1519 public String getToolTipText(MouseEvent event) {
1520 if(event != null) {
1521 Point p = event.getPoint();
1522 int index = locationToIndex(p);
1523 ListCellRenderer<? super E> r = getCellRenderer();
1524 Rectangle cellBounds;
1525
1526 if (index != -1 && r != null && (cellBounds =
1527 getCellBounds(index, index)) != null &&
1528 cellBounds.contains(p.x, p.y)) {
1529 ListSelectionModel lsm = getSelectionModel();
1530 Component rComponent = r.getListCellRendererComponent(
1531 this, getModel().getElementAt(index), index,
1532 lsm.isSelectedIndex(index),
1533 (hasFocus() && (lsm.getLeadSelectionIndex() ==
1534 index)));
1535
1536 if(rComponent instanceof JComponent) {
1537 MouseEvent newEvent;
1538
|
1499
1500 /**
1501 * Returns the tooltip text to be used for the given event. This overrides
1502 * {@code JComponent}'s {@code getToolTipText} to first check the cell
1503 * renderer component for the cell over which the event occurred, returning
1504 * its tooltip text, if any. This implementation allows you to specify
1505 * tooltip text on the cell level, by using {@code setToolTipText} on your
1506 * cell renderer component.
1507 * <p>
1508 * <strong>Note:</strong> For <code>JList</code> to properly display the
1509 * tooltips of its renderers in this manner, <code>JList</code> must be a
1510 * registered component with the <code>ToolTipManager</code>. This registration
1511 * is done automatically in the constructor. However, if at a later point
1512 * <code>JList</code> is unregistered, by way of a call to
1513 * {@code setToolTipText(null)}, tips from the renderers will no longer display.
1514 *
1515 * @param event the {@code MouseEvent} to fetch the tooltip text for
1516 * @see JComponent#setToolTipText
1517 * @see JComponent#getToolTipText
1518 */
1519 @SuppressWarnings("deprecation")
1520 public String getToolTipText(MouseEvent event) {
1521 if(event != null) {
1522 Point p = event.getPoint();
1523 int index = locationToIndex(p);
1524 ListCellRenderer<? super E> r = getCellRenderer();
1525 Rectangle cellBounds;
1526
1527 if (index != -1 && r != null && (cellBounds =
1528 getCellBounds(index, index)) != null &&
1529 cellBounds.contains(p.x, p.y)) {
1530 ListSelectionModel lsm = getSelectionModel();
1531 Component rComponent = r.getListCellRendererComponent(
1532 this, getModel().getElementAt(index), index,
1533 lsm.isSelectedIndex(index),
1534 (hasFocus() && (lsm.getLeadSelectionIndex() ==
1535 index)));
1536
1537 if(rComponent instanceof JComponent) {
1538 MouseEvent newEvent;
1539
|