Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Resizing Containers like 'HBox', 'VBox'

952782Aug 17 2012 — edited Aug 17 2012
I have a FXML : ''Landing Screen" which contains one Anchor Pane and two HBoxes independently (one below another).

Now I want to set the Width of these containers to the screen width. So that the application is portable. The total Heights of the annchor pane and Hboxes together should form the Screen Height. I have also declared FX:IDs to these containers.
I am unable to set the width of these containers to screen width.

I am using the following code under the 'Initialising method ' of the Controller class of the FXML:
Please tell me where I am going wrong:


@FXML HBox rect;
@FXML HBox rect2;
@FXML AnchorPane hb;

public void initialize(URL url, ResourceBundle rb) {
try {

rect = (HBox) FXMLLoader.load(getClass().getResource("LandingScreen.fxml"));
rect2 = (HBox) FXMLLoader.load(getClass().getResource("LandingScreen.fxml"));
hb = (AnchorPane) FXMLLoader.load(getClass().getResource("LandingScreen.fxml"));

Screen screen = Screen.getPrimary();
Rectangle2D bounds = screen.getVisualBounds();

hb.setPrefWidth(bounds.getWidth());
rect.setPrefWidth(bounds.getWidth());
rect2.setPrefWidth(bounds.getWidth());


} catch (Exception ex) {
Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex);
}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 14 2012
Added on Aug 17 2012
1 comment
318 views