Correctly displaying buttons in jOptionPane when text size of the message displayed grows
I have written the code below to show some information and get reponse from the user through a jOptionPane. Now the text provided to this method grows as time passes and after some time when the amount of text increases the jOptionPane acts weird and sometimes does not show the buttons and t开发者_开发问答he whole panel gets occupied by the text and the buttons are not accessible.
How can I fix this?
public void jOptionPane1(agent, text) {
if (GetParameter("MessagesCheck")) {
String[] choices = ["Yes", "No", "Default"]
JTextArea textArea = new JTextArea(text);
textArea.setColumns(125);
textArea.setLineWrap(true); textArea.setWrapStyleWord(true);
int response = JOptionPane.showOptionDialog(null,textArea,"choices",0,JOptionPane.INFORMATION_MESSAGE,null,choices,choices[2]);
}
}
Add a JScrollPane to the option pane. The setLineWrap was designed to be used when the text area is added to a scroll pane.
Build your own dialog using a JDialog
and specify the layout, buttons and any other details to needed to eliminate the "weird behaviour". JOptionPane
is handy, but not a silver bullet for dialogs.
精彩评论