Skip to content

Commit 6b4544c

Browse files
committed
8225220: When the Tab Policy is checked,the scroll button direction displayed incorrectly.
Backport-of: ed5b8c3a7bb6de27ab5050db494b08d5e5dd1c44
1 parent 3195d3d commit 6b4544c

File tree

2 files changed

+110
-1
lines changed

2 files changed

+110
-1
lines changed

src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/GTKEngine.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,8 @@ static WidgetType getWidgetType(JComponent c, Region id) {
337337
return widgets[0];
338338
}
339339
} else if (id == Region.ARROW_BUTTON) {
340-
if (c.getParent() instanceof JScrollBar) {
340+
if (c.getParent() instanceof JScrollBar
341+
|| c.getParent() instanceof JTabbedPane) {
341342
Integer prop = (Integer)
342343
c.getClientProperty("__arrow_direction__");
343344
int dir = (prop != null) ?
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (c) 2023, 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+
import java.awt.BorderLayout;
25+
import java.awt.event.ActionEvent;
26+
import java.awt.GridLayout;
27+
import javax.swing.AbstractAction;
28+
import javax.swing.JButton;
29+
import javax.swing.JFrame;
30+
import javax.swing.JLabel;
31+
import javax.swing.JPanel;
32+
import javax.swing.JTabbedPane;
33+
import javax.swing.SwingUtilities;
34+
import javax.swing.UIManager;
35+
36+
/*
37+
* @test
38+
* @bug 8225220
39+
* @library /java/awt/regtesthelpers
40+
* @build PassFailJFrame
41+
* @requires (os.family == "linux")
42+
* @summary JTabbedPane arrow should point to left or right direction
43+
* when tab layout policy is set to SCROLL_TAB_LAYOUT and tab
44+
* placement is set to either TOP or BOTTOM
45+
* @run main/manual TestJTabbedPaneArrowDirection
46+
*/
47+
48+
public class TestJTabbedPaneArrowDirection {
49+
private static JFrame frame;
50+
private static JTabbedPane tabPane;
51+
private static final String INSTRUCTIONS =
52+
"1. Observe the arrows are ponting to left and right direction\n" +
53+
" for tab placement set to TOP. Default tab placement is TOP.\n\n" +
54+
"2. Press BOTTOM to change the tab placement to bottom.\n\n" +
55+
"3. Observe arrows are pointing to the left and right direction.\n\n" +
56+
"4. If the behaviour is correct, press Pass else Fail.";
57+
58+
public static void main(String[] args) throws Exception {
59+
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
60+
PassFailJFrame passFailJFrame = new PassFailJFrame.Builder()
61+
.title("JTabbedPane Arrow Direction Test Instructions")
62+
.instructions(INSTRUCTIONS)
63+
.testTimeOut(5)
64+
.rows(12)
65+
.columns(40)
66+
.screenCapture()
67+
.build();
68+
SwingUtilities.invokeAndWait(
69+
TestJTabbedPaneArrowDirection::createAndShowUI);
70+
passFailJFrame.awaitAndCheck();
71+
}
72+
73+
private static void createAndShowUI() {
74+
int NUM_TABS = 15;
75+
frame = new JFrame("Test JTabbedPane Arrow Direction");
76+
JTabbedPane tabPane = new JTabbedPane();
77+
tabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
78+
tabPane.setTabPlacement(JTabbedPane.TOP);
79+
PassFailJFrame.addTestWindow(frame);
80+
PassFailJFrame.positionTestWindow(
81+
frame, PassFailJFrame.Position.HORIZONTAL);
82+
for( int i = 0; i < NUM_TABS; ++i) {
83+
tabPane.addTab("Tab " + i , new JLabel("Content Area"));
84+
}
85+
JPanel panel = new JPanel(new BorderLayout());
86+
panel.add(tabPane, BorderLayout.CENTER);
87+
JButton topButton = new JButton(new AbstractAction() {
88+
public void actionPerformed(ActionEvent e) {
89+
tabPane.setTabPlacement(JTabbedPane.TOP);
90+
}
91+
});
92+
topButton.setText("TOP");
93+
JButton bottomButton = new JButton(new AbstractAction() {
94+
public void actionPerformed(ActionEvent e) {
95+
tabPane.setTabPlacement(JTabbedPane.BOTTOM);
96+
}
97+
});
98+
bottomButton.setText("BOTTOM");
99+
JPanel buttonPanel = new JPanel(new GridLayout(1, 2));
100+
buttonPanel.add(topButton);
101+
buttonPanel.add(bottomButton);
102+
panel.add(buttonPanel, BorderLayout.SOUTH);
103+
frame.add(panel);
104+
frame.setSize(500, 500);
105+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
106+
frame.setVisible(true);
107+
}
108+
}

0 commit comments

Comments
 (0)