Java Swing How to - Display data of an array JOptionPane MessageDialog








Question

We would like to know how to display data of an array JOptionPane MessageDialog.

Answer

import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
//www . j  a v a 2  s . c  om
public class Main {
  public static void main(String[] args) {
    String[] items = { "1|9|2", "1|9|1", "1|4|7" };
    JList list = new JList(items);
    JPanel panel = new JPanel();
    panel.add(new JScrollPane(list));
    JOptionPane.showMessageDialog(null, panel);
  }
}