Skip to content

Commit 5fe07b3

Browse files
committed
5021949: JSplitPane setEnabled(false) shouldn't be partially functional
Reviewed-by: abhiscxk, achung, aivanov
1 parent ee4720a commit 5fe07b3

File tree

3 files changed

+138
-1
lines changed

3 files changed

+138
-1
lines changed

src/java.desktop/share/classes/javax/swing/JSplitPane.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -41,6 +41,7 @@
4141
import javax.accessibility.AccessibleStateSet;
4242
import javax.accessibility.AccessibleValue;
4343
import javax.swing.plaf.SplitPaneUI;
44+
import javax.swing.plaf.basic.BasicSplitPaneUI;
4445

4546
/**
4647
* <code>JSplitPane</code> is used to divide two (and only two)
@@ -361,6 +362,17 @@ public JSplitPane(int newOrientation,
361362

362363
}
363364

365+
/**
366+
* {@inheritDoc}
367+
* @param enabled {@inheritDoc}
368+
*/
369+
@Override
370+
public void setEnabled(boolean enabled) {
371+
super.setEnabled(enabled);
372+
if (this.getUI() instanceof BasicSplitPaneUI) {
373+
((BasicSplitPaneUI)(this.getUI())).getDivider().setEnabled(enabled);
374+
}
375+
}
364376

365377
/**
366378
* Sets the L&amp;F object that renders this component.

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicSplitPaneDivider.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,20 @@ else if (e.getPropertyName() == JSplitPane.
360360
}
361361
}
362362

363+
/**
364+
* {@inheritDoc}
365+
* @param enabled {@inheritDoc}
366+
*/
367+
@Override
368+
public void setEnabled(boolean enabled) {
369+
if (splitPane.isOneTouchExpandable() &&
370+
rightButton != null &&
371+
leftButton != null) {
372+
373+
rightButton.setEnabled(enabled);
374+
leftButton.setEnabled(enabled);
375+
}
376+
}
363377

364378
/**
365379
* Paints the divider.
@@ -472,6 +486,7 @@ public boolean isFocusTraversable() {
472486
b.setFocusPainted(false);
473487
b.setBorderPainted(false);
474488
b.setRequestFocusEnabled(false);
489+
b.setEnabled(splitPane.isEnabled());
475490
return b;
476491
}
477492

@@ -529,6 +544,7 @@ public boolean isFocusTraversable() {
529544
b.setFocusPainted(false);
530545
b.setBorderPainted(false);
531546
b.setRequestFocusEnabled(false);
547+
b.setEnabled(splitPane.isEnabled());
532548
return b;
533549
}
534550

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 5021949
27+
* @summary Verifies JSplitPane setEnabled(false) disables one touch expandable clicks
28+
* @run main TestSplitPaneEnableTest
29+
*/
30+
31+
import java.awt.Point;
32+
import java.awt.event.InputEvent;
33+
import javax.swing.JButton;
34+
import javax.swing.JSplitPane;
35+
import javax.swing.plaf.basic.BasicSplitPaneDivider;
36+
import javax.swing.plaf.basic.BasicSplitPaneUI;
37+
import javax.swing.SwingUtilities;
38+
import javax.swing.UIManager;
39+
import javax.swing.UnsupportedLookAndFeelException;
40+
41+
public class TestSplitPaneEnableTest {
42+
private static JButton leftOneTouchButton;
43+
private static JButton rightOneTouchButton;
44+
45+
private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
46+
try {
47+
UIManager.setLookAndFeel(laf.getClassName());
48+
} catch (UnsupportedLookAndFeelException ignored) {
49+
System.out.println("Unsupported LAF: " + laf.getClassName());
50+
} catch (ClassNotFoundException | InstantiationException
51+
| IllegalAccessException e) {
52+
throw new RuntimeException(e);
53+
}
54+
}
55+
56+
public static void main(String[] args) throws Exception {
57+
for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
58+
if (laf.getClassName().toLowerCase().contains("gtk")) {
59+
continue;
60+
}
61+
System.out.println("Testing LAF : " + laf.getClassName());
62+
63+
SwingUtilities.invokeAndWait(() -> {
64+
setLookAndFeel(laf);
65+
JSplitPane jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
66+
new JButton("Left"), new JButton("Right"));
67+
jsp.setUI(new TestSplitPaneUI());
68+
jsp.setOneTouchExpandable(true);
69+
jsp.setEnabled(false);
70+
if (leftOneTouchButton.isEnabled()) {
71+
throw new RuntimeException("leftButton is enabled for disabled JSplitPane");
72+
}
73+
if (rightOneTouchButton.isEnabled()) {
74+
throw new RuntimeException("rightButton is enabled for disabled JSplitPane");
75+
}
76+
77+
});
78+
}
79+
}
80+
81+
static class TestSplitPaneUI extends BasicSplitPaneUI {
82+
83+
public TestSplitPaneUI() {
84+
super();
85+
}
86+
87+
public BasicSplitPaneDivider createDefaultDivider() {
88+
return new TestSplitPaneDivider(this);
89+
}
90+
}
91+
92+
static class TestSplitPaneDivider extends BasicSplitPaneDivider {
93+
94+
public TestSplitPaneDivider(BasicSplitPaneUI ui) {
95+
super(ui);
96+
}
97+
98+
protected JButton createLeftOneTouchButton() {
99+
leftOneTouchButton = super.createLeftOneTouchButton();
100+
return leftOneTouchButton;
101+
}
102+
103+
protected JButton createRightOneTouchButton() {
104+
rightOneTouchButton = super.createRightOneTouchButton();
105+
return rightOneTouchButton;
106+
}
107+
}
108+
}
109+

0 commit comments

Comments
 (0)