11 Replies Latest reply on Jun 6, 2013 11:52 PM by user8709910

    GridPane class

    user8709910
      Dear Friends,


      I am new to JavaFX and I am trying to get started with netbeans and javafx. I have the latest netbeans 7.3 and javafx21 installed. But when I am trying to create the object

      GridPane grid = new GridPane(); netbeans says cannot find the symbol. This is from the tutorial 2 Creating a Form in JavaFX in http://docs.oracle.com/javafx/2/get_started/form.htm


      How can import this class? How can I solve the problem?


      THank you
        • 1. Re: GridPane class
          James_D
          Do you have
          import javafx.scene.layout.GridPane ;
          If you have it, and it's not recognized, you have your classpath misconfigured for the project. I'm not a NetBeans user so someone else can probably help you more easily with that.

          You should use the most recent version, though. JavaFX 2.1 is old. [url http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html]Download the latest JDK (1.7.0 update 21 at the time of writing), which includes JavaFX 2.2_xx. JavaFX is bundled with this version; you'll find it in the jre/lib directory, packaged as jfxrt.jar, under the JDK installation directory. I believe NetBeans will find this automatically once it knows where the JDK is.

          Edited by: James_D on Jun 6, 2013 2:14 PM (Corrected import statement)
          • 2. Re: GridPane class
            user8709910
            I have the latest version.... when I write import javafx.layout.GridPane ; netbeans says package javafx.layout doesn't exist


            Is it any better software I can use to run javafx? What are you using?

            I am interesting to develop animations and 3d is the javafx most suitable or some other java version better?

            THanks

            Edited by: user8709910 on Jun 6, 2013 12:54 PM
            • 3. Re: GridPane class
              shakir.gusaroff
              You have to create your application as Javafx application, not as Java application.

              File -> New Project -> JavaFX - -> Javafx Application
              • 4. Re: GridPane class
                James_D
                >
                Is it any better software I can use to run javafx? What are you using?
                javafx runs just with a properly-configured JRE. To develop JavaFX applications I use Eclipse with the E(fx)clipse plugin. I don't think either Eclipse or Netbeans have strong claims to be any better than the other, though; it's just a matter of preference and I've been using Eclipse for years and years. If you're starting from scratch Netbeans is probably slightly easier to get set up.
                I am interesting to develop animations and 3d is the javafx most suitable or some other java version better?
                IMO if you want to write animation in Java, JavaFX 2 (and later) is by far the best way to go. For 3D you're probably going to want to be using JavaFX8, which is only in beta (and has limited support from Netbeans, though I think it will work; if you're going to use the beta version of Java 8, you might want to look into using IntelliJ as your IDE). The 3D support is still a bit primitive, depending on what you want to do. (3D transforms of 2D objects are well supported, even in JavaFX 2.2; 3D objects were only recently introduced to the JavaFX 8 build.)
                THanks

                Edited by: user8709910 on Jun 6, 2013 12:54 PM
                • 5. Re: GridPane class
                  user8709910
                  I am creating my applications as JavaFX applicaiton but still when I run it I get this error

                  C:\Users\haris\Documents\NetBeansProjects\fxlogin\src\fxlogin\Fxlogin.java:29: error: cannot find symbol
                  GridPane grid = new GridPane();


                  Why netbeans 7.3 installed cannot find the Java fx classes?

                  Here is my code:


                  /*
                  * To change this template, choose Tools | Templates
                  * and open the template in the editor.
                  */
                  package fxlogin;

                  import javafx.application.Application;
                  import javafx.event.ActionEvent;
                  import javafx.event.EventHandler;
                  import javafx.scene.Scene;
                  import javafx.scene.control.Button;
                  import javafx.scene.layout.StackPane;
                  import javafx.stage.Stage;

                  /**
                  *
                  * @author haris
                  */




                  public class Fxlogin extends Application {

                  @Override
                  public void start(Stage primaryStage) {
                  primaryStage.setTitle("JavaFX Welcome");

                  GridPane grid = new GridPane();
                  grid.setAlignment(Pos.CENTER);
                  grid.setHgap(10);
                  grid.setVgap(10);
                  grid.setPadding(new Insets(25, 25, 25, 25));

                  Text scenetitle = new Text("Welcome");
                  scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
                  grid.add(scenetitle, 0, 0, 2, 1);

                  Label userName = new Label("User Name:");
                  grid.add(userName, 0, 1);

                  TextField userTextField = new TextField();
                  grid.add(userTextField, 1, 1);

                  Label pw = new Label("Password:");
                  grid.add(pw, 0, 2);

                  PasswordField pwBox = new PasswordField();
                  grid.add(pwBox, 1, 2);

                  Scene scene = new Scene(grid, 300, 275);
                  primaryStage.setScene(scene);
                  primaryStage.show();
                  }

                  /**
                  * The main() method is ignored in correctly deployed JavaFX application.
                  * main() serves only as fallback in case the application can not be
                  * launched through deployment artifacts, e.g., in IDEs with limited FX
                  * support. NetBeans ignores main().
                  *
                  * @param args the command line arguments
                  */
                  public static void main(String[] args) {
                  launch(args);
                  }
                  }
                  • 6. Re: GridPane class
                    James_D
                    I don't see
                    import javafx.scene.layout.GridPane ;
                    in your code
                    • 7. Re: GridPane class
                      user8709910
                      Thanks this seems to solve some of the problems, but still when I run it I get this

                      Compiling 1 source file to C:\Users\haris\Documents\NetBeansProjects\fxlogin\build\classes
                      C:\Users\haris\Documents\NetBeansProjects\fxlogin\src\fxlogin\Fxlogin.java:31: error: cannot find symbol
                      grid.setAlignment(Pos.CENTER);
                      symbol: variable Pos
                      location: class Fxlogin
                      C:\Users\haris\Documents\NetBeansProjects\fxlogin\src\fxlogin\Fxlogin.java:34: error: cannot find symbol
                      grid.setPadding(new Insets(25, 25, 25, 25));
                      symbol: class Insets
                      location: class Fxlogin
                      C:\Users\haris\Documents\NetBeansProjects\fxlogin\src\fxlogin\Fxlogin.java:36: error: cannot find symbol
                      Text scenetitle = new Text("Welcome");
                      symbol: class Text
                      location: class Fxlogin
                      C:\Users\haris\Documents\NetBeansProjects\fxlogin\src\fxlogin\Fxlogin.java:36: error: cannot find symbol
                      Text scenetitle = new Text("Welcome");
                      symbol: class Text
                      location: class Fxlogin
                      C:\Users\haris\Documents\NetBeansProjects\fxlogin\src\fxlogin\Fxlogin.java:37: error: cannot find symbol
                      scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
                      symbol: variable FontWeight
                      location: class Fxlogin
                      C:\Users\haris\Documents\NetBeansProjects\fxlogin\src\fxlogin\Fxlogin.java:37: error: cannot find symbol
                      scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
                      symbol: variable Font
                      location: class Fxlogin
                      C:\Users\haris\Documents\NetBeansProjects\fxlogin\src\fxlogin\Fxlogin.java:40: error: cannot find symbol
                      Label userName = new Label("User Name:");
                      symbol: class Label
                      location: class Fxlogin
                      C:\Users\haris\Documents\NetBeansProjects\fxlogin\src\fxlogin\Fxlogin.java:40: error: cannot find symbol
                      Label userName = new Label("User Name:");
                      symbol: class Label
                      location: class Fxlogin
                      C:\Users\haris\Documents\NetBeansProjects\fxlogin\src\fxlogin\Fxlogin.java:43: error: cannot find symbol
                      TextField userTextField = new TextField();
                      symbol: class TextField
                      location: class Fxlogin
                      C:\Users\haris\Documents\NetBeansProjects\fxlogin\src\fxlogin\Fxlogin.java:43: error: cannot find symbol
                      TextField userTextField = new TextField();
                      symbol: class TextField
                      location: class Fxlogin
                      C:\Users\haris\Documents\NetBeansProjects\fxlogin\src\fxlogin\Fxlogin.java:46: error: cannot find symbol
                      Label pw = new Label("Password:");
                      symbol: class Label
                      location: class Fxlogin
                      C:\Users\haris\Documents\NetBeansProjects\fxlogin\src\fxlogin\Fxlogin.java:46: error: cannot find symbol
                      Label pw = new Label("Password:");
                      symbol: class Label
                      location: class Fxlogin
                      C:\Users\haris\Documents\NetBeansProjects\fxlogin\src\fxlogin\Fxlogin.java:49: error: cannot find symbol
                      PasswordField pwBox = new PasswordField();
                      symbol: class PasswordField
                      location: class Fxlogin
                      C:\Users\haris\Documents\NetBeansProjects\fxlogin\src\fxlogin\Fxlogin.java:49: error: cannot find symbol
                      PasswordField pwBox = new PasswordField();
                      symbol: class PasswordField
                      location: class Fxlogin
                      14 errors
                      C:\Users\haris\Documents\NetBeansProjects\fxlogin\nbproject\build-impl.xml:960: The following error occurred while executing this line:
                      C:\Users\haris\Documents\NetBeansProjects\fxlogin\nbproject\build-impl.xml:297: Compile failed; see the compiler error output for details.
                      BUILD FAILED (total time: 6 seconds)
                      • 8. Re: GridPane class
                        James_D
                        You're missing a ton more imports. You should be able to hover over the errors, or maybe right-click, to get suggested automatic fixes for the imports.
                        • 9. Re: GridPane class
                          jsmith
                          @user8709910 I recommend spending a couple of days learning the Java language before you start developing JavaFX applications.
                          http://docs.oracle.com/javase/tutorial/java/
                          • 10. Re: GridPane class
                            KonradZuse
                            in Metbeans you press and hold control + shift + i and it will IMPORT everything you need, and UN-IMPORT un-used imports.


                            Whenever you do Class name = new Class(); do this. This is how I do it, it's simple and fast. Also you do need to make sure it's the FX control you want though. When you import it either automatically imports it, gives you some choices,or it gives you a list of all imports and choice for each. If you have a label there are 2 types of labels. Swing's and FX's, so make sure you're importing the right one, same with ANY GUI component.
                            • 11. Re: GridPane class
                              user8709910
                              Thanks James, I solved the problems, its working now, I imported everything