JavaFX Bug or Feature? Panel doesn't layout if placed in class
I run into a strange problem. I think I have missed something. So every hint is welcome!
Try this demo:
[cc lang="c"]import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.Panel;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.layout.Container;
public function run( ) {
//Remove the next two lines for a miracle!
Asdf {}}
public class Asdf {
def stage: Stage = Stage {
scene: Scene {
width: 800
height: 600
content: [
{
def p: Panel = Panel {
width: bind stage.scene.width
height: bind stage.scene.height
onLayout: function (): Void {
p.resizeContent();
for ( node in Container.getManaged( p.content ) ) {
Container.positionNode( node, indexof node * 20 + 50, indexof node * 30 + 40, true );
}
}
content: [
Rectangle {
width: 140, height: 90
fill: Color.ORANGE
opacity: 0.5
},
Rectangle {
width: 100, height: 120
fill: Color.BLUE
opacity: 0.5
}, ]
}
},
]
}
};
}
[/cc]
The layout of the panel doesn’t work properly…
Now lets move the stage directly into the run function (just remove two lines):
[cc lang="c"]
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.Panel;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.layout.Container;
public function run( ) {
//Remove the next two lines for a miracle!
//Asdf {}}
//public class Asdf {
def stage: Stage = Stage {
scene: Scene {
width: 800
height: 600
content: [
{
def p: Panel = Panel {
width: bind stage.scene.width
height: bind stage.scene.height
onLayout: function (): Void {
p.resizeContent();
for ( node in Container.getManaged( p.content ) ) {
Container.positionNode( node, indexof node * 20 + 50, indexof node * 30 + 40, true );
}
}
content: [
Rectangle {
width: 140, height: 90
fill: Color.ORANGE
opacity: 0.5
},
Rectangle {
width: 100, height: 120
fill: Color.BLUE
opacity: 0.5
}, ]
}
},
]
}
};
}
[/cc]
Now everything works as expected! Any hints?
May 3rd, 2010 at 01:40
[...] Johannes Schneider has done a tonne of posts recently, so I can only cover the blog titles here. ‘JavaFX: Custom controls in 1.3‘, ‘JavaFX 1.3: Template for custom controls‘, ‘JavaFX Light Bulb with improved UI performance‘, ‘JavaFX: Bug in Timeline(?!)‘, ‘JavaFX: Transparency and Linux‘, ‘New JavaFX default font (Amble Condensed) looks ugly!‘, ‘JavaFX: Making a CustomNode resizable‘, ‘JavaFX: Template for resizable CustomNode‘, ‘JavaFX: How to extend CustomNode properly‘, and ‘JavaFX Bug or Feature? Panel doesn’t layout if placed in class‘ [...]
May 11th, 2010 at 20:45
Hi!
The first sample declares the (one and only) stage object on scripting level. The JavaFX compiler is able to use this stage object like with declarative programming:
Stsge {
…
}
If you omit the run method, JavaFX creates this method for you. So this is equal:
run () {
Stage {}
}
In the second example the stage object is defined on class level. The “magic” stage-call (open and layout) generated by the JavaFX compiler is broken.
br, josh.
June 2nd, 2010 at 10:31
Thanks for the explanation. I think I should make my hands dirty and use a decompiler…
I just don’t get why such basic things are still broken…