Last active
August 29, 2015 14:22
-
-
Save varren/ac08d1855322c685adcf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<?import javafx.scene.control.*?> | |
<?import javafx.scene.layout.VBox?> | |
<VBox xmlns="http://javafx.com/javafx/8.0.60-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Main$ListItemController"> | |
<children> | |
<Label text="This is ListItem.fxml from ListItemController"/> | |
<Label fx:id="lblName" text="Original Text from fxml"/> | |
</children> | |
</VBox> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample; | |
import javafx.application.Application; | |
import javafx.fxml.FXML; | |
import javafx.fxml.FXMLLoader; | |
import javafx.scene.Scene; | |
import javafx.scene.control.Label; | |
import javafx.scene.layout.AnchorPane; | |
import javafx.scene.layout.Pane; | |
import javafx.stage.Stage; | |
import java.io.IOException; | |
public class Main extends Application { | |
public static void main(String[] args) { | |
launch(args); | |
} | |
@Override | |
public void start(Stage primaryStage) throws Exception { | |
Pane root = FXMLLoader.load(getClass().getResource("MainView.fxml")); | |
primaryStage.setScene(new Scene(root)); | |
primaryStage.show(); | |
} | |
public static class MainViewController { | |
@FXML | |
private AnchorPane acContent; | |
private Label myLabel; | |
public void initialize() { | |
FXMLLoader fxmlLoader = new FXMLLoader(); | |
try { | |
fxmlLoader.load(getClass().getResource("ListItem.fxml").openStream()); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
myLabel = (Label) fxmlLoader.getNamespace().get("lblName"); | |
ListItemController controller = fxmlLoader.getController(); //controller defined in ListItem.fxml | |
Pane root = fxmlLoader.getRoot();// this is root of ListItem.fxml | |
acContent.getChildren().add(root); | |
} | |
@FXML | |
public void btnHome() { | |
myLabel.setText("btnHome pressed"); | |
} | |
@FXML | |
public void btnOne() { | |
myLabel.setText("btnOne pressed"); | |
} | |
@FXML | |
public void btnTwo() { | |
myLabel.setText("btnTwo pressed"); | |
} | |
} | |
public static class ListItemController { | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<?import javafx.scene.control.*?> | |
<?import javafx.scene.layout.VBox?> | |
<?import javafx.scene.layout.AnchorPane?> | |
<?import javafx.scene.layout.BorderPane?> | |
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Main$MainViewController"> | |
<children> | |
<BorderPane prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> | |
<top> | |
<AnchorPane prefHeight="78.0" prefWidth="600.0" BorderPane.alignment="CENTER"> | |
<children> | |
<Label fx:id="lblName" layoutX="506.0" layoutY="32.0" text="Rifat" /> | |
</children> | |
</AnchorPane> | |
</top> | |
<left> | |
<AnchorPane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER"> | |
<children> | |
<Button fx:id="btnHome" layoutX="49.0" layoutY="39.0" mnemonicParsing="false" onAction="#btnHome" text="Home" /> | |
<Button fx:id="btnOne" layoutX="36.0" layoutY="87.0" mnemonicParsing="false" onAction="#btnOne" text="Seen One" /> | |
<Button fx:id="btnTwo" layoutX="36.0" layoutY="136.0" mnemonicParsing="false" onAction="#btnTwo" text="Seen Two" /> | |
</children> | |
</AnchorPane> | |
</left> | |
<center> | |
<AnchorPane fx:id="acContent" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER" /> | |
</center> | |
</BorderPane> | |
</children> | |
</AnchorPane> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment