fxml

MVC with JavaFX and FXML

别说谁变了你拦得住时间么 提交于 2019-12-22 00:40:09
问题 If I have a JavaFX project that uses FXML, how would I structure it to adhere to the Model-View-Controller pattern? This is what I would assume the general structure to be like: Model - Underlying program (what the GUI is representing). View - FXML file. Controller - FXML controller. The issue with this representation is that the view cannot be notified of the model's changes, as it is simply an FXML file. Should the view be the FXML controller class, and then should I have a main controller

Pass object from one scene to another

谁都会走 提交于 2019-12-21 20:48:36
问题 As I'm learning the new world of JavaFX2 I stumbled on another annoying problem. I'm developing a program with multiple scenes (~10 scenes). For that I created a small class like this: public class SceneSelector { ... public void setScene(Stage stage, String fxmlfilename, ObservableList ol) throws Exception{ String s = "../" + fxmlfilename; Parent root = FXMLLoader.load(getClass().getResource(s)); root.setUserData(ol); Scene scene = new Scene(root); stage.setScene(scene); //show the stage

Migrate from Javafx2.2 to Javafx8

偶尔善良 提交于 2019-12-21 20:25:42
问题 I am trying to migrate Javafx2.2 application to Javafx8. I am getting following issue while using nested FXML : javafx.fxml.LoadException: Root hasn't been set. Use method setRoot() before load. FXML file: <fx:root type="javafx.scene.layout.VBox" xmlns:fx="http://javafx.com/fxml" xmlns="http://javafx.com/javafx/8" fx:controller="com.ui.TestController"> <TextField fx:id="textField"/> <Button text="Click Me"/> </fx:root> Code: FXMLLoader loader = new FXMLLoader(); loader.setResources(bundle);

JavaFX access parent Controller class from FXML child

自古美人都是妖i 提交于 2019-12-21 12:42:02
问题 using JavaFX for an application and I have a Main.fxml file with some fxml child files inside it. I would like to access to MainController class of Main.fxml from the child Controllers. I'll try to explain better with an example: MainFxml: <HBox fx:controller="MainController.java"> <fx:include source="child.fxml"/> </HBox> MainController: public class MainController implements Initializable { private String string; public void setString (String string) { this.string = string; } ChildFxml:

FXML, JavaFX 8, TableView: Make a delete button in each row and delete the row accordingly

半世苍凉 提交于 2019-12-20 23:23:14
问题 I am working on a TableView (FXML) where I want to have all the rows accompanied with a delete button at the last column. Here's a video that shows what I mean: YouTube Delete Button in TableView Here's what I have in my main controller class: public Button del() { Button del = new Button(); del.setText("X"); del.setPrefWidth(30); del.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { int i = index.get(); if(i > -1) { goals.remove(i); list.getSelectionModel(

JavaFX 8 - Tabpanes and tabs with separate FXML and controllers for each tab

删除回忆录丶 提交于 2019-12-20 19:41:07
问题 I hope to get some answers regarding having fx:include statements for each tab in a tabpane. I have managed with ease to get content to show up BUT referencing methods of the associated controller class simply gives me a nullpointerreference exception no matter how I structure it. The controllers of the included FXML layouts do not have neither constructor not initialize() methods, are they needed? I tried some different things but always got the same exception. What I simply did was add a

JavaFX 8 - Tabpanes and tabs with separate FXML and controllers for each tab

陌路散爱 提交于 2019-12-20 19:40:35
问题 I hope to get some answers regarding having fx:include statements for each tab in a tabpane. I have managed with ease to get content to show up BUT referencing methods of the associated controller class simply gives me a nullpointerreference exception no matter how I structure it. The controllers of the included FXML layouts do not have neither constructor not initialize() methods, are they needed? I tried some different things but always got the same exception. What I simply did was add a

How to set button text in JavaFX?

时间秒杀一切 提交于 2019-12-20 07:46:56
问题 I'm trying to set the button text using this code: public void initialize(URL location, ResourceBundle resources) { // TODO Auto-generated method stub //checking to see whether these buttons were loaded from the FXML file assert fx_btnStart != null : "fx:id=\"fx_btnStart\" was not injected: Check your FXML file 'FX-Timer.fxml'."; assert fx_btnStop != null : "fx:id=\"fx_btnStop\" INJECTION ERROR"; assert fx_btnHourUp != null : "fx:id=\"fx_btnHourUp\" INJECTION ERROR"; assert fx_btnHourDown !=

How to show / hide / auto hide a node

天大地大妈咪最大 提交于 2019-12-20 07:35:29
问题 I am doing a javafx project which if i click the button, the scene is showing, but if the scene is left open for few seconds, the scene will auto hide. The actual scene is if i left it open, it will auto hide at the below of the main scene just like the button is pressed. But i tried alot ways, the scene will either not hiding, or moving upward which if i click the button, the scene is at upward of the scene moving but not on the main scene. If the scene is not on main scene, nothing will

Switch between fxml files

╄→гoц情女王★ 提交于 2019-12-20 07:28:53
问题 I have created an application using jfxPanel inside swing component. The problem I am facing is I am not being able to change the fxml files. When a button of the fxml is clicked, I want to dispose that fxml and load another fxml file there. This is what I have done till now public class NonResponsiveButtons extends JFrame { NonResponsiveButtons nrb; BottomPanelIncomingController bpic; JPanel panel; JPanel bPanel; private int applicationWidth_600 = 600; private int applicationHeight_600 = 600