Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Swing / AWT / SWT and the fly likes what is wrong in the code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "what is wrong in the code?" Watch "what is wrong in the code?" New topic
Author

what is wrong in the code?

Komal Arora
Ranch Hand

Joined: Sep 30, 2010
Posts: 91

I am making a gui to open image files, display them, manipulate them and then save them. In the menu bar there is a file option which has the "open" option. i am using event handling to open an image file when we click on the open option. by using the following code, the image file is being read. now i want to display the image file on my frame. for that i used Image icon. But, the image is displayed once you minimize and then maximize the frame. it does not display instantaneously. what is wrong in the code?



OCPJP
Tarun Bolla
Ranch Hand

Joined: Jun 20, 2011
Posts: 89
Try this

right after
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

JFrame doesn't have a revalidate() method; you need to either pack() the frame or revalidate() its contentPane.


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

Joined: Sep 30, 2010
Posts: 91

the f.validate() worked. thanks
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1449
    
    6

Darryl,

It has been added since 1.7


Swastik
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Swastik Dey wrote:Darryl,

It has been added since 1.7

I hadn't noticed that, thank you for sharing the information here.

To be more specific for the benefit of others who may read this thread, revalidate() has been added to java.awt.Component.
Komal Arora
Ranch Hand

Joined: Sep 30, 2010
Posts: 91

ok the image is displaying fine with f.validate. now the problem is that if one image is displayed, and i try to open another image, the second image opens but it's like it is pasted over the 1st one. what should i do so that this does not happen?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
this stuff should be in createGUI()



and in your filechooser code you should have
Komal Arora
Ranch Hand

Joined: Sep 30, 2010
Posts: 91

Thanks Michael, it worked
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: what is wrong in the code?
 
Similar Threads
how to create a search engine?
display contents of a text file in a new window
Adding a new JMenu to an existing JMenuBar
Global Editor project
display image selected by Jfilechooser on the content pane of the frame