aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes how to open picture in JPanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to open picture in JPanel" Watch "how to open picture in JPanel" New topic
Author

how to open picture in JPanel

Bobby Marvikuan
Ranch Hand

Joined: Mar 14, 2012
Posts: 54
how to open picture in JPanel??? I have code but it does not do anything=/
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18121
    
    8

Creating a new JLabel inside your action event is a very strange thing to do. You might be able to make that code work if you subsequently added the JLabel to your GUI, but in your case I would recommend you keep it simple. Use a JLabel which is already part of your GUI to display the picture.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4522
    
    5

Whenever you add components to an already realized container, you need to call revalidate(). In the case of removing components, it's necessary to additionally repaint() the container.

Since repaint() isn't usually computationally expensive, take the safe path and call both whenever you add or remove components.


luck, db
There are no new questions, but there may be new answers.
Bobby Marvikuan
Ranch Hand

Joined: Mar 14, 2012
Posts: 54
Darryl Burke wrote:Whenever you add components to an already realized container, you need to call revalidate(). In the case of removing components, it's necessary to additionally repaint() the container.

Since repaint() isn't usually computationally expensive, take the safe path and call both whenever you add or remove components.

cheers a lot!
Bobby Marvikuan
Ranch Hand

Joined: Mar 14, 2012
Posts: 54
Paul Clapham wrote:Creating a new JLabel inside your action event is a very strange thing to do. You might be able to make that code work if you subsequently added the JLabel to your GUI, but in your case I would recommend you keep it simple. Use a JLabel which is already part of your GUI to display the picture.

Thank you!:)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to open picture in JPanel
 
Similar Threads
ImageIcon not working
drawing to the file with GDC
How to open a file using Java
Using a FileChooser to get and display an image
HELP! me pls i can't open image on JLabel