JavaFX BorderPane - make borders visible - javafx

Am developing an application in JavaFX. I use BorderPane to place various controls. In each region of BorderPane, I use either use HBox or VBox.
Now I wish to make the borders visible, so that each region can be separated by a line. Is there an option to make the borders of each region visible ?
If not possible, suggest me another way to separate each region of the BorderPane using lines or dotted lines ?

Related

Auto-size pane in JavaFX like scene builer have

I creating site builder and I want anchorpane at center of another pane. I have 3 anchor panes in SplitPane and in the central pane I need rezise of object like scene builder have when you resize scene builder. How to make that resizing? Is it very hard? I want to make this in fxml or directly in scene builder. I use IntelliJ.
This picture is show how it look when you open at first time and it need to be always 16:9 (central pane). Maybe you know what pane can be it
And this is how it look when you open in full-screen
In this example I tried to use borderPane and I put empty anchorpane's in all other corners because when you put something in center it fit all borderPane. How I remember when you do this thing in anchorPane with constraints (like 100px from upper corner) it looks the same.
How to do normal 16:9 all-time resizing?

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.

How To Center a GridPane on a Stage

Context: I'm currently writing an application using JavaFX. At the moment I've created a login form that is placed on a Scene within a GridPane, however currently the GridPane is always aligned in the top left corner of the application.
Problem: What I would like to do is center the login form (within a GridPane) into the middle of the window instead of the top left. How would I go about this? Would I need to place the GridPane within another layout and center it that way? Could I somehow designate the positioning of the GridPane using CSS?

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.

JavaFX - StackPane X, Y coordinates

I'm using StackPanel as container for my figures, panels, etc. What I discovered, that coordinates X,Y (0,0) are placed right in center of my panel.
Is it possible to move it to left top od Pane ?
Calculating all dimensions from center is much more difficult.
You can set the layout of Nodes added to the StackPane to a position within the Stackpane using the StackPane.setAlignment(node, position) method:
Label topLeftLabel = new Label("Top Left");
StackPane stack = new StackPane();
stack.getChildren().add(topLeftLabel);
StackPane.setAlignment(topLeftLabel, Pos.TOP_LEFT);
Even though this is possible, from your brief description of how you are trying to use the StackPane, it sounds like you would be better off using a regular Pane, or a Group or an AnchorPane for the kind of absolute positioning you appear to be wanting to achieve.
Possibly look into using a visual tool such as SceneBuilder as well. Even if you don't end up using the FXML it outputs, SceneBuilder should give you a much better idea of how JavaFX layout mechanisms work. SceneBuilder makes use of AnchorPane as its default layout pane used to provide absolute positioning for elements (which seems to be what you want to achieve).
The previous answer is of course the best in this situation, but it is also wise to know that you can move Nodes on the StackPane using Translation.
Ex.
Label topLeftLabel = new Label("Top Left");
StackPane stack = new StackPane();
stack.getChildren().add(topLeftLabel);
topLeftLabel.setTranslateX(stack.getWidth()/2);
topLeftLabel.setTranslateY(stack.getHeight()/2);
It would do the same thing (but may look a bit worse)

Resources