• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I got a problem about JFrame.

 
Yanxin Zhao
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, everybody,
I wanted to implemented that a JButton in a JFrame, And when I click which button, a picture will be displayed on the JFrame. But how can I enable the size of the JFrame be changed into a suitable size ? And this is also my problem.
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You use setSize(width, height) to change the size of a JFrame. How are you getting/storing the image? The Image class has getHeight() and getWidth() methods.
 
Kai Witte
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

when the Component that displays your image automatically has the correct preferred size, you can use JFrame#pack().

Conan
 
Yanxin Zhao
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much for your replyes. But I do not think that setSize() and pack() can do what I wanted to do. I used this to show my pic.


Although the pic can be add into JFrame, but the size of JFrame still can not be changed.
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, I tried changing your code and making it change the size of the parent component as well, but that didn't work either. Now I'm kind of stuck too
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic