1

I try to display an ArrayList in a nice way into an InfoBox. The ArrayList contains names (String) of files that got edited in a certain period of work and gets created automatically.

If I use JOptionPane.showMessageDialog, I get a super long window that is impossible to read. It would be better to have a nice list view. How do I do that?

The parts of the code affected:

//List initiation

List output = new ArrayList();

//FIll List with data

for (String fileOrFilderName : changedFilesAndFolders) { 
    output.add(fileOrFilderName);
}

//Output

JOptionPane.showMessageDialog(null, output, "Edited or added files",
                   JOptionPane.INFORMATION_MESSAGE);

Output: Too long window

4
  • 1
    Show us your code. Commented Jan 30, 2017 at 10:00
  • //List initiation List output = new ArrayList(); //FIll List with data for (String fileOrFilderName : changedFilesAndFolders) { output.add(fileOrFilderName);} //Output JOptionPane.showMessageDialog(null, output, "Edited or added files", JOptionPane.INFORMATION_MESSAGE); Commented Jan 30, 2017 at 10:02
  • 1
    Create your own dialog, insert a JList, make it scrollable and insert your values. Commented Jan 30, 2017 at 10:02
  • Don't use raw types. Commented Jan 30, 2017 at 10:48

2 Answers 2

2

Bundle your output into a javax.swing.JList decorated by a javax.swing.JScrollPane.

For example:

    List<String> output = new ArrayList<>();

    //FIll List with data
    for (String fileOrFilderName : changedFilesAndFolders) {
        output.add(fileOrFilderName);
    }

    //Output

    JList<String> list = new JList<>(new Vector<>(output));

    JOptionPane.showMessageDialog(null, new JScrollPane(list), "Edited or added files", JOptionPane.INFORMATION_MESSAGE);

Hope this helps!

Sign up to request clarification or add additional context in comments.

1 Comment

thats exactly what i was looking for, it worked. Thanks!
0

@Benjamin Maier, you can add any JComponent om the JOptionPane. So what you do is to add JScrollpane to it containing JList.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.