Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Proportional resizing of the main window

 
Ron Alby
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to ensure that my main window always has the same height/width ratio. I was hoping there would be some sort of 'Resize' event, but I can't find one.

I can get separate callbacks on height changing and width changing - but trying to maintain proportions in two separate callbacks strikes me as being a lot more difficult (they can be making it larger or smaller, sometimes they change height, sometimes they change width, sometimes they change both at the same time).

Can anyone point me to a solution? Sorry if there is an obvious solution I'm just overlooking.

Ron
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think I know the answer, but anyone who might would first need to know whether your question pertains to JavaFX Script (aka 1.x) or JavaFX 2.
 
Ron Alby
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah ... sorry about that
Java 2.1-Beta on Ubuntu Linux
 
John Damien Smith
Ranch Hand
Posts: 285
13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the sample code here on how to listen to stage (JavaFX term for most windows) size changes and modify the size of the stage if necessary:
https://forums.oracle.com/forums/thread.jspa?messageID=10004342

Essentially, you can do something like this:

And the do the same for height.
Then bind the stageHeightProperty to a proportion of the stageWidthProperty, e.g.

I didn't try the exact code to get the exact result you are requesting, but by playing around using the tips provided you should be able to achieve the effect you need.
 
Ron Alby
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately, I could not get that to work. Creating new simple double properties passing in the width in the constructor did not trigger the callback. When I used the actual stage properties it said they had to be read only properties. When I did a cast I got a cast exception.

I gave up on binding and just tried to change the size in the callback of the read only property ... it's funny, the callback kept getting the updated size but the size never changed on the screen.

At this point I'm about to set resize to false.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic