Skip to content

Commit e783c52

Browse files
committed
8368185: Test javax/swing/plaf/synth/SynthButtonUI/6276188/bug6276188.java failed: Synth ButtonUI does not handle PRESSED & MOUSE_OVER state
Reviewed-by: tr, aivanov
1 parent eb34a11 commit e783c52

1 file changed

Lines changed: 36 additions & 15 deletions

File tree

test/jdk/javax/swing/plaf/synth/SynthButtonUI/6276188/bug6276188.java

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2025, 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
@@ -21,47 +21,67 @@
2121
* questions.
2222
*/
2323
/**
24-
* @test 1.4 08/08/05
24+
* @test
2525
* @key headful
2626
* @bug 6276188
2727
* @library ../../../../regtesthelpers
2828
* @build Util
29-
* @author Romain Guy
3029
* @summary Tests PRESSED and MOUSE_OVER and FOCUSED state for buttons with Synth.
3130
* @run main/othervm -Dsun.java2d.uiScale=1 bug6276188
3231
*/
33-
import java.awt.*;
34-
import java.awt.image.*;
35-
import java.awt.event.*;
3632

37-
import javax.swing.*;
38-
import javax.swing.plaf.synth.*;
33+
import java.io.File;
34+
import java.awt.BorderLayout;
35+
import java.awt.Color;
36+
import java.awt.Dimension;
37+
import java.awt.Point;
38+
import java.awt.Rectangle;
39+
import java.awt.Robot;
40+
import java.awt.Toolkit;
41+
import java.awt.image.BufferedImage;
42+
import java.awt.event.InputEvent;
43+
import java.awt.event.MouseAdapter;
44+
import java.awt.event.MouseEvent;
45+
import javax.imageio.ImageIO;
46+
import javax.swing.JButton;
47+
import javax.swing.JFrame;
48+
import javax.swing.plaf.synth.SynthLookAndFeel;
49+
import javax.swing.SwingUtilities;
50+
import javax.swing.UIManager;
51+
import java.util.concurrent.CountDownLatch;
3952

4053
public class bug6276188 {
4154

4255
private static JButton button;
43-
private static Point p;
4456
private static JFrame testFrame;
4557

4658
// move away from cursor
47-
private final static int OFFSET_X = -20;
48-
private final static int OFFSET_Y = -20;
59+
private final static int OFFSET_X = 20;
60+
private final static int OFFSET_Y = 20;
4961

5062
public static void main(String[] args) throws Throwable {
63+
Robot robot = new Robot();
5164
try {
52-
Robot robot = new Robot();
5365
robot.setAutoDelay(100);
5466

5567
SynthLookAndFeel lookAndFeel = new SynthLookAndFeel();
5668
lookAndFeel.load(bug6276188.class.getResourceAsStream("bug6276188.xml"), bug6276188.class);
5769
UIManager.setLookAndFeel(lookAndFeel);
70+
CountDownLatch latch = new CountDownLatch(1);
5871

5972
SwingUtilities.invokeAndWait(new Runnable() {
6073
public void run() {
6174
testFrame = new JFrame();
6275
testFrame.setLayout(new BorderLayout());
6376
testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
6477
testFrame.add(BorderLayout.CENTER, button = new JButton());
78+
button.addMouseListener(new MouseAdapter() {
79+
@Override
80+
public void mousePressed(MouseEvent e) {
81+
System.out.println("Mouse pressed");
82+
latch.countDown();
83+
}
84+
});
6585

6686
testFrame.setSize(new Dimension(320, 200));
6787
testFrame.setLocationRelativeTo(null);
@@ -72,13 +92,14 @@ public void run() {
7292
robot.waitForIdle();
7393
robot.delay(1000);
7494

75-
p = Util.getCenterPoint(button);
95+
Point p = Util.getCenterPoint(button);
7696
System.out.println("Button center point: " + p);
7797

7898
robot.mouseMove(p.x , p.y);
7999
robot.waitForIdle();
80100
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
81-
robot.waitForIdle();
101+
latch.await();
102+
robot.delay(1000);
82103

83104
Color color = robot.getPixelColor(p.x - OFFSET_X, p.y - OFFSET_Y);
84105
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
@@ -89,7 +110,7 @@ public void run() {
89110
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
90111
Rectangle screen = new Rectangle(0, 0, (int) screenSize.getWidth(), (int) screenSize.getHeight());
91112
BufferedImage img = robot.createScreenCapture(screen);
92-
javax.imageio.ImageIO.write(img, "png", new java.io.File("image.png"));
113+
ImageIO.write(img, "png", new File("image.png"));
93114
throw new RuntimeException("Synth ButtonUI does not handle PRESSED & MOUSE_OVER state");
94115
}
95116
} finally {

0 commit comments

Comments
 (0)