Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is wrong in the code?

 
Komal Arora
Ranch Hand
Posts: 91
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
Tarun Bolla
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this

right after
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JFrame doesn't have a revalidate() method; you need to either pack() the frame or revalidate() its contentPane.
 
Komal Arora
Ranch Hand
Posts: 91
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the f.validate() worked. thanks
 
Swastik Dey
Rancher
Posts: 1602
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl,

It has been added since 1.7
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this stuff should be in createGUI()



and in your filechooser code you should have
 
Komal Arora
Ranch Hand
Posts: 91
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael, it worked
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic