I can add elements to an AnchorPane that is inside a ScrollPane. However they come in temporarily hidden. The second I click on the AnchorPane, the elements show up. I tried to do thing like element.toFront(), but with no success. Any ideas how to get elements to show up right away?
Sample code would like:
AnchorPane host= new AnchorPae();
ScrollPane sp = new ScrollPane(host);
AnchorPane node = new AnchorPane();
host.getChildren().add(node);
I tried things like requestFocus() on each of these nodes, but without success. I also tried to mimic a mouse click event but it did not work. everything shows once I physically click on the AnchorPane.
Related
I'm creating an app in which I use nested FXML nodes. They are connected to parent nodes in the parent controllers using constructs like
#FXML
private AnchorPane nestedNodeConnector;
, to which I attach the child like this:
AnchorPane child = createNestedAnchorPaneWithTableViewInside();
nestedNodeConnector.getChildren().setAll((AnchorPane)child);
The code is a bit simplified, but I hopefully explained myself enough. Now my problem is that I am trying to load (as the child node) an as-large-as-possible AnchorPane with an anchored TableView inside. However I can't get this to work as the TableView dimension never sticks to the parent node (in order to grow with the window size).
I was able to get it working without nesting the child, but I really have to load the TableView in a separate FXML file. Any suggestions? I think that my approach creates an AnchorPane "child" within an AnchorPane "nestedNodeConnector", which messes up the anchor properties.
All I had to do was anchor the child AnchorPane (to the parent AnchorPane):
AnchorPane child = createNestedAnchorPaneWithTableViewInside();
AnchorPane.setTopAnchor(child, 10.0);
AnchorPane.setBottomAnchor(child, 10.0);
AnchorPane.setLeftAnchor(child, 10.0);
AnchorPane.setRightAnchor(child, 10.0);
nestedNodeConnector.getChildren().setAll((AnchorPane)child);
I am trying to move things such as buttons and labels that I put inside a StackPane since I want these things to stay centered when minimizing or maximizing windows. When I put everything I want into the StackPane, they all get centered and layered up on each other. How am I able to move these elements around in the StackPane if it's possible or how will I be able to keep everything centered when resizing the window?
You edit their TranslateX and TranslateY properties. for instance
Label label1 = new Label();
label1.setText("0");
label1.TranslateX(-10.0); //<< moves the label 10 pixels to the left.
if you are using Scene Builder you can edit these properties on the right under the "layout" tab.
I have two distinct main pane. These panes have a scrollPane and scrollPane has a another pane. I'm adding a node like a rectangle to ScrollPane's pane.
I want to get the rectangle in front of all.
I'm using toFront() method for rectangle. But rectangle does not get to front of scrollPane.
How can i get the rectangle in front of all, any ideas?
I have a program where i have a rootLayout made from a BorderPane. When i press a button in this rootLayout i place a new fxml view into the center of the the borderPane using .setCenter(). The view i am placing into the borderPane consists of an AnchorPane that has a scrollPane as it's child element and when i run this view by itself the scrolling works. However after placing the view into the borderPane it stops working. The area in the scrollPane doesnt move at all when i scroll down or up. I am guessing this has to do with the size that is given in the borderPane but the whole point of having the scrollPane is so that i can show all of the information in 1/3 of the space.
Any tips or Ideas on how to make this work in either javafx, fxml or scenebuilder?
Can't make comments yet ... correct me if I'm wrong but don't you have to use the AnchorPane as the child of the ScrollPane? I always have my TextAres as child of the ScrollPanes!
I have an Hbox which contains Vboxes and each Vbox itself contains other Elements which can be added or removed and some control Buttons. Now I want to add or remove those flexible Elements in my Model and I need to know in which Vbox this is happening.
My attempt was to get the Children of the Hbox and check where the Vbox, where something happend/changed, is located in this List. And work with this Index afterwards.
public int getId (Action event){
Button button= event.getSource();
Vbox vbox= button.getParent();
Hbox hbox= vbox.getParent();
hbox.getChildrenUnmodifiable();
....//TODO
}
The Problem is that if I Print hbox.getChildrenUnmodifiable(); it shows me that:
[VBox#1402dd44, Separator#4eaff333[styleClass=separator], Grid hgap=0.0, vgap=0.0, alignment=TOP_LEFT]
and after I add an other Vbox it just adds the
Grid hgap=0.0, vgap=0.0, alignment=TOP_LEFT]
part again and again and doesen't show me any more information of the Vboxes which have been added.
I load the Vboxes from an other .fxml file with hbox.getChildren().add(FXMLLoader.load(getClass().getResource("/VBoxElement.fxml")));
Now I wonder if that looks like an proper way to get the Indexnumber of my Vbox where I am working on? And if anyone has any advice how to get a working Index of my Hbox?
This is my first JavaFX project and if I miss understood something feel free to correct me.
As James_D sayd:
ObservableList is just a subinterface of java.util.List, so you can
just call all the usual methods: indexOf(...), add(..), remove(...),
etc – James_D May 14 at 15:41
Thx, worked fine. As I expected it as first but I messed up my fxml structure and my added fxml did not contain a VBox as root element it contained a Grid. The toString() from the Grid produces the Grid hgap=0.0, vgap=0.0, alignment=TOP_LEFT in the output