views:

94

answers:

2

How do you create a JavaFX application that (instantly) dynamically resizes? Right now I have coded a simple application that dynamically resizes but the layout changes don't display until after the release of the mouse button on a drag. I want instantly see the results/layout changes before this button release.

I'm assuming this is done by just binding the correct values/controls with inverse... Any help would be great!


EDIT:

Here's how I got things working (thanks to Praeus). Exactly as he said, I had to bind my top level container/layout width and height to scene.width and scene.height. --

var scene: Scene;

Stage {
title: "Application title"
scene: scene = Scene {
content: [
XMigLayout {
width: bind scene.width;
height: bind scene.height;
...}]}}

+1  A: 

Yes I think you're on the right lines - binding would be the obvious way to do what you trying to do. You could also look at triggers.

Read the 1.3 guide to layouts as a starting point if you haven't already

The layout containers automatically manage the dynamic layout behavior of their content nodes. However, it is often desirable to also use the binding mechanism of the JavaFX Script to establish certain dynamic aspects of layout. For example, you can bind the width and height of an HBox container to the Scene height and width so that whenever Scene resizes, the HBox container resizes as well.

It's also probably worth reading articles and blog posts by JavaFX layout guru Amy Fowler

Matthew Hegarty
Thanks for the response! Yeah, I already had my interface structured using layout containers. I will check out some of the resources you have listed... though Amy Fowler's blog is blocked at my workplace for "social media." Lame.
Greg
+1  A: 

Actually if you've already organized everything into layouts, then you might be able to just bind the top level layout container(s) width and height to the scene.width and scene.height. I don't think top level layout controls are managed by anything, so you may be safe just setting width and height of the layout control directly. If that doesn't work then you might have success binding the layoutInfo width and height.

Ideally you want to use layout management before resorting to binds. Excessive binds can be a performance problem, and can lead to slow redraws as you are resizing. In this case you can probably just use binds for the top level container, and then all of the children of the top level container should resize accordingly. At least I think that should work.

Praeus
That did the trick. Thanks! I had to bind my top level container (layout) to scene width and height as you said. Just had to create a variable to provide a way to reference scene.width and scene.height. I edited my original post to show this solution.
Greg