• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JFrame resize

 
Timothy Leong
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when a user resize the java application, how can I get dimensions before resized and dimensions after resize??
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't believe there are events for "about to resize" so what I would do is store your deminsions when your application first loads. Afterwhich you can capture resize events and store them accordingly.
 
Timothy Leong
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I want to store the dimensions when the java Frame first loads. I should call getHeight, getWidth from the constructor right? But the value I gotten is 0. Is there anyway I can get the initial value?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
call your getWidth() getHeight() after setting the frame's visibility to true
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Dunn:
call your getWidth() getHeight() after setting the frame's visibility to true


I was going to suggest that but wanted to do a bit more research on when the size actually gets set. It seems odd to me that setting the frame visible is when that happens. To me it makes more sense for it to be when a) pack() is called or b) setSize(x,y) is called. I'd assume, though I haven't tested, that setVisible(false) will then return 0,0 for w and h. Again, seems odd as the frame is not disposed of, merely invisible. I guess if you think of it in terms of the frame being "turned off" then it makes more sense. But still odd.

Ok, I am rambling and it doesn't really matter. Michael is right, of course.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic