Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java, how can I popup a dialog box as only an image?

I'm trying to find a way to replace all the contents of a JDialog to simply an image. It's for the about page of a project I'm working on and I want when the user clicks on the About section, an image to popup in the style of a JDialog(and to disappear when focus is lost). Example: http://www.tecmint.com/wp-content/uploads/2012/08/About-Skype.jpg There Skype displays only an image they've created as their "About" page. How can I make an "image dialog" in Java(swing)?

like image 589
martin Avatar asked Dec 11 '22 17:12

martin


2 Answers

How can I make an "image dialog" in Java(swing)?

Use an undecorated JDialog with a JLabel containing an ImageIcon:

JDialog dialog = new JDialog();
dialog.setUndecorated(true);
JLabel label = new JLabel( new ImageIcon(...) );
dialog.add( label );
dialog.pack();
dialog.setVisible(true);
like image 148
camickr Avatar answered Dec 24 '22 17:12

camickr


BufferedImage image = ImageIO.read(new File("myfile.png"));
JLabel picLabel = new JLabel(new ImageIcon(image));
JOptionPane.showMessageDialog(null, picLabel, "About", JOptionPane.PLAIN_MESSAGE, null);
like image 40
martinez314 Avatar answered Dec 24 '22 18:12

martinez314