I am using JavaFX in my project (also Spring, Hibernate e.t.c.).
I am trying to create Pagination for TableView. I found many reasonable solutions, but all off them are controller-based solutions. The best of them in this solution.
But in my situation - I am using multiple fxml files which were created in SceneBuilder with all huge design options and which contains the TabPane and for one Tab I have one FXML-file and one controller for it.
I have one basic file which imports others, and in my Main class I am loading it:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
minWidth="-Infinity" prefHeight="592.0" prefWidth="920.0" xmlns="http://javafx.com/javafx/8"
fx:controller="com.varinsia.statistical.controller.GenericController">
<children>
<TabPane layoutX="3.0" layoutY="50.0" prefHeight="542.0" prefWidth="914.0" tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab text="Statistics">
<content>
<fx:include fx:id="statistics" source="/fxml/child/statistics.fxml"/>
</content>
</Tab>
<Tab text="Shedule">
<content>
<fx:include fx:id="shedule" source="/fxml/child/shedule.fxml"/>
</content>
</Tab>
<Tab text="Ponab devices">
<content>
<fx:include fx:id="ponabDevices" source="/fxml/child/ponabDevices.fxml"/>
</content>
</Tab>
<Tab text="Als devices">
<content>
<fx:include fx:id="alsDevices" source="/fxml/child/alsDevices.fxml"/>
</content>
</Tab>
<Tab text="Search">
<content>
<fx:include fx:id="search" source="/fxml/child/search.fxml"/>
</content>
</Tab>
<Tab text="Settings">
<content>
<fx:include fx:id="settings" source="/fxml/child/settings.fxml"/>
</content>
</Tab>
</tabs>
</TabPane>
<Label layoutX="127.0" layoutY="9.0" text="..."
underline="true">
<font>
<Font size="18.0"/>
</font>
</Label>
</children>
</AnchorPane>
In my controller class for my statistics.fxml I am creating the TableView and columns:
#FXML
public TableView<StatisticsRemarkTableDto> statisticsTableView;
#FXML
public TableColumn<StatisticsRemarkTableDto, String> objectColumn;
#FXML
public TableColumn<StatisticsRemarkTableDto, String> noteColumn;
#FXML
public TableColumn<StatisticsRemarkTableDto, String> stageColumn;
#FXML
public TableColumn<StatisticsRemarkTableDto, String> dateColumn;
#FXML
public TableColumn<StatisticsRemarkTableDto, String> vagonColumn;
#FXML
public TableColumn<StatisticsRemarkTableDto, String> repeatColumn;
#FXML
public TableColumn<StatisticsRemarkTableDto, Integer> remarkIdColumn;
And all other things like in this solution.
Information from the entity is added to my table and everything works fine. But!
Problem starts when i am trying to add Pagination, because I can't understand how I should do this. My Main method looks like this:
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/spring/application-context.xml");
context.getBeanFactory().registerResolvableDependency(Stage.class, primaryStage);
primaryStage.setTitle(Constants.MAIN_TITLE);
primaryStage.setScene(new Scene((Parent) context.getBean(SpringFXMLLoader.class).load(Constants.FXML_PATH), 914, 542));
primaryStage.show();
}
}
In all TableView-pagination examples Pagination were added in the Main class, like in the code from other valid and checked example:
private Node createPage(int pageIndex) {
int fromIndex = pageIndex * rowsPerPage;
int toIndex = Math.min(fromIndex + rowsPerPage, data.size());
table.setItems(FXCollections.observableArrayList(data.subList(fromIndex, toIndex)));
return new BorderPane(table);
}
#Override
public void start(final Stage stage) throws Exception {
Pagination pagination = new Pagination((data.size() / rowsPerPage + 1), 0);
pagination.setPageFactory(this::createPage);
Scene scene = new Scene(new BorderPane(pagination), 1024, 768);
stage.setScene(scene);
stage.setTitle("Table pager");
stage.show();
}
public static void main(String[] args) throws Exception {
launch(args);
}
Is there some way to pass this issue and to add Pagination to my TableView?
I'll be very glad to any answers on this subject, the problem does not suffer the first day.
RESOLVED!:
Thanks to James_D and his solution.
I have tried this variant and it worked fine. My TableView is now with pagination.
I have added to my statistical.fxml:
<Pagination fx:id="statisticsTableViewPagination" layoutX="2.0" layoutY="188.0" prefHeight="275.0"
prefWidth="912.0">
<fx:define>
<TableView fx:id="statisticsTableView" layoutX="2.0" layoutY="188.0" prefHeight="301.0" prefWidth="912.0">
<placeholder>
<Label text="No search results found."/>
</placeholder>
<columns>
<TableColumn fx:id="objectColumn" prefWidth="131.0" text="Object"/>
<TableColumn fx:id="noteColumn" minWidth="0.0" prefWidth="167.0" text="Remark"/>
<TableColumn fx:id="stageColumn" prefWidth="282.0" text="Stage"/>
<TableColumn fx:id="dateColumn" prefWidth="72.0" text="Date"/>
<TableColumn fx:id="vagonColumn" prefWidth="133.0" text="Laboratory"/>
<TableColumn fx:id="repeatColumn" prefWidth="125.0" text="Repeats"/>
<TableColumn fx:id="remarkIdColumn" minWidth="9.0" prefWidth="15.0" text="Id" visible="false"/>
</columns>
</TableView>
</fx:define>
</Pagination>
And in my controller I have added the same parts as in this example. And everything is working fine. Thanks a lot!
Just define the Pagination in statistics.fxml:
<Pagination fx:id="pagination"/>
and then configure it in the controller for that class:
#FXML
private TableView<StatisticsRemarkTableDto> statisticsTableView;
#FXML
private Pagination pagination ;
public void initialize() {
pagination.setPageFactory(this::createPage);
// etc...
}
Since the table itself is placed in the scene graph by the page factory, it isn't part of the scene graph until after the initialize() method is invoked, i.e. after the FXML has been parsed. So you can either just define the table in the controller directly (and not include it in the FXML file at all):
private TableView<StatisticsRemarkTableDto> statisticsTableView;
#FXML
private Pagination pagination ;
public void initialize() {
statisticsTableView = new TableView<>();
// create columns, etc...
pagination.setPageFactory(this::createPage);
// etc...
}
or you can define it in FXML in a <fx:define> block:
<Pagination fx:id="pagination">
<fx:define>
<TableView fx:id="statisticsTableView">
<columns>
<TableColumn fx:id="objectColumn" ... />
<!-- etc -->
</columns>
</TableView>
</fx:define>
</Pagination>
and then inject it into the controller with #FXML in the usual way.
Related
I know there are many questions about this, but the answers didn't solve my problem.
I have a TableView with 4 columns. The data is read out of a txt file.
In the initialize method from the Controller the CellValueFactory is set, and another method is called, which reads the Data from the file and creates an observableList of the model.
Then the list is added to the items of the table, but no data is displayed, and no placeholder is there. Does anyone know what is wrong?
Controller class
#FXML
private TableView<Data> dataTable;
#FXML
private TableColumn<Data, String> dataType;
#FXML
private TableColumn<Data, String> dataName;
#FXML
private TableColumn<Data, String> dataDate;
#FXML
private TableColumn<Data, String> dataInformation;
#FXML
public void initialize() {
dataType.setCellValueFactory(value -> new SimpleStringProperty(value.getValue().getDataType()));
dataName.setCellValueFactory(value -> new SimpleStringProperty(value.getValue().getDataName()));
dataDate.setCellValueFactory(value -> new SimpleStringProperty(value.getValue().getDataDate()));
dataInformation.setCellValueFactory(value -> new SimpleStringProperty(value.getValue().getDataInformation()));
initData();
}
private void initData() {
ArrayList<Data> data = new ArrayList<>();
try {
Path filePath = Paths.get("src/main/resources/kl/fla/decrypted.txt");
if (filePath.toFile().exists()) {
data = (ArrayList<Data>) Files.readAllLines(filePath, StandardCharsets.UTF_8).stream()
.map(Data::new).collect(Collectors.toList());
}
} catch (Exception e) {
e.printStackTrace();
}
dataTable.setItems(FXCollections.observableArrayList(data));
dataTable.refresh();
}
FXML File
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="720.0"
prefWidth="1080.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="kl.fla.controller.TableController"
>
<children>
<Label alignment="CENTER" layoutX="393.0" layoutY="34.0" prefHeight="70.0" prefWidth="295.0" text="Hidden Gate">
<font>
<Font size="48.0" />
</font>
</Label>
<TableView fx:id="dataTable" fixedCellSize="1.0" layoutX="36.0" layoutY="141.0" prefHeight="439.0" prefWidth="840.0">
<columns>
<TableColumn fx:id="dataType" prefWidth="135.0" resizable="false" text="Datatype" />
<TableColumn fx:id="dataName" minWidth="4.0" prefWidth="135.0" resizable="false" text="Name" />
<TableColumn fx:id="dataDate" prefWidth="135.0" resizable="false" text="Date" />
<TableColumn fx:id="dataInformation" minWidth="0.0" prefWidth="285.0" resizable="false" text="Information" />
</columns>
</TableView>
</children>
</Pane>
Screenshot of the empty TableView
The data are (probably) there; you just can’t see them because you have constrained every row to be just one pixel high:
fixedCellSize="1.0"
Remove that attribute and just use the default setting, and it should work (assuming there are no other errors in code you haven’t posted).
Working on a Simple Invoice Software for self. Got stuck at the first point.
Unable to display rows in Tableview. I have tried every possible solution, gone through many tutorial videos, guides etc. Still not able to find the problem
Please help
NewInvoice.fxml
<TabPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="720.0" prefWidth="1280.0" tabClosingPolicy="UNAVAILABLE" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1">
<tabs>
<Tab text="CASH">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<Button fx:id="additembutton" layoutX="412.0" layoutY="41.0" mnemonicParsing="false" text="ADD" />
<TableView fx:id="invoiceitemtableview" layoutX="190.0" layoutY="180.0" prefHeight="200.0" prefWidth="481.0">
<columns>
<TableColumn fx:id="amountcol" prefWidth="75.0" text="Amount" />
<TableColumn fx:id="gstcol" prefWidth="75.0" text="GST" />
<TableColumn fx:id="subtotalcol" prefWidth="75.0" text="Subtotal" />
<TableColumn fx:id="cgstcol" prefWidth="75.0" text="CGST" />
<TableColumn fx:id="sgstcol" prefWidth="75.0" text="SGST" />
</columns>
</TableView>
<TextField fx:id="itemcodetextbox" layoutX="216.0" layoutY="41.0" />
</children></AnchorPane>
</content>
</Tab>
<Tab text="BOBCARD">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</Tab>
NewInvoiceController.java
public class NewInvoiceController implements Initializable {
#FXML
TableView<InvoiceItemBean> invoiceitemtableview;
#FXML
TableColumn<InvoiceItemBean,String> amountcol, gstcol, subtotalcol, cgstcol, sgstcol;
final ObservableList<InvoiceItemBean> data = FXCollections.observableArrayList(
new InvoiceItemBean("1049","5","999.10","22.5","22.5"),
new InvoiceItemBean("1800","12","1180.10","305.00","305.00")
);
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
amountcol.setCellValueFactory(new PropertyValueFactory<>("amount"));
gstcol.setCellValueFactory(new PropertyValueFactory<>("gst"));
subtotalcol.setCellValueFactory(new PropertyValueFactory<>("subtotal"));
cgstcol.setCellValueFactory(new PropertyValueFactory<>("cgst"));
sgstcol.setCellValueFactory(new PropertyValueFactory<>("sgst"));
invoiceitemtableview.setItems(data);}
}
InvoiceItemBean.java
public class InvoiceItemBean {
private final SimpleStringProperty amount;
private final SimpleStringProperty gst;
private final SimpleStringProperty subtotal;
private final SimpleStringProperty cgst;
private final SimpleStringProperty sgst;
public InvoiceItemBean( String amount, String gst, String subtotal, String cgst, String sgst) {
this.amount = new SimpleStringProperty(amount);
this.gst = new SimpleStringProperty(gst);
this.subtotal = new SimpleStringProperty(subtotal);
this.cgst = new SimpleStringProperty(cgst);
this.sgst = new SimpleStringProperty(sgst);
}
public String getAmount() {
return amount.get();
}
public String getGst() {
return gst.get();
}
public String getSubtotal() {
return subtotal.get();
}
public String getCgst() {
return cgst.get();
}
public String getSgst() {
return sgst.get();
}
public void setAmount(String amount_value) {
amount.set(amount_value);
}
public void setGst(String gst_value) {
gst.set(gst_value);
}
public void setSubtotal(String subtotal_value) {
subtotal.set(subtotal_value);
}
public void setCgst(String cgst_value) {
cgst.set(cgst_value);
}
public void setSgst(String sgst_value) {
sgst.set(sgst_value);
}
}
Main.java
public class ClimaxInvoice extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("NewInvoice.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Unable to get anything
Output Table view showing no content
PLEASE HELP!!!
Your problem is really simple, you haven't specified the controller in the fxml.
Just add fx:controller="packageName.NewInvoiceController"
at the end of the first line in your fxml file.
So the whole line should be:
<TabPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="720.0" prefWidth="1280.0" tabClosingPolicy="UNAVAILABLE" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="packageName.NewInvoiceController">
Of course, replace packageName with the name of your package.
I am building an simple javafx application using afterburner. I have main window which have a border pane and it's upper part contains menus and in center it have a vertical split pane which have two anchor panes with fx:id=inputPane and fx:id=tablePane. Now in inputPane i am loading different scenes and submitting data from it into tablePane.
Now i have a scene opened in inputPane which have a button and i want to submit the data from this scene into table as well as i want to open an another scene into inputPane and again want to submit it's data into table.
adara.fxml
<BorderPane fx:id="mainPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="180.0" minWidth="-Infinity" prefHeight="507.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.qaf.presentation.adara.AdaraPresenter">
<top>
<Pane prefHeight="26.0" prefWidth="800.0" BorderPane.alignment="CENTER">
<children>
<MenuBar fx:id="menuBar" prefHeight="25.0" prefWidth="800.0">
<menus>
<Menu mnemonicParsing="false" text="Stock">
<items>
<MenuItem fx:id="createStock" mnemonicParsing="false" onAction="#showCreateStockForm" text="Create" />
<MenuItem fx:id="incoming" mnemonicParsing="false" onAction="#showIncomingForm" text="Incoming" />
</items>
</Menu>
</menus>
</MenuBar>
</children>
</Pane>
</top>
<center>
<SplitPane dividerPositions="0.5" orientation="VERTICAL" prefHeight="469.0" prefWidth="800.0" BorderPane.alignment="CENTER">
<items>
<BorderPane fx:id="contentBorderPane" prefHeight="200.0" prefWidth="200.0">
<center>
<AnchorPane fx:id="contentBox" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<AnchorPane fx:id="tableBox" minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0" />
</items>
</SplitPane>
</center>
</BorderPane>
adaraView.java
public class AdaraView extends FXMLView {
}
adaraPresenter.java
public class AdaraPresenter implements Initializable {
#FXML
AnchorPane contentBox;
#FXML
AnchorPane tableBox;
StockCreationPresenter stockCreationPresenter;
InwardsPresenter inwardsPresenter;
ViewStockPresenter viewStockPresenter;
#Override
public void initialize(URL location, ResourceBundle resources) {
StockCreationView scView = new StockCreationView();
// other codes
.
.
ViewStockView vsView = new ViewStockView();
// other codes
.
.
contentBox.getChildren().add(scView.getView());
tableBox.getChildren().add(vsView.getView());
}
public void showCreateStockForm(){
StockCreationView scView = new StockCreationView();
// other codes
.
.
ViewStockView vsView = new ViewStockView();
// other codes
.
.
contentBox.getChildren().add(scView.getView());
tableBox.getChildren().add(vsView.getView());
}
public void showIncomingForm(){
InwardsView inView = new InwardsView();
// other codes
.
.
ViewStockView vsView = new ViewStockView();
// other codes
.
.
contentBox.getChildren().add(inView.getView());
tableBox.getChildren().add(vsView.getView());
}
}
Here is the main class which is starting the stage and application.
Main.java
public class App extends Application
{
#Override
public void start(Stage stage) throws Exception {
AdaraView appView = new AdaraView();
Scene scene = new Scene(appView.getView());
stage.setTitle("Adara");
final String uri = getClass().getResource("app.css").toExternalForm();
scene.getStylesheets().add(uri);
stage.setScene(scene);
stage.show();
}
#Override
public void stop() throws Exception {
Injector.forgetAll();
}
public static void main(String[] args) {
launch(args);
}
}
Now here is the InwardsPresenter.java which have to save the stockCreationPresenter.java data into table as well as it have to open the inwardsView into the contentPane.
InwardsPresenter.java
public class InwardsPresenter implements Initializable {
#FXML
Button saveButton;
#FXML
TextField orderNo;
#FXML
TextField other;
#FXML
CheckBox save;
#Inject
AdaraPresenter adaraPresenter;
#Override
public void initialize(URL location, ResourceBundle resources) {
}
public void save() {
Inwards inward = newInward();
inward.setOrderNo(Integer.parseInt(orderNo.getText()));
inward.setOther(other.getText());
inward.setSave(save.isSelected());
this.newInward.set(inward);
adaraPresenter.incomingForm();
}
}
// while executing adaraPresenter.incomingForm(); it's showing NPE to contentBox and tableBox.
Thank you very much for any help.
I have the following FXML:
<BorderPane fx:controller="mypackage.MainStage" id="BorderPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
<bottom>
<ToolBar>
<items>
<Slider id="slider" prefWidth="443.0" />
<Label text="Record:" />
<TextField prefWidth="46.0" />
<Label text=" of " />
<Label id="totalLabel" text="0" />
</items>
</ToolBar>
</bottom>
<center>
<Pane id="mainPane" prefHeight="200.0" prefWidth="200.0" />
</center>
<top>
<ToolBar>
<items>
<Button mnemonicParsing="false" text="Load more" />
</items>
</ToolBar>
</top>
</BorderPane>
and the following controller code:
public class MainStage implements Initializable {
#FXML
private Pane mainPane;
#FXML
private Label totalLabel;
#Override
public void initialize(URL location, ResourceBundle resources) {
totalLabel.setText("245");
}
}
and the following application code
public class MyClass extends Application
{
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("MainStage.fxml"));
Scene scene = new Scene(root);
stage.setTitle("MyClass");
stage.setScene(scene);
stage.show();
}
public static void main( String[] args )
{
launch(args);
}
}
If I set breakpoint to initialize() I see it is called, but member is null.
Why isn't it injected?
Because I used id while was to use fx:id tag.
After much searching I found this question How to create a javafx 2.0 application MDI. What I really wanted to know is if I can create a pop-up window or child window to the main window using JavaFX components and Scene Builder to create the new window.
I ended up with this for a modal pop-up window:
In the Main class I wanted to save the primary stage to a field I can access from my primary controller class. So, I added a static variable Stage to it and this in the Main.Start() method:
primaryController.primaryStage = primaryStage;
This the method that a button in the primaryController uses:
public void OnBtnShowChild(ActionEvent event) {
MessageBoxController msgBox = new MessageBoxController();
try {
msgBox.showMessageBox(primaryStage);
} catch (Exception e) {
e.printStackTrace();
}
}
This is the MessageBoxController class that I created with help from Scene Builder. It has the basic layout of a standard pop-up box that can be used to display an Icon (ImageView), TextBox (for your message text), and two buttons (for YES/NO functionality). I am not sure yet how to have it communicate the results of what button was pressed back to the primaryController.
public class MessageBoxController implements Initializable {
#FXML
// fx:id="btnNo"
private Button btnNo; // Value injected by FXMLLoader
#FXML
// fx:id="btnYes"
private Button btnYes; // Value injected by FXMLLoader
#FXML
// fx:id="imgMessage"
private ImageView imgMessage; // Value injected by FXMLLoader
#FXML
// fx:id="txtMessage"
private TextField txtMessage; // Value injected by FXMLLoader
private Stage myParent;
private Stage messageBoxStage;
public void showMessageBox(Stage parentStage) {
this.myParent = parentStage;
try {
messageBoxStage = new Stage();
AnchorPane page = (AnchorPane) FXMLLoader.load(MessageBoxController.class.getResource("/MessageBox/MessageBoxFXML.fxml"));
Scene scene = new Scene(page);
messageBoxStage.setScene(scene);
messageBoxStage.setTitle("Message Box");
messageBoxStage.initOwner(this.myParent);
messageBoxStage.initModality(Modality.WINDOW_MODAL);
messageBoxStage.show();
} catch (Exception ex) {
System.out.println("Exception foundeth in showMessageBox");
ex.printStackTrace();
}
}
#Override
public void initialize(URL fxmlFileLocation, ResourceBundle arg1) {
txtMessage.setText("Howdy");
}
public void OnBtnYes(ActionEvent event) {
}
public void OnBtnNo(ActionEvent event) {
}
}
And finally, this is the FXML file I created in Scene Builder:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.net.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane id="AnchorPane2" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
prefHeight="172.0" prefWidth="524.0" xmlns:fx="http://javafx.com/fxml" fx:controller="MessageBox.MessageBoxController">
<children>
<VBox prefHeight="172.0" prefWidth="524.0" styleClass="vboxes" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<HBox alignment="CENTER" prefHeight="109.99990000000253" prefWidth="516.0" spacing="30.0">
<children>
<ImageView fx:id="imgMessage" fitHeight="110.0" fitWidth="146.66666666666666" pickOnBounds="true" preserveRatio="true" styleClass="null" />
<TextField fx:id="txtMessage" editable="false" prefHeight="47.0" prefWidth="325.0" />
</children>
<stylesheets>
<URL value="#MyCSS.css" />
</stylesheets>
</HBox>
<HBox alignment="CENTER" prefHeight="58.0" prefWidth="516.0" spacing="30.0">
<children>
<Button fx:id="btnYes" mnemonicParsing="false" onAction="#OnBtnYes" text="Button" />
<Button fx:id="btnNo" mnemonicParsing="false" onAction="#OnBtnNo" text="Button" />
</children>
</HBox>
</children>
<stylesheets>
<URL value="#MyCSS.css" />
</stylesheets>
</VBox>
</children>
<stylesheets>
<URL value="#MyCSS.css" />
</stylesheets>
</AnchorPane>
With this I can create a modal pop-up window, and I also want to create other child windows for displaying data in other ways using different controls. And, most importantly, I can use Scene Builder to create the layout.
What do you think? Is this a good way to do this until they add real support in Java 8 and JavaFX 8?
did you try wit the Group class? you can add diferent elements with fxml and controllers.
Group root= new Group();
AnchorPane frame=FXMLLoader.load(getClass().getResource("frame.fxml"));
AnchorPane content= FXMLLoader.load(getClass().getResource("principal.fxml"));
root.getChildren().add(window);
root.getChildren().add(frame);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();