1

I'm working on a program that displays a MessageDialog which shows data of an array I created. Each line for example:

11327|933393|2 is inside element 0 of an array.
11833|938393|1 is inside element 1 of an array.

For example pretend the numbers below are inside the MessageDialog:

11327|933393|2
11833|938393|1
11934|483393|7

My only problem is that I can only display each element of the array one by one per MessageDialog. but I want to display all 3 elements inside one single MessageDialog.

Any hints or tips of how I can display my entire array inside one MessageDialog? :)

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user983246
  • 1,429
  • 6
  • 19
  • 20

1 Answers1

6

You can place arbitrary components in your dialog, as shown in this example. A JList or JTable would seem to be a good choice.

Addendum: Here's a simple example using JList.

enter image description here

import java.awt.EventQueue;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/** @see https://stackoverflow.com/questions/7781781 */
public class OptionList {

    private void display() {
        String[] items = {
            "11327|933393|2", "11833|938393|1", "11934|483393|7"
        };
        JList list = new JList(items);
        JPanel panel = new JPanel();
        panel.add(list);
        JOptionPane.showMessageDialog(null, panel);
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new OptionList().display();
            }
        });
    }
}
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I forgot to mention the data is from a textfile. – user983246 Oct 16 '11 at 02:01
  • 1
    Excellent! You now have a working [sscce](http://sscce.org/) from which to start. [`BufferedReader`](http://download.oracle.com/javase/7/docs/api/java/io/BufferedReader.html) may be a good choice. Is this homework? – trashgod Oct 16 '11 at 02:08