8244557: test/jdk/javax/swing/JTabbedPane/TestBackgroundScrollPolicy.java failed
Reviewed-by: prr
This commit is contained in:
parent
eb91535be5
commit
f64bdedeac
@ -27,113 +27,93 @@ import java.util.concurrent.CountDownLatch;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTabbedPane;
|
||||
|
||||
import static javax.swing.UIManager.*;
|
||||
import static javax.swing.SwingUtilities.*;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 8172269
|
||||
* @bug 8172269 8244557
|
||||
* @summary Tests JTabbedPane background for SCROLL_TAB_LAYOUT
|
||||
* @run main TestBackgroundScrollPolicy
|
||||
*/
|
||||
|
||||
public class TestBackgroundScrollPolicy implements Runnable {
|
||||
private static final ArrayList<String> LIST = new ArrayList<>();
|
||||
private static final LookAndFeelInfo[] INFO = getInstalledLookAndFeels();
|
||||
private static final CountDownLatch LATCH = new CountDownLatch(INFO.length);
|
||||
public class TestBackgroundScrollPolicy {
|
||||
private static Robot ROBOT;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
ROBOT = new Robot();
|
||||
invokeLater(new TestBackgroundScrollPolicy());
|
||||
LATCH.await();
|
||||
if (!LIST.isEmpty()) {
|
||||
throw new RuntimeException(LIST.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static void addOpaqueError(boolean opaque) {
|
||||
LIST.add(getLookAndFeel().getName() + " background color wrong for opaque=" + opaque);
|
||||
}
|
||||
|
||||
private static boolean updateLookAndFeel() {
|
||||
int index = (int) LATCH.getCount() - 1;
|
||||
if (index >= 0) {
|
||||
ROBOT.setAutoWaitForIdle(true);
|
||||
ROBOT.setAutoDelay(100);
|
||||
for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
|
||||
System.out.println("Testing L&F: " + laf.getClassName());
|
||||
SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));
|
||||
try {
|
||||
LookAndFeelInfo info = INFO[index];
|
||||
System.err.println("L&F: " + info.getName());
|
||||
setLookAndFeel(info.getClassName());
|
||||
return true;
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
SwingUtilities.invokeAndWait(() -> createGUI());
|
||||
ROBOT.waitForIdle();
|
||||
ROBOT.delay(1000);
|
||||
SwingUtilities.invokeAndWait(() -> test(laf));
|
||||
ROBOT.delay(2000);
|
||||
} finally {
|
||||
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
|
||||
}
|
||||
ROBOT.delay(1000);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private JFrame frame;
|
||||
private JTabbedPane pane;
|
||||
|
||||
public void run() {
|
||||
if (this.frame == null) {
|
||||
if (!updateLookAndFeel()) {
|
||||
return;
|
||||
}
|
||||
this.pane = new JTabbedPane();
|
||||
this.pane.setOpaque(false);
|
||||
this.pane.setBackground(Color.RED);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
this.pane.addTab("Tab " + i, new JLabel("Content area " + i));
|
||||
}
|
||||
this.pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
|
||||
this.frame = new JFrame(getClass().getSimpleName());
|
||||
this.frame.getContentPane().setBackground(Color.BLUE);
|
||||
this.frame.add(this.pane);
|
||||
this.frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
this.frame.setSize(400, 200);
|
||||
this.frame.setLocationRelativeTo(null);
|
||||
this.frame.setVisible(true);
|
||||
} else {
|
||||
Point point = new Point(this.pane.getWidth() - 2, 2);
|
||||
convertPointToScreen(point, this.pane);
|
||||
Color actual = ROBOT.getPixelColor(point.x, point.y);
|
||||
|
||||
boolean opaque = this.pane.isOpaque();
|
||||
Color expected = opaque
|
||||
? this.pane.getBackground()
|
||||
: this.frame.getContentPane().getBackground();
|
||||
|
||||
System.out.println("expected " + expected + " actual " + actual);
|
||||
if (!expected.equals(actual)){
|
||||
addOpaqueError(opaque);
|
||||
}
|
||||
if (!opaque) {
|
||||
this.pane.setOpaque(true);
|
||||
this.pane.repaint();
|
||||
} else {
|
||||
this.frame.dispose();
|
||||
this.frame = null;
|
||||
this.pane = null;
|
||||
LATCH.countDown();
|
||||
}
|
||||
|
||||
private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
|
||||
try {
|
||||
UIManager.setLookAndFeel(laf.getClassName());
|
||||
} catch (UnsupportedLookAndFeelException ignored) {
|
||||
System.out.println("Unsupported L&F: " + laf.getClassName());
|
||||
} catch (ClassNotFoundException | InstantiationException
|
||||
| IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
ROBOT.delay(2000);
|
||||
SecondaryLoop secondaryLoop =
|
||||
Toolkit.getDefaultToolkit().getSystemEventQueue()
|
||||
.createSecondaryLoop();
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
secondaryLoop.exit();
|
||||
invokeLater(TestBackgroundScrollPolicy.this);
|
||||
}
|
||||
}.start();
|
||||
secondaryLoop.enter();
|
||||
}
|
||||
|
||||
private static void addOpaqueError(UIManager.LookAndFeelInfo laf, boolean opaque) {
|
||||
throw new RuntimeException(laf.getClassName() + " background color wrong for opaque=" + opaque);
|
||||
}
|
||||
|
||||
private static JFrame frame;
|
||||
private static JTabbedPane pane;
|
||||
|
||||
public static void createGUI() {
|
||||
pane = new JTabbedPane();
|
||||
pane.setOpaque(true);
|
||||
pane.setBackground(Color.RED);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
pane.addTab("Tab " + i, new JLabel("Content area " + i));
|
||||
}
|
||||
pane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
|
||||
pane.repaint();
|
||||
frame = new JFrame();
|
||||
frame.getContentPane().setBackground(Color.BLUE);
|
||||
frame.add(pane);
|
||||
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
frame.setSize(400, 200);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setVisible(true);
|
||||
frame.toFront();
|
||||
}
|
||||
|
||||
public static void test(UIManager.LookAndFeelInfo laf) {
|
||||
Point point = new Point(pane.getWidth() - 2, 2);
|
||||
SwingUtilities.convertPointToScreen(point, pane);
|
||||
Color actual = ROBOT.getPixelColor(point.x, point.y);
|
||||
|
||||
boolean opaque = pane.isOpaque();
|
||||
Color expected = opaque
|
||||
? pane.getBackground()
|
||||
: frame.getContentPane().getBackground();
|
||||
|
||||
if (!expected.equals(actual)){
|
||||
System.out.println("expected " + expected + " actual " + actual);
|
||||
addOpaqueError(laf, opaque);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user