JOptionPane and scroll function

user1060187 picture user1060187 · Dec 4, 2011 · Viewed 20.4k times · Source

I want to JList a lot of results in a JOptionPane, however, I'm not sure how to add in a scroll function should there be too many results. How would I add a scroll bar to a JOptionPane? Any help would be great.

Thanks.

Answer

GETah picture GETah · Dec 4, 2011

Here is an example using a JTextArea embedded in a JScrollPane:

JTextArea textArea = new JTextArea("Insert your Text here");
JScrollPane scrollPane = new JScrollPane(textArea);  
textArea.setLineWrap(true);  
textArea.setWrapStyleWord(true); 
scrollPane.setPreferredSize( new Dimension( 500, 500 ) );
JOptionPane.showMessageDialog(null, scrollPane, "dialog test with textarea",  
                                       JOptionPane.YES_NO_OPTION);