Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javaFX in JDK SE 7

 
arjun gaur
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey!!
On oracle website it is mentioned that for javaFX api you require JDK SE 7 as it comes with jdk 7 or higher.
I have already downloaded and installed JDK SE 7 but i'm having a problem.
when i write the following code

i'm getting compiler error "package javafx does not exist"
Also in my JDK folder i couldn't see the package "javafx" as it is the case with other packages like "java" or "javax"
There's no issue with path(till bin) and classpath(till lib) ,i have set it correctly as i'm able to compile and run other programs.
Help me,how can i sort this out.
Thanks .
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are no classes in the javafx package, they're in subpackages: http://docs.oracle.com/javafx/2/api/index.html. (I'm assuming you have a recent version of JDK 7, early versions did not ship with JavaFX.)

Also in my JDK folder i couldn't see the package "javafx" as it is the case with other packages like "java" or "javax"

That's not how it works. The name of the jar file classes are in does not necessarily reflect their package name.
 
arjun gaur
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah i know that there are no classes in javafx package,but even when i'm using javafx.animation.*; or javafx.event.*;
still i'm getthing the same error "javafx.animation package not found". The problem persists.
And yes i'm using the latest version of jdk 7 , i downloaded it from webpage

Also just as i can see other packages like "java" and "javax" in my JDK folder , i couldn't find the javafx package.
Help me to resolve this.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15628
46
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With Java 7, JavaFX is included with the JDK and JRE, but it is not on the classpath by default. You have to add jfxrt.jar to your classpath (or to your project settings, if you're using an IDE).

You can find jfxrt.jar in the jre\lib directory.

Note: This will be different in Java 8; there, JavaFX will be on the classpath by default and you will not have to do anything special.
 
arjun gaur
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohk thanks for that.i'll try it.i'm not using any IDE just compiling via cmd.
And one more thing do i need to include that jar file in both "path" and "classpath" or "classpath" only.
and this jar file should be in classpath only when i'm using javafx package ? or even if i'm not using javafx then also is it ok to have classpath till that jar file .
one more thing : which jar file to include,i mean jfxrt is presnt in both jdk and jre folder because after installation 2 folders get created one for jdk that contains jre folder and one separate jre folder.
1) C:\Program Files\Java\jre7\lib\jfxrt.jar
2)C:\Program Files\Java7\jdk1.7.0_51\jre\lib\jfxrt.jar
Thanks.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The PATH has nothing to do with how Java classes are found.

It's safe to include even if you're not using JavaFX in some particular piece of code.

Those two files should be identical, assuming that you don't have multiple versions of Java 7 installed.
 
arjun gaur
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.i included that file and now i'm able to compile but now help me with running a small app.
i used the following code from oracle's tutorial but not able to run it .



i got to know that start() is the entry point for javafx applications.tell me what modifications do i need to do here to run the application.
Thanks.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15628
46
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make your main method look like this:
 
arjun gaur
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ohk thanks..and can you tell me how these launch(args) and start() are working.i mean how is the control flowing in the code?
whether launch() calls start() ?and both start() and launch() are part of Application class ?
Thanks..
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To learn which method gets called when you could add System.out.println statements at the start of each method. The javadoc of the javafx.application.Application class answers the other questions.
 
arjun gaur
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks..and do we have anything like a JOptionPane ,dialogbox kind of a thing in javafx like we have in javax.swing.
Suppose i want to pop up a message on a button click ,in swings i can do so with JOptionPane.showMessageDialog();
So, can we do such thing in a javaFX program ? If yes,then how and what classes and methods are required.
Thanks.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not too familiar with JavaFX, so I don't know what components it comes with, but I thought it was possible to use Swing components in JavaFX apps. http://docs.oracle.com/javafx/8/embed_swing/jfxpub-embed_swing.htm and http://docs.oracle.com/javafx/2/swing/swing-fx-interoperability.htm make it sound as if that's possible even side by side within a component, so I'd think it should definitely be possible when using a "standalone" component like a JOptionPane.
 
arjun gaur
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks mate..
If anyone else is familiar with javafx do let me know.
Thanks.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This seems a common thing to want to do. A quick search for "javafx joptionpane" found numerous relevant links, like http://edu.makery.ch/blog/2012/10/30/javafx-2-dialogs/, http://syedfarhanquadri.blogspot.de/2013/08/javafxstagepopup-as-joptionpane.html and https://community.oracle.com/thread/2298354.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic