I am learning java swing. The code below is a catch block that handles an IOException and displays an 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 setting up a JOptionPane of my own inside the catch block, for example, 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 do not know how to make it appear on the screen, as the showMessageDialogue method does. Please help. Thanks in advance.
source
share