我有一個JOptionPane和一個自定義的消息面板,在一個針對Java 1.5的應用程序中。該面板除其他外還包含一個JTextField。每調用20次,對話框中的任何內容都不會被繪製(甚至沒有OK/Cancel按鈕)。如果我將對話框從屏幕拖出來並再次強制重畫,那麼這些組件可以按預期顯示出來,除了繪畫問題之外,這些組件可以很好地響應。這裏是我可以展示此bug的最小示例:Java 1.5 JOptionPane使用面板消息/解決方法時出現錯誤?
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,
"SomeTitle", JOptionPane.OK_CANCEL_OPTION,
JOptionPane.PLAIN_MESSAGE, null, null, null);
}
}
});
}
}
這是Swing中一個衆所周知的錯誤嗎?有沒有標準的解決方法?我一直無法找到官方的錯誤報告。該錯誤似乎並未出現在Java 1.7中,但我的應用程序需要運行在較舊的1.5版上,我希望找到適用於後者的解決方法。
相關:Modeless JDialog not showing contents(不包括代碼示例,所以很難知道它是否是相同的錯誤)
具體的Java版本我發現的bug的是1.5.0_22。
請其版本的Java5,因爲我有jdk1.5.0_22作爲最穩定的版本 – mKorbel
它是JRE 1.5.0_22具體。 – eirikbakke
無法複製,包括在JProfiler – mKorbel