Skip to content

Commit 72a99d2

Browse files
Merge pull request #9239 from matthiasblaesing/allow_scrolling_with_mouse_designer
Form Editor: When designing form larger than design area scrolling the form needs to available
2 parents f29349d + 95ab7d6 commit 72a99d2

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

java/form/src/org/netbeans/modules/form/HandleLayer.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,15 +1231,26 @@ private void selectTabInUnknownTabbedPane(RADVisualComponent metacomp, Point p)
12311231
}
12321232
}
12331233
Component[] clicked = getDeepestComponentsAt(formDesigner.getComponentLayer(), p);
1234-
if (clicked != null && clicked.length > 0 && clicked[0] instanceof JTabbedPane) {
1235-
JTabbedPane tabbedPane = (JTabbedPane)clicked[0];
1236-
p = convertPointToComponent(p, tabbedPane);
1237-
for (int i=0,n=tabbedPane.getTabCount(); i < n; i++) {
1238-
Rectangle rect = tabbedPane.getBoundsAt(i);
1239-
if (rect != null && rect.contains(p)) {
1240-
tabbedPane.setSelectedIndex(i);
1241-
break;
1234+
if (clicked != null && clicked.length > 0) {
1235+
Point pointInComponent = convertPointToComponent(p, clicked[0]);
1236+
if (clicked[0] instanceof JTabbedPane tabbedPane) {
1237+
for (int i = 0, n = tabbedPane.getTabCount(); i < n; i++) {
1238+
Rectangle rect = tabbedPane.getBoundsAt(i);
1239+
if (rect != null && rect.contains(pointInComponent)) {
1240+
tabbedPane.setSelectedIndex(i);
1241+
break;
1242+
}
1243+
}
1244+
} else if (clicked[0] instanceof JScrollBar scrollbar) {
1245+
double position;
1246+
if (scrollbar.getOrientation() == JScrollBar.VERTICAL) {
1247+
double offset = scrollbar.getVisibleAmount() * (((double) scrollbar.getHeight()) / scrollbar.getMaximum());
1248+
position = ((double) pointInComponent.y - (offset / 2)) / (scrollbar.getHeight() - offset);
1249+
} else {
1250+
double offset = scrollbar.getVisibleAmount() * (((double) scrollbar.getWidth()) / scrollbar.getMaximum());
1251+
position = ((double) pointInComponent.x - (offset / 2)) / (scrollbar.getWidth() - offset);
12421252
}
1253+
scrollbar.setValue((int) (scrollbar.getMaximum() * position));
12431254
}
12441255
}
12451256
}

0 commit comments

Comments
 (0)