I am using JavaFX and I have a StackPane within a BorderPane within a TitledPane. Like so:
TitledPane->AnchorPane->BorderPane->StackPane
The StackPane is placed in the center region of the BorderPane. My problem is that when I run the app, the BorderPane is not filling the AnchorPane that is associated with the TitledPane. I have tried the AnchorPane.setBottom(), setTop(), setLeft(), and setRight() properties, setting them to 0.0 and it doesn't work. Thanks.
Related
I'm tasked with styling/skinning a JavaFX application. I'm trying to do as much in CSS stylesheets as possible rather than in the code. I've got a question about nested SplitPanes: when the application is rendered, is there anything that is created surrounding the inner SplitPane that gets in between the outer SplitPane and the inner SplitPane in the parent/child hierarchy of nodes.
Here's a little test application that mimics my full application:
BorderPane root = new BorderPane();
root.setId("root");
Label mws_header = new Label("This is the header");
root.setTop(mws_header);
Label sidebar = new Label("This is the sidebar");
root.setLeft(sidebar);
SplitPane outer = new SplitPane();
outer.setId("mws_pano_360_split");
outer.setOrientation(Orientation.VERTICAL);
root.setCenter(outer);
Label bigGraphic = new Label("This is the top");
outer.getItems().add(bigGraphic);
SplitPane inner = new SplitPane();
inner.setId("flat_data_split");
inner.setOrientation(Orientation.HORIZONTAL);
Label label1 = new Label("This is the left");
Label label2 = new Label("This is the right");
inner.getItems().addAll(label1, label2);
outer.getItems().add(inner);
In the CSS, what I'd like to do is get to the inner SplitPane using direct child syntax:
BorderPane > SplitPane > SplitPane {
/* all kinds of styling of background colors */
}
But instead, what I have to do is treat it as a descendant:
BorderPane > SplitPane SplitPane {
/* all kinds of styling of background colors */
}
So what might be getting in between the outer SplitPane and the inner SplitPane? I'd love to have a tool that lets you inspect the parent/child nodes in the hierarchy but so far haven't found one.
The center of my BorderPane has a stackpane called designView (an FXML defined stackpane). I'm trying to get a draggable pane in the designView. If I add that pane to the rootView (my BordePane) all is well. If however I try to add it to the designView like this:
// This works fine except the pnae is on the wrong place obviously
....
Pane p = displayField.createDraggablePane(800.0, 800.0, 400.0, 300.0);
rootView.getChildren().add(p);
// Now the pane is in the right place, but it's 'stuck'
....
rootView.setCenter(designView);
Pane p = displayField.createDraggablePane(800.0, 800.0, 400.0, 300.0);
designView.getChildren().add(p);
The pane appears correctly in the designView, BUT it is no longer draggable. The MouseEvents fire, but the position of the pane is not updated. I think the problem is with the fact that layoutX, getSceneX, layoutXProperty etc. have no reference to designView, but how do I get that? Can anyone help?
I found a solution. Instead of adding a StackPane to my BorderPane center, I have added a Pane and all is well :-) So my draggable Pane is added to a Pane instead of added to a StackPane.
Don't quite understand why this should change the behaviour of the draggable pane, but practice shows that it does.
I am trying to learn JavaFX and I've run into a problem with the Menus in my MenuBar. Here is a minimal example:
public void start(Stage mainStage) throws Exception {
BorderPane root = new BorderPane();
Scene scene = new Scene(root, 1200, 1000, Color.WHITE);
MenuBar menuBar = new MenuBar();
Menu menuFile = new Menu("_File");
menuBar.getMenus().add(menuFile);
MenuItem add = new MenuItem("_New");
menuFile.getItems().add(add);
root.getChildren().add(menuBar);
menuBar.prefWidthProperty().bind(mainStage.widthProperty());
mainStage.setScene(scene);
mainStage.show();
}
This application starts, but the Menu in the MenuBar is only shown as three dots (...). It does open however when I press ALT+F, so it is there.
From what I understand, a Menu item has no width or similar attribute, so that can't be set. I suspect it has something to do with my root node being a BorderPane, because in every other example I found that works, the root is either a VBox or something else. I seem to get the desired results when I place a Vbox as my root node, and then add the MenuBar and the BorderPane` to the root - but that seems like a strange and uneccesary workaround to me.
So what am I missing here? Is it true that a MenuBar will only ever look like it should in certain containers? What is the difference between a BorderPane and a VBox in this regard? If someone could explain or point me to a part of the documentation that I've missed, I would be very thankful.
You are using a BorderPane and using getChildren().add() to add MenuBar in it, which is incorrect. BorderPane unlike VBox, can't accept any number of children and is divided into 5 specific positions :
top
left
right
bottom
center
The children goes into any one of these positions. Please go through the documentation for BorderPane.
You need to add the Menubar to the top of the BorderPane using :
root.setTop(menuBar);
I'm trying to load a FXML into a FXML. The main FXML has a borderpane, and the second contains a VBox. I load both of these with the FXMLLoader. When I try to set the center of the boarderpane, the entire screen gets replaced with the second FXML. Here is the code
BorderPane riskAnalysis = new BorderPane((BorderPane) FXMLLoader.load(getClass().getResource("./proposaldevelopment/riskAnalysis.fxml")));
VBox center = new VBox((VBox) FXMLLoader.load(getClass().getResource("./proposaldevelopment/openRiskAssessmentVbox.fxml")));
riskAnalysis.setCenter(center);
root = riskAnalysis;
stage.getScene().setRoot(root);
Any ideas that could cause this? I also tried making a new label and putting that into the borderpane center with the same result.
Try as
BorderPane riskAnalysis = (BorderPane) FXMLLoader.load(getClass().getResource("./proposaldevelopment/riskAnalysis.fxml"));
VBox center = (VBox) FXMLLoader.load(getClass().getResource("./proposaldevelopment/openRiskAssessmentVbox.fxml"));
riskAnalysis.setCenter(center);
stage.getScene().setRoot(riskAnalysis);
I'm creating an JavaFX Game like "Wheel of Fortune". I use a BorderPane as root of the scene. and the right of this pane is set to contain a GridPane which in turn contain an ImageView and some other elements. I want to set the position of the ImageView (the wheel) so that only half of it is displayed. I've setLayoutX and setLayoutY to set the position of ImageView with x = X of GridPane + ImageView. X /2 (something like that), but the ImageView is not placed as expected. How should I do that???
ImageView http://imageshack.com/a/img812/6161/ynb8.png