Discussions
Categories
- 197K All Categories
- 2.5K Data
- 546 Big Data Appliance
- 1.9K Data Science
- 450.8K Databases
- 221.9K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 552 MySQL Community Space
- 479 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.1K ORDS, SODA & JSON in the Database
- 556 SQLcl
- 4K SQL Developer Data Modeler
- 187.2K SQL & PL/SQL
- 21.4K SQL Developer
- 296.3K Development
- 17 Developer Projects
- 139 Programming Languages
- 293K Development Tools
- 110 DevOps
- 3.1K QA/Testing
- 646.1K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 158 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.2K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 19 Java Essentials
- 162 Java 8 Questions
- 86K Java Programming
- 81 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 205 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 468 LiveLabs
- 39 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 175 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 233 Portuguese
stage.setScene(newScene);

915418
Member Posts: 3
Im uuing pretty mych default example file. Im trying to make default javafx program to load another scene from default button. Im using Netbeans 7.2.1.
lines which is errorious is:
Parent sceneMapRoot = FXMLLoader.load(getClass().getResource("piirros.fxml"));
would you need more information? I can also upload a package if that is needed.
Edited by: Ebure on 20.12.2012 7:04
Edited by: Ebure on 20.12.2012 7:06
lines which is errorious is:
Parent sceneMapRoot = FXMLLoader.load(getClass().getResource("piirros.fxml"));
would you need more information? I can also upload a package if that is needed.
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javafxapplicationfxml; import java.net.URL; import java.util.ResourceBundle; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; import javafx.scene.Parent; import javafx.scene.control.Label; import javafx.scene.Scene; import javafx.stage.Stage; /** * * @author ebure */ public class SampleController implements Initializable { @FXML private Stage stage; @FXML private Label label; @FXML private void handleButtonAction(ActionEvent event) { Parent sceneMapRoot = FXMLLoader.load(getClass().getResource("piirros.fxml")); Scene sceneMap = new Scene(sceneMapRoot,500,500); stage.setTitle("Welcome to game!"); stage.setScene(sceneMap); stage.show(); System.out.println("You clicked me!"); } @Override public void initialize(URL url, ResourceBundle rb) { // TODO } }Edited by: Ebure on 20.12.2012 6:22
Edited by: Ebure on 20.12.2012 7:04
Edited by: Ebure on 20.12.2012 7:06
Tagged:
Answers
-
# 1 #
???
@FXML
private Stage stage;
???
you need to use @FXML only to call nodes (with an id) inside the fxml.
stage contains your fxml, so delete these lines.
# 2 #
your fxml is supposed to be added in a scene. it knows nothing about it before his initialization.
it means that your code is "garbage"... (sorry)
make it in this way:
create a class like this that will create the scene and will fill it by the fxml content:public class ClassName extends Application { public static void main(String[] args) { Application.launch(ClassName.class, args); } @Override public void start(final Stage stage) throws Exception { //use here the path for the fxml you want to load as root Parent root = FXMLLoader.load(getClass().getResource("fxmlPath")); final Scene scene = new Scene(root); stage.setScene(scene); stage.setTitle("Title"); stage.show(); } }
then in fxml controller, just write nodes parameters, listener, handler etc etc related to the fxml itself.
ask for more or look at the javafx tutorial
Edited by: fabsav on 21-dic-2012 13.14
Edited by: fabsav on 21-dic-2012 13.15
This discussion has been closed.