本文整理匯總了Java中javax.swing.JList.locationToIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java JList.locationToIndex方法的具體用法?Java JList.locationToIndex怎麽用?Java JList.locationToIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JList
的用法示例。
在下文中一共展示了JList.locationToIndex方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: showJList
import javax.swing.JList; //導入方法依賴的package包/類
private void showJList (JScrollPane view, Point pt) {
JList list = (JList) view.getViewport().getView();
Point p = SwingUtilities.convertPoint(view, pt.x, pt.y, list);
int row = list.locationToIndex(p);
if (row == -1) {
hide();
return;
}
Rectangle bds = list.getCellBounds(row,
row);
//GetCellBounds returns a width that is the
//full component width; we want only what
//the renderer really needs.
ListCellRenderer ren = list.getCellRenderer();
Dimension rendererSize =
ren.getListCellRendererComponent(list,
list.getModel().getElementAt(row),
row, false, false).getPreferredSize();
bds.width = rendererSize.width;
if (bds == null || !bds.contains(p)) {
hide();
return;
}
if (setCompAndRow (list, row)) {
Rectangle visible = getShowingRect (view);
Rectangle[] rects = getRects (bds, visible);
if (rects.length > 0) {
ensureOldPopupsHidden();
painter.configure(
list.getModel().getElementAt(row),
view, list, row);
showPopups (rects, bds, visible, list, view);
} else {
hide();
}
}
}
示例2: getIndexAt
import javax.swing.JList; //導入方法依賴的package包/類
public static int getIndexAt(JList list, Point point) {
if (point == null)
return list.getSelectedIndex();
return list.locationToIndex(point);
}