Which Scene Builder container can I use to make my desktop application responsive?

Asked

Viewed 794 times

2

I’m starting to study Javafx and I have a question.

Which Scene Builder container can I use to make my desktop application be responsive?

The only container that came close to what I wanted was Borderpane, however, it is restricted and I would like to move the screen freely, as in Anchorpane.

1 Figure: Borderpane (Responsive but I can’t insert a pane between the bottom and top) My idea would be to insert one between red and purple as shown in the other figure.

inserir a descrição da imagem aqui

2 Figure: Anchorpane (Non-responsive, but I can insert a pane between two Hbox.

inserir a descrição da imagem aqui

1 answer

2

1° Step: Create the design in Scene Builder

To make the application responsive, I created an Anchorpane, inside this Anchorpane I inserted a Pane and put as id="PaneTopoTela". This Pane (child element) is that I will be able to make responsive from the FXML file.

Step: Insert code into FXML file:

<AnchorPane id="AnchorPane" prefHeight="613.0" prefWidth="748.0" stylesheets="@estilo.css" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxapplicationteste.FXMLDocumentController">
   <children>
      <Pane id="PaneTopoTela" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"    layoutY="-9.0" prefHeight="92.0" prefWidth="748.0" stylesheets="@estilo.css" />
   </children>
</AnchorPane>

Explanation:

Notice that after the id="Panetoptela" I put Anchorpane.leftAnchor="0.0" Anchorpane.rightAnchor="0.0"?

This Anchorpane.right and left will have the same functionality in Javafx as the anchor has in netbeans. It will anchor the elements in wherever you want.

About the anchor in the netbeans layout: Do you know when you right-click a child element in netbeans and it appears to you "Anchor -> Left/Right/Top/Bottom"? So, this is it!

So in Javafx, you have 4 options, they are:

AnchorPane.topAnchor

AnchorPane.bottomAnchor

AnchorPane.leftAnchor

AnchorPane.rightAnchor

If you match the 0.0, as I did... it will align the child element within the Anchorpane.

For more information.

Anchorpane Javafx

Browser other questions tagged

You are not signed in. Login or sign up in order to post.