Skip to content

Commit fc652d2

Browse files
author
Alisen Chung
committed
8235404: [macos] JOptionPane blocks drawing string on another component
Reviewed-by: honkar, dnguyen
1 parent 22a3421 commit fc652d2

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

src/java.desktop/share/classes/javax/swing/JOptionPane.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2024, 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
@@ -883,6 +883,11 @@ public static int showOptionDialog(Component parentComponent,
883883

884884
Object selectedValue = pane.getValue();
885885

886+
if (parentComponent != null) {
887+
parentComponent.revalidate();
888+
parentComponent.repaint();
889+
}
890+
886891
if(selectedValue == null)
887892
return CLOSED_OPTION;
888893
if(options == null) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) 2024, 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.Canvas;
25+
import java.awt.Color;
26+
import java.awt.Graphics2D;
27+
import javax.swing.JFrame;
28+
import javax.swing.JOptionPane;
29+
import javax.swing.JTextField;
30+
import javax.swing.SwingUtilities;
31+
32+
/*
33+
* @test
34+
* @bug 8235404
35+
* @summary Checks that JOptionPane doesn't block drawing strings on another component
36+
* @library /java/awt/regtesthelpers
37+
* @build PassFailJFrame
38+
* @run main/manual OptionPaneInput
39+
*/
40+
public class OptionPaneInput {
41+
private static JFrame f;
42+
private static Canvas c;
43+
private static JTextField t;
44+
private static final String instructions = """
45+
1. Type "test" into the message dialog.
46+
2. Press enter key.
47+
3. Press OK button.
48+
4. If the OptionPaneInput frame has test drawn on it, pass. Otherwise fail.
49+
""";
50+
51+
public static void main(String[] args) throws Exception {
52+
PassFailJFrame testFrame = new PassFailJFrame(instructions);
53+
54+
SwingUtilities.invokeAndWait(() -> createGUI());
55+
testFrame.awaitAndCheck();
56+
}
57+
58+
public static void createGUI() {
59+
f = new JFrame("OptionPaneInput");
60+
c = new Canvas();
61+
t = new JTextField();
62+
f.add(c);
63+
64+
t.addActionListener(e -> {
65+
String text = t.getText();
66+
Graphics2D g2 = (Graphics2D)(c.getGraphics());
67+
g2.setColor(Color.BLACK);
68+
g2.drawString(text, 10, 10);
69+
System.out.println("drawing "+text);
70+
g2.dispose();
71+
});
72+
73+
f.setSize(300, 100);
74+
PassFailJFrame.addTestWindow(f);
75+
PassFailJFrame.positionTestWindow(f, PassFailJFrame.Position.HORIZONTAL);
76+
f.setVisible(true);
77+
78+
JOptionPane.showMessageDialog(f, t);
79+
}
80+
}

0 commit comments

Comments
 (0)