JDK-8113419 : JavaFX Controls do not return their Bounds
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: fx2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • Submitted: 2011-05-24
  • Updated: 2023-08-23
  • Resolved: 2011-05-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
fx2.0Resolved
Description
* PROCEDURE
Label l = new Label("bla");
System.out.println(l.getBoundsInLocal());
System.out.println(l.getBoundsInParent());

* PROBLEM
BoundingBox [minX:0.0, minY:0.0, minZ:0.0, width:-1.0, height:-1.0, depth:0.0, maxX:-1.0, maxY:-1.0, maxZ:0.0]
BoundingBox [minX:0.0, minY:0.0, minZ:0.0, width:-1.0, height:-1.0, depth:0.0, maxX:-1.0, maxY:-1.0, maxZ:0.0]

* COMMENT
same happens with methos getWidth(), getHeight(), getMaxWidth, ... 
Although the controls are painted perfectly, there seems to be no way to retrieve their postions / bounds.
Comments
TYVM
24-05-2011

Having looked at your sample code, the scene is still not 'live' - to be live it needs to be visible, however, your call to stage.setVisible(true) occurs after your System.out.println calls. If you move the println calls to be after the stage.setVisible(true) call, then you get output such as the following: BoundingBox [minX:0.0, minY:0.0, minZ:0.0, width:16.0, height:15.0, depth:0.0, maxX:16.0, maxY:15.0, maxZ:0.0] BoundingBox [minX:0.0, minY:0.0, minZ:0.0, width:16.0, height:15.0, depth:0.0, maxX:16.0, maxY:15.0, maxZ:0.0]
24-05-2011

Thanks. This is fine - I'll investigate it further when time permits.
24-05-2011

import javafx.application.Launcher; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.layout.VBox; import javafx.stage.Stage; /** * @author D052040 * */ public class App extends Application { @Override public void start(Stage stage) { VBox root = new VBox(); Scene scene = new Scene(root); stage.setScene(scene); Label l = new Label("bla"); root.getChildren().add(l); System.out.println(l.getBoundsInLocal()); System.out.println(l.getBoundsInParent()); stage.setVisible(true); } public static void main(String args[]) { Launcher.launch(App.class, args); } } called after being added to a live scene. I think this should be sufficient as minimal example, do you need anything else?
24-05-2011

You don't mention whether you are calling these methods before or after the controls are part of a 'live' scene? If before, then this is expected behavior - css and layout don't run on controls that are not part of a scene. Can you provide a reproducible test case where this occurs?
24-05-2011