Javafx - getting a node of scrollPane to front - javafx

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?

Related

JavaFX Scenebuilder moving elements inside StackPane

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.

Adding Shapes to GridPane results in wrong Position

I got the task to draw some points on a map. Wrote some code but currently every point I create via shapes will be added to the wrong position inside of my gridpane. Oh and I'm using JavaFX.
I added an imageView to the index 0,0 of my GridPane and every point is created through x and y position of the MouseEvent on the imageView.
After that I added the created point as a child of the GridPane and it's displayed at the center of the y-axis of the first grid.
Tried different things like anchorPanes and canvas but can't seem to get it working.
Code of my View:
http://pastebin.com/dCb7EN4d
Code of my Main:
http://pastebin.com/vp5tzxkG
I hope that's enough ^^'
pls help!
Greetings,
Ben
GridPane is a managed layout: it will position nodes that are added to it via the properties you set (using defaults if you don't set them). So when you add your circles to the grid pane, since you don't set any properties, it will place it in cell (0,0) and align it within that cell using default settings; i.e. it ignores the centerX and centerY properties.
What you should really do here is use a layout that does not manage the positioning of the nodes for you, such as a Pane (or possibly a Group). You can put the ImageView and the Circles in the pane, and then place the pane in the rest of your layout (in the scroll pane, I think).
The other option you have is to call setManaged(false) on the nodes you add to the GridPane in order to instruct the GridPane not to position them, though this feels like more of a workaround.

How do you get a ScrollPane that is placed in the center of a BorderPane to work?

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!

Adding Nodes to an AnchorPane (inside Scroll Pane), Javafx

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.

Flex Vertical Scroll bar problem

I have a problem in flex scroll bars. I have a mxml component based on canvas. Inside that I have used a VBox for my form. Above that Vbox I have another canvas just for title.
My form gets longer than normal screen size when the grid inside that is filled with more data. In that case I want a vertical scroll bar just for Vbox in which my form is located. But the whole canvas is getting scrollbar including title canvas. how to solve this problem.
I set vertical scrollbar policy of main canvas to off and inside Vbox's VerticalScrollbarPolicy to on. but that's not working. It is not overriding the property of parent container.
Thanks.
Keep your Form inside a Canvas inside the parent canvas instead of VBox. VBox and HBox are set to grow automatically in the parent container, so if your form grows, your corresponding VBox will grow as well.
You want to overload the "updateDisplayList" function for your parent canvas, and force the height of your form Vbox to be canvasHeight-titleHeight (including padding, space, etc...) so that the VBox never grows larger than the screen. This will solve your problem. Just make sure you check for the existence of the VBox as sometimes the updateDisplayList will be called before it has been instantiated.
Had the same problem myself and decided to take the easy route.
Have the following
App->vbox->[vbox + hbox]
components are dynamically being added to last vbox. Wanted hbox to stay on screen and have scrollbars only in vbox above it(2nd vbox).
Was experiencing the same problem. All containers had scroll policy=off except for last vbox, but when dynamically adding components, when the components filled the vbox > 100%, the outer vbox would start to scroll.
Resolution was simple once I went back to the documentation.
Set scroll policy - horizontal and vert on app and first vbox to off, and also added autoLayout=false. This causes the engine to not resize the components after initialization, ie, they are static sized.
Once I added this property, no more scrollbars except for the inner vbox.
Tada!

Resources