JAVAFX - scene questions - java

The end goal is to reproduce this image as well as possible. I am trying to start from a bottom up approach as I have many questions.
My first question is how can I get labels alongside the textboxes (it has been suggested to use VBoxes on an hbox to organize everything, but then the textbox automatically goes below the label)
My second question is, as you can see there are borders around the four related boxes to separate the information. I am uncertain how this is done.
Finally what is the configuration of Panes that I should put these four groups on. As I mentioned below someone suggested VBoxes placed on a HBox but I can't get the text to be at the right spot with this approach.
One last thing... I was trying to use ComboBoxes but I can only make one selection, unlike in the image showing the appetizers and main courses selected.
I looked at ListView but its not a drop down box and I read in the API that this in general is not supported since they thought having multiple selections was not necessary. So how might one approach this?
Thanks so much

I'de recommaned an HBox as the primary container, and a VBox on the left side containing the three panes.
In case the window is resizable, and you want to keep either of the panes flushed to the side, try AnchorPane, instead of the HBox.

this required nested panes. for those with similar assignments, creating grid boxes and placing them inside titled boxes allows for the "group box" effect shown above that was a part of swing. An additional HBox was added where the image and title were, making three parts: the top HBox, the right title box, and the left VBox.the left VBox and the top HBox were added into a VBox (or grid), linking the entire left side, which was then placed in an hbox along with the right side title pane.

Related

Recalculate layout of buttons on a dynamic language change using ComboBox in FXML

I have a BorderPane where I have a TreeView (meny) on the left, mainPane (AnchorPane) on the right and toolbar on the top. I'm able to select a language from the ComboBox which is located on the toolbar and it changes the language to the selected one somewhat dynamically (Just needs an extra click on a random treeView item for some reason. This is also a problem I have but not my main issue concerning this question). However, when I change the language from the ComboBox, the layout stays the same on the mainPane and buttons, labels etc. overlap each other if a long language is selected (i.e Spanish). If I start the program with Spanish locale, then no problem, the layout is calculated accordingly.
I've read about Binding and checked other SO regarding this issue for ex. changing language. However, considering the amount of buttons, labels, etc. on each of my TreeView pages I have, it feels pretty overwhelming to me to bind each and every object in my case. Is there any other approach to this?

Javafx Scrollpane Constraints when inside another Pane

I'm a bit new to Javafx and have only ever done simple projects with it. I'm currently working on a more complex project and I'm stumbled into an issue with ScrollPanes. I'm struggling to find out how to make the ScrollPane resize in height whenever I resize the application. Here is my structure:
The Pane indicated by the orange arrow works fine, I can add constraints as shown here:
However I do not have the constraint options on the ScrollPane or the AnchorPane inside of the ScrollPane, which results in this upon resizing of the application:
If I remove the parent Pane and just put the ScrollPane in it's place, I can add the constraints, however if I did that I would not be able to properly design the application as I have it now. In short, I'm just curious if there's an alternate method I can use or if I'm just using bad practice, in which case any advice is appreciated.
Pane simply resizes the children to the preferred size and keeps the position. This means no resizing is applied. Also it does not offer any further layout constraints.
You could simply replace the parent pane with a AnchorPane and the anchors become available again.
However a AnchorPane(base) containing that many Panes, probably all with different AnchorPane constraints, indicates that the scene should probably be restructured a bit. E.g. a GridPane, VBox, HBox or a combination of those could help you achieve the desired result in a simpler way.
See Using Built-in Layout Panes for a description of the available layouts and example uses.

Add components dynamically in JavaFX

Updated: question is incorrect because of low knowledge of the subject. Sorry.
I'm trying to create a small application that shows a graph that contains nodes and connections between them. Both nodes and connections are complex, I mean they can have another components in it, like labels.
I have a big Pane which plays a canvas role. I'm going to add and remove elements from it. The problem is that I want to add or remove graph elements dynamically, using buttons or context menu. Sort of Paint for Graphs :) And I have no idea how to implement it.
Especially I desperately need help in dynamical adding/removing mechanism. I would be very grateful for your help!
Just get the child list of the pane you want to add stuff to, and add the stuff when the appropriate action occurs.
FlowPane pane = new FlowPane();
Button addNode = new Button("Add");
addNode.setOnAction(e -> pane.getChildren().add(new Circle(10));
Notes:
If you want to use a Pane rather than a FlowPane, then Pane has no internal layout, so you need to also set the layoutX and layoutY properties appropriately when you add to the Pane.
If you want to change the rendering order of nodes in the Pane (e.g. which nodes are rendered on the bottom and which on top), then you do that by adding new nodes at an appropriate position in the child list; for example, pane.getChildren().add(0, new Circle(10)), will add a circle that is rendered underneath all other children of the pane rather than on top.

Realigning Components in AnchorPane in JavaFX 8

I am trying to develop an app using JavaFX 8 and I'm stuck with a resizing problem. The Selected File and Password fields in the below figure doesn't realign as I wish it to be in the AnchorPane..i.e. to be in the center with exact distances from the top navigation bar and the footer. I have tried AnchorPane Constraints in Scene Builder. I was unable to get a perfect match.
Hoping to get an alternate approach or a small overview of AnchorPane constraints.
Note: I'm new to JavaFX graphics library.
Below enclosed are the images and the FXML file that I'm working on.
What I want is this kind of alignment in full screen mode too.
This is the actuality when I switch to full screen.
For a quick fix, try wrapping your AnchorPane in a simple layout, such as an HBox, and set the alignment of the HBox to Pos.CENTER.
However, AnchorPane is probably not the best layout pane to use here. You should read through the layout tutorial and figure out a different strategy: probably you want a BorderPane as the overall structure with HBoxs and/or GridPanes inside.

Creating a fully dynamic GUI

I'm currently trying to learn JavaFX and FXML (and Java) and decided to write a textbased RPG. The basis for this was already written quite some time ago, but now I wanted to do the whole thing better. Including the visuals, that is, the GUI.
First of all: I'd like to do this using FXML. That does not mean however that I'm not interested in seeing a way using basic Java.
What I want to build is a fully dynamic GUI. No Matter how it is resized, the components (and ideally the text as well) would be at the same location, relative to the other components / window border.
The window would have some kind of top line with several buttons for saving, the menu, overview and whatnot. Below that, on the left side, would be Character information: Health, Experience, Money etc. On the right side would be the text output (using a Scrollpane) plus a text field, for user input. Below the text input/output I'd place the buttons used for actions and decisions. Bottom left corner does not contain anything, though it should be a separate area.
At first I tried using Splitpanes, not knowing that they can be resized anytime and have visible Dividers. Now I'm not sure what to do.
A Gridpane would give some of the functionality I need (separate the areas), but also does not give the flexibility I want (unless I just don't know how to do it). I couldn't get it to work. So I tried using simple Panels. But with them I couldn't figure out how to keep the panels keep their relative position and size, and how to make the Buttons stick to the borders.
So what would be the best way to go about this? GridPane? Panel? Something else I'm missing? Since I don't really know how to achieve this, any help in any direction would be highly appreciated.
Have you read the layout tutorial?
From your description, it sounds like a BorderPane might be best for the overall layout (i.e. the root of your scene graph): I'm not quite sure if you could easily make this give you the empty bottom left corner you want. Alternatively you could use a GridPane as you suggested, with appropriate ColumnConstraints and RowConstraints applied to size the cells in the pane.

Categories