author | aivanov |
Fri, 10 Oct 2014 11:26:51 +0400 | |
changeset 27266 | 677e0bfc64d7 |
child 27764 | 4e79ff3e0602 |
permissions | -rw-r--r-- |
27266
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
1 |
/* |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
4 |
* |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
8 |
* |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
13 |
* accompanied this code). |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
14 |
* |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
18 |
* |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
21 |
* questions. |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
22 |
*/ |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
23 |
|
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
24 |
import java.awt.Component; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
25 |
import java.awt.Dimension; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
26 |
import java.awt.Rectangle; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
27 |
import java.awt.Toolkit; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
28 |
import javax.swing.JComponent; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
29 |
import javax.swing.JFrame; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
30 |
import javax.swing.JPanel; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
31 |
import javax.swing.JTabbedPane; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
32 |
import javax.swing.JViewport; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
33 |
import javax.swing.SwingUtilities; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
34 |
import javax.swing.UIManager; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
35 |
import javax.swing.plaf.metal.MetalLookAndFeel; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
36 |
|
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
37 |
import sun.awt.SunToolkit; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
38 |
|
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
39 |
/** |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
40 |
* @test |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
41 |
* @bug 7170310 |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
42 |
* @author Alexey Ivanov |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
43 |
* @summary Selected tab should be scrolled into view. |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
44 |
* @run main bug7170310 |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
45 |
*/ |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
46 |
public class bug7170310 { |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
47 |
private static final int TABS_NUMBER = 3; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
48 |
|
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
49 |
private static volatile JTabbedPane tabbedPane; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
50 |
private static volatile int count = 1; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
51 |
|
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
52 |
private static volatile JFrame frame; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
53 |
|
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
54 |
private static volatile Exception exception = null; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
55 |
|
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
56 |
public static void main(String[] args) throws Exception { |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
57 |
try { |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
58 |
UIManager.setLookAndFeel(new MetalLookAndFeel()); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
59 |
SwingUtilities.invokeAndWait(bug7170310::createAndShowUI); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
60 |
|
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
61 |
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
62 |
toolkit.realSync(); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
63 |
|
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
64 |
for (int i = 0; i < TABS_NUMBER; i++) { |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
65 |
SwingUtilities.invokeAndWait(bug7170310::addTab); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
66 |
toolkit.realSync(); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
67 |
} |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
68 |
|
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
69 |
SwingUtilities.invokeAndWait(bug7170310::check); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
70 |
|
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
71 |
if (exception != null) { |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
72 |
System.out.println("Test failed: " + exception.getMessage()); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
73 |
throw exception; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
74 |
} else { |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
75 |
System.out.printf("Test passed"); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
76 |
} |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
77 |
} finally { |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
78 |
frame.dispose(); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
79 |
} |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
80 |
} |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
81 |
|
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
82 |
private static void createAndShowUI() { |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
83 |
frame = new JFrame("bug7170310"); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
84 |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
85 |
frame.setSize(200, 100); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
86 |
|
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
87 |
tabbedPane = new JTabbedPane(); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
88 |
tabbedPane.addTab("Main Tab", new JPanel()); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
89 |
|
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
90 |
tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
91 |
|
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
92 |
frame.getContentPane().add(tabbedPane); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
93 |
frame.setVisible(true); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
94 |
} |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
95 |
|
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
96 |
private static void addTab() { |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
97 |
tabbedPane.addTab("Added Tab " + count++, new JPanel()); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
98 |
tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
99 |
} |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
100 |
|
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
101 |
private static void check() { |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
102 |
try { |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
103 |
JViewport vp = null; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
104 |
for (Component c : tabbedPane.getComponents()) { |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
105 |
if (c instanceof JViewport) { |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
106 |
vp = (JViewport) c; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
107 |
break; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
108 |
} |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
109 |
} |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
110 |
|
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
111 |
JComponent v = (JComponent) vp.getView(); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
112 |
Rectangle vr = vp.getViewRect(); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
113 |
Dimension vs = v.getSize(); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
114 |
|
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
115 |
// The tab view must be scrolled to the end so that the last tab is visible |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
116 |
if (vs.width != (vr.x + vr.width)) { |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
117 |
throw new RuntimeException("tabScroller.tabPanel view is positioned incorrectly: " |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
118 |
+ vs.width + " vs " + (vr.x + vr.width)); |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
119 |
} |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
120 |
} catch (Exception e) { |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
121 |
exception = e; |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
122 |
} |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
123 |
} |
677e0bfc64d7
7170310: ScrollBar doesn't become active when tabs are created more than frame size
aivanov
parents:
diff
changeset
|
124 |
} |