Mega Code Archive

 
Categories / Java Tutorial / Swing
 

Complex message arguments

The message argument not only supports displaying an array of strings, but it also can support an array of any type of object. If the element is an Icon, the icon is placed within a JLabel, import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JOptionPane; import javax.swing.JSlider; public class ComplexMessageDemo {   public static void main(String[] a) {     Object complexMsg[] = { "Above Message", new ImageIcon("yourFile.gif"), new JButton("Hello"),         new JSlider(), new ImageIcon("yourFile.gif"), "Below Message" };     JOptionPane optionPane = new JOptionPane();     optionPane.setMessage(complexMsg);     optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE);     JDialog dialog = optionPane.createDialog(null, "Width 100");     dialog.setVisible(true);   } }