我在一个针对Java 1.5的应用程序中有一个带有自定义消息面板的JOptionPane.该面板包含JTextField等.每20个调用左右,对话框中的任何内容都不会被绘制(甚至不是OK/Cancel按钮).如果我将对话框从屏幕拖出并再次返回以强制重新绘制,则组件可以按预期显示,除了绘制问题之外,组件响应正常.这是我可以展示这个bug的最小例子:
public class BugTest {
public static void main(String args[]) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// The text field needs to be wrapped in a panel for the bug to show up.
JPanel messagePanel = new JPanel();
// A JLabel won't exhibit the bug, but a JTextField will.
JTextField textField = new JTextField("Some content");
messagePanel.add(textField);
// Loop so we can keep clicking OK until the bug shows up.
while (true) {
int res = JOptionPane.showOptionDialog(null, messagePanel, …Run Code Online (Sandbox Code Playgroud)