20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import java.awt.Component;
25 import java.awt.Dimension;
26 import java.awt.Rectangle;
27 import java.awt.Toolkit;
28 import javax.swing.JComponent;
29 import javax.swing.JFrame;
30 import javax.swing.JPanel;
31 import javax.swing.JTabbedPane;
32 import javax.swing.JViewport;
33 import javax.swing.SwingUtilities;
34 import javax.swing.UIManager;
35 import javax.swing.plaf.metal.MetalLookAndFeel;
36
37
38 /**
39 * @test
40 * @bug 7170310
41 * @author Alexey Ivanov
42 * @summary Selected tab should be scrolled into view.
43 * @library ../../../../lib/testlibrary/
44 * @build ExtendedRobot
45 * @run main bug7170310
46 */
47 public class bug7170310 {
48 private static final int TABS_NUMBER = 3;
49
50 private static volatile JTabbedPane tabbedPane;
51 private static volatile int count = 1;
52
53 private static volatile JFrame frame;
54
55 private static volatile Exception exception = null;
56
57 public static void main(String[] args) throws Exception {
58 try {
59 UIManager.setLookAndFeel(new MetalLookAndFeel());
60 SwingUtilities.invokeAndWait(bug7170310::createAndShowUI);
61
62 sync();
63
64 for (int i = 0; i < TABS_NUMBER; i++) {
65 SwingUtilities.invokeAndWait(bug7170310::addTab);
66 sync();
67 }
68
69 SwingUtilities.invokeAndWait(bug7170310::check);
70
71 if (exception != null) {
72 System.out.println("Test failed: " + exception.getMessage());
73 throw exception;
74 } else {
75 System.out.printf("Test passed");
76 }
77 } finally {
78 frame.dispose();
79 }
80 }
81
82 private static void createAndShowUI() {
83 frame = new JFrame("bug7170310");
84 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
85 frame.setSize(200, 100);
86
87 tabbedPane = new JTabbedPane();
88 tabbedPane.addTab("Main Tab", new JPanel());
89
90 tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
91
92 frame.getContentPane().add(tabbedPane);
93 frame.setVisible(true);
94 }
95
96 private static void addTab() {
97 tabbedPane.addTab("Added Tab " + count++, new JPanel());
98 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
|
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import java.awt.Component;
25 import java.awt.Dimension;
26 import java.awt.Rectangle;
27 import java.awt.Toolkit;
28 import javax.swing.JComponent;
29 import javax.swing.JFrame;
30 import javax.swing.JPanel;
31 import javax.swing.JTabbedPane;
32 import javax.swing.JViewport;
33 import javax.swing.SwingUtilities;
34 import javax.swing.UIManager;
35 import javax.swing.plaf.metal.MetalLookAndFeel;
36
37
38 /**
39 * @test
40 * @key headful
41 * @bug 7170310
42 * @author Alexey Ivanov
43 * @summary Selected tab should be scrolled into view.
44 * @library ../../../../lib/testlibrary/
45 * @build ExtendedRobot
46 * @run main bug7170310
47 */
48
49 public class bug7170310 {
50 private static final int TABS_NUMBER = 3;
51
52 private static volatile JTabbedPane tabbedPane;
53 private static volatile int count = 1;
54
55 private static volatile JFrame frame;
56
57 private static volatile Exception exception = null;
58
59 public static void main(String[] args) throws Exception {
60 try {
61 UIManager.setLookAndFeel(new MetalLookAndFeel());
62 SwingUtilities.invokeAndWait(bug7170310::createAndShowUI);
63
64 sync();
65
66 for (int i = 0; i < TABS_NUMBER; i++) {
67 SwingUtilities.invokeAndWait(bug7170310::addTab);
68 sync();
69 }
70
71 SwingUtilities.invokeAndWait(bug7170310::check);
72
73 if (exception != null) {
74 System.out.println("Test failed: " + exception.getMessage());
75 throw exception;
76 } else {
77 System.out.printf("Test passed");
78 }
79 } finally {
80 if (frame != null) { frame.dispose(); }
81 }
82 }
83
84 private static void createAndShowUI() {
85 frame = new JFrame("bug7170310");
86 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
87 frame.setSize(200, 100);
88
89 tabbedPane = new JTabbedPane();
90 tabbedPane.addTab("Main Tab", new JPanel());
91
92 tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
93
94 frame.getContentPane().add(tabbedPane);
95 frame.setVisible(true);
96 }
97
98 private static void addTab() {
99 tabbedPane.addTab("Added Tab " + count++, new JPanel());
100 tabbedPane.setSelectedIndex(tabbedPane.getTabCount() - 1);
|