Resizing Containers like 'HBox', 'VBox'
952782Aug 17 2012 — edited Aug 17 2012I 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);
}
}