Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change sub fxml gui parts at runtime with Button Click
    primarykey
    data
    text
    <p>I'm tryin to build a skeleton for a big complex gui, so the idea is to make everything with mvc like style in javafx 2.1, so every component has a fxml file and if needed css,controller and model. I'm tryin to figure out how to change sub scenes(sub fxml at runtime). Anybody know how to do it? I'm kinda stuck on this. May bee to add MainViewController? scenario: user clicks on button in taskbar and the included content1.fxml will be replaced with content2.fxml</p> <p>here the basic code</p> <p><strong>MainApp.java</strong></p> <pre><code>Loads the MainView.fxml </code></pre> <p><strong>MainView.fxml</strong> </p> <pre><code>&lt;?import javafx.scene.control.*?&gt; &lt;?import javafx.scene.layout.*?&gt; &lt;BorderPane xmlns:fx="http://javafx.com/fxml"&gt; &lt;center&gt; &lt;fx:include source="Content1.fxml"/&gt; &lt;/center&gt; &lt;bottom&gt; &lt;fx:include source="TaskBar.fxml"/&gt; &lt;/bottom&gt; &lt;/BorderPane&gt; </code></pre> <p><strong>Content1.fxml</strong> </p> <pre><code>&lt;?import javafx.scene.control.*?&gt; &lt;?import javafx.scene.layout.*?&gt; &lt;StackPane xmlns:fx="http://javafx.com/fxml" fx:id="content1"&gt; &lt;Label text="Hallo Java FX 2.1.1 Content1.fxml"/&gt; &lt;/StackPane&gt; </code></pre> <p><strong>Content2.fxml</strong> </p> <pre><code>&lt;?import javafx.scene.control.*?&gt; &lt;?import javafx.scene.layout.*?&gt; &lt;StackPane xmlns:fx="http://javafx.com/fxml" fx:id="content2"&gt; &lt;Label text="Hallo Java FX 2.1.1 Content2.fxml"/&gt; &lt;/StackPane&gt; </code></pre> <p><strong>TaskBar.fxml</strong> </p> <pre><code>&lt;?import javafx.scene.control.*?&gt; &lt;?import javafx.scene.layout.*?&gt; &lt;HBox xmlns:fx="http://javafx.com/fxml" spacing="10" alignment="center" fx:id="taskBar" fx:controller="TaskBarController"&gt; &lt;children&gt; &lt;Button fx:id="taskBarButton1" onAction="#handleTaskBarButton1Action"/&gt; &lt;Button fx:id="taskBarButton2" onAction="#handleTaskBarButton2Action"/&gt; &lt;/children&gt; &lt;/HBox&gt; </code></pre> <p><strong>TaskBarController.java</strong></p> <pre><code>import java.net.URL; import java.util.ResourceBundle; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.Button; public class TaskBarController implements Initializable { // Binding with the FXML @FXML private Button taskBarButton1; @FXML private Button taskBarButton2; @FXML private void handleTaskBarButton1Action(ActionEvent event) { System.out.println("click! taskBarButton1"); } @FXML private void handleTaskBarButton2Action(ActionEvent event) { System.out.println("click! taskBarButton2"); } @Override public void initialize(URL location, ResourceBundle resources) { // TODO Auto-generated method stub } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload