I am learning java swing. The code below is a catch block which handles an IOException and shows a error message.
catch(IOException e)
{
System.out.println("IOException");
JOptionPane.showMessageDialog(null,"File not found",null,
JOptionPane.ERROR_MESSAGE);
}
I was thinking of declaring and customizing a JOptionPane of my own inside the catch block like the code below:
JOptionPane jop=new JOptionPane();
jop.setLayout(new BorderLayout());
JLabel im=new JLabel("Java Technology Dive Log",
new ImageIcon("images/gwhite.gif"),JLabel.CENTER);
jop.add(im,BorderLayout.NORTH);
jop.setVisible(true);
But the problem is that I don't know how to make it appear on the screen as the showMessageDialogue method does. Please help. Thanks in advance.
I guess that depends on what's wrong with
JOptionPaneshowMessageDialog(Component parentComponent, Object message, String title, int messageType, Icon icon)
?You can simply add your components to a
JPanel
and then add thisJPanel
to yourJOptionPane
, as shown in this small example :