< prev index next >
src/java.desktop/share/classes/javax/swing/plaf/basic/BasicListUI.java
Print this page
@@ -2132,10 +2132,13 @@
ListSelectionModel lsm = list.getSelectionModel();
int lead = adjustIndex(lsm.getLeadSelectionIndex(), list);
Rectangle leadRect =
(lead==-1) ? new Rectangle() : list.getCellBounds(lead, lead);
+ if (leadRect == null) {
+ return index;
+ }
if (list.getLayoutOrientation() == JList.VERTICAL_WRAP &&
list.getVisibleRowCount() <= 0) {
if (!list.getComponentOrientation().isLeftToRight()) {
direction = -direction;
}
@@ -2145,33 +2148,33 @@
// left
visRect.x = leadRect.x + leadRect.width - visRect.width;
Point p = new Point(visRect.x - 1, leadRect.y);
index = list.locationToIndex(p);
Rectangle cellBounds = list.getCellBounds(index, index);
- if (visRect.intersects(cellBounds)) {
+ if (cellBounds != null && visRect.intersects(cellBounds)) {
p.x = cellBounds.x - 1;
index = list.locationToIndex(p);
cellBounds = list.getCellBounds(index, index);
}
// this is necessary for right-to-left orientation only
- if (cellBounds.y != leadRect.y) {
+ if (cellBounds != null && cellBounds.y != leadRect.y) {
p.x = cellBounds.x + cellBounds.width;
index = list.locationToIndex(p);
}
}
else {
// right
visRect.x = leadRect.x;
Point p = new Point(visRect.x + visRect.width, leadRect.y);
index = list.locationToIndex(p);
Rectangle cellBounds = list.getCellBounds(index, index);
- if (visRect.intersects(cellBounds)) {
+ if (cellBounds != null && visRect.intersects(cellBounds)) {
p.x = cellBounds.x + cellBounds.width;
index = list.locationToIndex(p);
cellBounds = list.getCellBounds(index, index);
}
- if (cellBounds.y != leadRect.y) {
+ if (cellBounds != null && cellBounds.y != leadRect.y) {
p.x = cellBounds.x - 1;
index = list.locationToIndex(p);
}
}
}
@@ -2188,18 +2191,18 @@
p.y = visRect.y;
index = list.locationToIndex(p);
Rectangle cellBounds = list.getCellBounds(index, index);
// go one cell down if first visible cell doesn't fit
// into adjasted visible rectangle
- if (cellBounds.y < visRect.y) {
+ if (cellBounds != null && cellBounds.y < visRect.y) {
p.y = cellBounds.y + cellBounds.height;
index = list.locationToIndex(p);
cellBounds = list.getCellBounds(index, index);
}
// if index isn't less then lead
// try to go to cell previous to lead
- if (cellBounds.y >= leadRect.y) {
+ if (cellBounds != null && cellBounds.y >= leadRect.y) {
p.y = leadRect.y - 1;
index = list.locationToIndex(p);
}
}
}
@@ -2210,12 +2213,14 @@
visRect.y + visRect.height - 1);
index = list.locationToIndex(p);
Rectangle cellBounds = list.getCellBounds(index, index);
// go up one cell if last visible cell doesn't fit
// into visible rectangle
- if (cellBounds.y + cellBounds.height >
- visRect.y + visRect.height) {
+ if (cellBounds != null &&
+ cellBounds.y + cellBounds.height >
+ visRect.y + visRect.height)
+ {
p.y = cellBounds.y - 1;
index = list.locationToIndex(p);
cellBounds = list.getCellBounds(index, index);
index = Math.max(index, lead);
}
@@ -2227,25 +2232,28 @@
p.y = visRect.y + visRect.height - 1;
index = list.locationToIndex(p);
cellBounds = list.getCellBounds(index, index);
// go one cell up if last visible cell doesn't fit
// into adjasted visible rectangle
- if (cellBounds.y + cellBounds.height >
- visRect.y + visRect.height) {
+ if (cellBounds != null &&
+ cellBounds.y + cellBounds.height >
+ visRect.y + visRect.height)
+ {
p.y = cellBounds.y - 1;
index = list.locationToIndex(p);
cellBounds = list.getCellBounds(index, index);
}
// if index isn't greater then lead
// try to go to cell next after lead
- if (cellBounds.y <= leadRect.y) {
+ if (cellBounds != null && cellBounds.y <= leadRect.y) {
p.y = leadRect.y + leadRect.height;
index = list.locationToIndex(p);
}
}
}
}
+
return index;
}
private void changeSelection(JList<?> list, int type,
int index, int direction) {
@@ -2308,37 +2316,42 @@
cellBounds.x + cellBounds.width - visRect.width);
int startIndex =
list.locationToIndex(new Point(x, cellBounds.y));
Rectangle startRect = list.getCellBounds(startIndex,
startIndex);
- if (startRect.x < x && startRect.x < cellBounds.x) {
+ if (startRect != null &&
+ startRect.x < x && startRect.x < cellBounds.x) {
startRect.x += startRect.width;
startIndex =
list.locationToIndex(startRect.getLocation());
startRect = list.getCellBounds(startIndex,
startIndex);
}
cellBounds = startRect;
}
+ if (cellBounds != null) {
cellBounds.width = visRect.width;
}
+ }
else {
if (direction > 0) {
// left for right-to-left
int x = cellBounds.x + visRect.width;
int rightIndex =
list.locationToIndex(new Point(x, cellBounds.y));
Rectangle rightRect = list.getCellBounds(rightIndex,
rightIndex);
+ if (rightRect != null) {
if (rightRect.x + rightRect.width > x &&
rightRect.x > cellBounds.x) {
rightRect.width = 0;
}
cellBounds.x = Math.max(0,
rightRect.x + rightRect.width - visRect.width);
cellBounds.width = visRect.width;
}
+ }
else {
cellBounds.x += Math.max(0,
cellBounds.width - visRect.width);
// adjust width to fit into visible rectangle
cellBounds.width = Math.min(cellBounds.width,
@@ -2357,20 +2370,23 @@
cellBounds.y + cellBounds.height - visRect.height);
int startIndex =
list.locationToIndex(new Point(cellBounds.x, y));
Rectangle startRect = list.getCellBounds(startIndex,
startIndex);
- if (startRect.y < y && startRect.y < cellBounds.y) {
+ if (startRect != null &&
+ startRect.y < y && startRect.y < cellBounds.y) {
startRect.y += startRect.height;
startIndex =
list.locationToIndex(startRect.getLocation());
startRect =
list.getCellBounds(startIndex, startIndex);
}
cellBounds = startRect;
+ if (cellBounds != null) {
cellBounds.height = visRect.height;
}
+ }
else {
// adjust height to fit into visible rectangle
cellBounds.height = Math.min(cellBounds.height, visRect.height);
}
}
< prev index next >