Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JOptionPane and scroll function

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.

like image 538
user1060187 Avatar asked Dec 04 '11 11:12

user1060187


People also ask

What is the purpose of a JOptionPane?

The JOptionPane class is used to provide standard dialog boxes such as message dialog box, confirm dialog box and input dialog box. These dialog boxes are used to display information or get input from the user. The JOptionPane class inherits JComponent class.

What are the 4 JOptionPane dialog boxes?

Java AWT Programming Project The JOptionPane displays the dialog boxes with one of the four standard icons (question, information, warning, and error) or the custom icons specified by the user.

What is dialog box in Java?

Dialog boxes are graphical components that are usually used to display errors or give some other information to the user. They are part of the three top-level containers that each Java graphical user interface (GUI) application must have as a root. Dialogs are created as part of a frame.


1 Answers

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);
like image 113
GETah Avatar answered Sep 18 '22 23:09

GETah