Refering FXML file element into Main class in Javafx

Hi,
  Is it possible to refer FXML file elements or components  in main class in javafx?
   if possible then how?

Typically you define a controller class to interact with the UI components. You can inject components into the controller by defining them as fields annotated with @FXML, and then define a fx:id attribute for those elements in the FXML file with attribute values matching the variable name in the controller class. There's a example in the "Adding Rows to the Table" section of the FXML tutorial.

Similar Messages

  • Problem in file association and main-class in JWS

    Hello , all
    I have a problem in JWS with file association and main-class. I have a java application that has two entry classes, one is appmain.class that is required to launch from web, and the other is player.class that is required to launch when user double-click the .abc extension file.
    In JWS 5.0+, there is a association element in JNLP syntax that can be used to make the file association with .abc extension. But how can I declare the main-class in JNLP file?
    If I declare the application-desc element as <application-desc main-class="player">, the player.class will be launched from web. But if I declare it as <application-desc main-class="appmain">, the .abc extension wil be associated to the appmain.class.
    Does anyone know how to solve this problem? Thank you for your kindly help.

    One way is to define a third main that refers
    to the other two, as appropriate. E.G. if the
    web based main does not include -open as
    its arguments, it is easy.class WebStartSpringboard {
      /** Call web based main unless args include -open. */
      public static void main(String[] args) {
        if (args[0].equals("-open") ) {
          OpenFileBasedClass.main(args);
        } else {
          WebBasedClass.main(args);
    }Other measures might be taken for a situation
    where the web based version does include a
    -open argument.

  • How can I assign image file name from Main() class

    I am trying to create library class which will be accessed and used by different applications (with different image files to be assigned). So, what image file to call should be determined by and in the Main class.
    Here is the Main class
    import org.me.lib.MyJNIWindowClass;
    public class Main {
    public Main() {
    public static void main(String[] args) {
    MyJNIWindowClass mw = new MyJNIWindowClass();
    mw.s = "clock.gif";
    And here is the library class
    package org.me.lib;
    public class MyJNIWindowClass {
    public String s;
    ImageIcon image = new ImageIcon("C:/Documents and Settings/Administrator/Desktop/" + s);
    public MyJNIWindowClass() {
    JLabel jl = new JLabel(image);
    JFrame jf = new JFrame();
    jf.add(jl);
    jf.setVisible(true);
    jf.pack();
    I do understand that when I am making reference from main() method to MyJNIWindowClass() s first initialized to null and that is why clock could not be seen but how can I assign image file name from Main() class for library class without creating reference to Main() from MyJNIWindowClass()? As I said, I want this library class being accessed from different applications (means different Main() classes).
    Thank you.

    Your problem is one of timing. Consider this simple example.
    public class Example {
        public String s;
        private String message = "Hello, " + s;
        public String toString() {
            return message;
        public static void main(String[] args) {
            Example ex = new Example();
            ex.s = "world";
            System.out.println(ex.toString());
    }When this code is executed, the following happens in order:
    1. new Example() is executed, causing an object to constructed. In particular:
    2. field s is given value null (since no value is explicitly assigned.
    3. field message is given value "Hello, null"
    4. Back in method main, field s is now given value "world", but that
    doesn't change message.
    5. Finally, "Hello, null" is output.
    The following fixes the above example:
    public class Example {
        private String message;
        public Example(String name) {
            message = "Hello, " + name;
        public String toString() {
            return message;
        public static void main(String[] args) {
            Example ex = new Example("world");
            System.out.println(ex.toString());
    }

  • Java .class files - Moving the Main Class .class file to a new location

    Novice question....so much so that I hope it's even coherent...
    In a Java program which references many associated .class files (e.g. bicycleMain.class, bicycleSub1.class, bicycleSub2.class, etc....), do the associated .class files always have to be located in the same directory as the Main .class file?
    What I'm getting at is - If I've developed an application consisting of several .class files on my own Windows PC and I want to put the compiled application out on our Windows File Server so that anyone can execute my application, how would I go about doing this?
    Say I put the compiled .class files in H:\PROJECTS\JAVA\COMPILED\, will other people be able to execute the application from their PCs by simply issuing the command line:
    'java h:\projects\java\compiled\bicycleMain'
    Any insights would be very helpful in getting me oriented. Thanks in advance.

    Interesting...so are you saying the command line might look something like this:
    java -classpath h:\projects\java\compiled bicycleMain
    And if I want other people to be able to execute the application without specifying the -classpath option then they would need to manually update the ClassPath environment variable on their individual PCs first?

  • Implimenting GUI into main class

    Hello all, I'm trying to figure out how to create a GUI for a program I'm writing.
    Basically, the program I'm making allows a user to search through a list of movies that have been entered into a database (a textfile). The movie objects have a Title, Description, Genre, and a Rating.
    I'm a little confused as to how I should set up all my code. I've written most of the background code to sort and search the movie objects, and I've also written most of the code to display the GUI. I just don't really know how to link them both.
    Here's my question. I have a GUI class that currently has a main method, which calls run(), which then calls createAndShowGUI(), a method of the GUI class. Is this the right way to do things?
    I also have a MovieSorter class, which creates an ArrayList of movieObjects, with the information taken from the text file. Unfortunatly, this too has a main method. So right now I can run the program from either class, to get the GUI to display, or to get the functional program to run. I don't know how to combine them.
    I'm assuming I will have the main method be in the MovieSorter class, that will call the createAndShowGUI method, which will then display the GUI. Then the GUI listens for any input (buttons, etc) and calls the appropriate methods accordingly. Is this right?
    I guess my main question is am I supposed to have a GUI object that I somehow put inside a JFrame (the GUI object being a JPanel or something)? I don't really know how the program is supposed to flow.
    Thanks!
    EDIT I can attach the code if you like, but it's a bit long.
    Edited by: lifeismusic434 on Oct 22, 2008 6:57 PM

    My take on something like this is that I look on the GUI as the View, and the non-GUI class as the Model. I suppose the program will be started by some Control object that will start up the GUI and start up the Model and link the two. Without more specifics, I'm afraid that that's the best that I can do. Hopefully someone else will give you more helpful advice.

  • One class type compiles into many .class files

    I have written a single large GUI file that is composed of a single class (FCTabGui class). When I run javac FCTabGui.java it generates around 190 classes with the same name (FCTabGui) but each one after the first is attached with $# at the end (ie FCTabGui$1.class, ..., FCTabGui$189.class) . I have never seen this before. Does anyone know why this is happening and how I can keep it to just one .class file instead of 190. Thanks.
    Jason

    What I meant by "standard to jar up files for a GUI"
    is that if there are lots of buttons that create
    anonymous classes then you HAVE to jar up the files
    because there is no alternative to it. One cannot
    preserve the single .class file setup with a GUI,
    unless its really small and has no action listeners.I suppose you could contort your code so that the single class not only creates all the widgets but also acts as the single action listener for every single button. This way you could avoid creating anonymous inner classes. But anyone who needs to maintain your code will grow to hate you.
    One can double click on a jar file and it will start
    running automatically, (assuming the JRE is
    installed), right?You can do that, but it's not automatic. You have to explicitly list what class has the main() method to invoke when the jar is double clicked. If you're using a wizard to create the jar, this may be easily specified. Otherwise you can do it by creating a jar manifest file with a "Main-class:" attribute.

  • "Failed to load main class manifest attribute from " directory path

    i get this error when trying to run a jar file i made with eclipse. does anyone know how to fix it? thanks derek
    "Failed to load main class manifest attribute from "<directory path>

    A JAR file is simply a collection of class files, in order to make it an "executable" JAR file you must specify which class file is the "main" class file. In other words, which class should the runtime start executing first. You do this using what is called a manifest file, this is meta information included into the JAR file that the runtime extracts and uses. One attribute is the Main-Class key, which specifies the application's entry point.
    The Java tutorial goes into further detail on how to do this
    http://java.sun.com/docs/books/tutorial/deployment/jar/appman.html
    You may also do this using Eclipse by going File -> Export -> Java -> JAR and follow the wizard.
    Using Netbeans this almost comes for free.

  • How to specify relative path for file name in java class

    I have a directory structure like this.
    C:\Aurora\com\optemys\aurora\validation
    I have a class Test.java under the validation folder.
    I have various files under the same folder i.e validation.
    If I want to access the file "test.properties" in Test.java, how can I just specify "test.properties" & not "C:\Aurora\com\optemys\aurora\validation\test.properties".
    I dont want to hardcode any file path into the class. How can I specify the relative file name into the class.
    Thanks In Advance
    Sachin

    switch the name in Test.properties and use
    this.getClass().getResourceAsStream(fileName)

  • Could not find the main class. Program will exit!

    I have created many Executable Jar files before, and this one I did the same. When I run the jar file, (Clicking on it) I get the "Could not find the main class. Program will exit!" error message. When I run the jar file through DOS I get this Stack trace:
    Exception in thread "main" java.lang.NoClassDefFoundError: javax/media/ControllerListener
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:509)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:246)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)
    Any Ideas? I did a search on google, and looks like others have had this problem but found no answer.
    US101

    There could be several reasons for getting this "Could not find main class" error message. From your stack trace it looks like the class javax/media/ControllerListener is not in your class path. Make sure your manifest file has a line like this:
    Class-Path: pathToTheJarFileWithControllerListenerClass.jar otherJars.jar
    This error message is also generated whenever any static initialization errors out giving the misleading error message implying that there is something wrong with the main class. Prior to starting your main class, static initialization of any static variables takes place. In my case, I was initializing a resource bundle, and forgot to include the property file in my building of the jar file. Well this failed of course and the generic error message appeared. It took many long hours to figure out it didn't have anything to do with the manifest file or the main class itself.
    HTH,
    John Bender

  • Could not find the main class ! exception.

    hi,
    I create one java project. for this I am using netbeans 5.
    I try to run the project jar file stff.jar. When run using "java -jar stff.jar " , it throws error "could not find the main class. program will exit".
    I am extracting this jar file, in manifest, main class is set.
    i.e, in manifest, Main-Class: ems.emsFrame.
    ems is my folder ,inside it main class kept.
    here, emsFrame is my main class where " public static void main (String args[])" is located.
    I am also, set the class path for that class folder(ems) and run.
    The same error ("could not find the main class. program will exit") occured.
    Why this error occured.
    also,I am uninstall the jdk and reinstall .
    whats my problem.
    bye

    yes sir.
    In projects, inside it, in Libraries ,the SNMPInquisitor.jar is located.
    inside that jar, snmp package is located.
    but, when build and run, there is no problem sir.
    Only when i try to run the stff.jar file (java -jar stff.jar), that time only the exception thrown.
    when I double click that jar, it show, "could not find the main class. program will exit". But, I am adding the main class in manifest. when i open manifest.mf, it show, Main-Class: ems.emsFrame.
    but, when i run jar thro' cmd window, it shows,
    Exception in thread "main" java.lang.NoClassDefFoundError: snmp/SNMPGetException
    at ems.emsFrame.<init>(emsFrame.java:1163)
    at ems.emsFrame.<clinit>(emsFrame.java:1155).
    i am still trying it.

  • Main-class not found error while clicking on the jar

    I have a created a jar �FinARM.jar� for my swing application using eclipse.
    Clicking on this jar, it is giving the problem main-class not found.
    It contains the MANIFEST.MF file, with entry Main-Class: FinAlignTest for the main class.
    FinAlignTest is my main class.
    I have a similar jar created with a small swing application (Single file) clicking on it can open the swing application.
    It is also attached above.

    Hi ,
    My Apllication runs with out any warnings or errors. But when i create a jar file using eclipse it is giving this problem.
    When i double click on the jar file i am getting this problem. MANIFEST.MF entry contains the main method entry.
    I have created another jar (Which contains a simple java file, swing application) from eclipse export option.
    It works fine on click.
    But jar FinARM.jar contains 5 files (Swing app), which even fetch some data from the database.
    My jar is placein the same machine where it can fetch data from DB
    Can u plese tell me whats the problem.
    -regards
    Anu

  • Multiple palette files in a library/class file causes problems

    While developing a labview class, I wanted to set the default palette, so I added the relevant dir.mnu file to the class. Unfortunately, the class already had a dir.mnu file in it. On adding the file, I got some error message about a dependency change*(which makes no sesne, how can a palette file have any dependencies !). On saving the class and then attempting to reopen it, LabVIEW claims it is corrupt. Inspecting the xml .lvclass files reveals that when I added the new paletee file, LabVIEW actually just added a second reference to the palette file already in the project, which it then considers to be a problem when it tries loading the class. This is clearly a bug on a number of levels:
    It should not be possible for the user to induce LabVIEW to create corrupt xml files through such simple attempts to use documented features.
    The underlying problem is that LabVIEW appears to be using the conventional search/linking rules to load library items irrespective of whether they are a vi (which should ahve a unique name) or other file (which might well be legitimately non-unique).
    Given the near impossibility of renaming a palette file without breaking palette links this particular bug is extra annoying.
    Gavin Burnell
    Condensed Matter Physics Group, University of Leeds, UK
    http://www.stoner.leeds.ac.uk/
    Solved!
    Go to Solution.

    Sorry for the delay, it took me a little longer to reproduce the problem systematically. Attached are three zip files of the same trivial class. The only difference between them is the contents of the class file itself.
    The key point is that I have two folders in my class - Public and Protected (although I haven't actually set the access scope I realise). Each folder has a dir.mnu file in it and there is also a dir.mnu file in the main class folder. The class virtual folder structure maps directly to the on disc version.
    In the first zip file the dir.mnu files are not added to the class.
    In the second zip dile I added the dir.mnu by right clicking and doing Add file...  This is allowed because each dir.mnu has a distinct path. I then save the class file and close it.
    To get the third zip file, I reopen the class file. I  get a single dependency warning about dir.mnu in one of the sub folders. So I think "fine ok, somethign funny about that dir.mnu file" - note if I'm loading a whole heirarchy of classes I may be told LabVIEW is laoding the dir.mnu file from somewhere completely different in my class structure. I then save the class file to give the thrid zip file.
    The lvclass file in the third zip file is corrupt because it has multiple entries for the same file, because it didn't handle having more than 2 items conflicting.
    The correct behaviour would be not to invoke the conflicting item names for non vi/ctl document types. I could imagine that there would be similar problems if I had a say a whole range of say README.html files strewn over the place.
    Gavin Burnell
    Condensed Matter Physics Group, University of Leeds, UK
    http://www.stoner.leeds.ac.uk/
    Attachments:
    Break Class File-1.zip ‏21 KB
    Break Class File-2.zip ‏21 KB
    Break Class File-3.zip ‏21 KB

  • The manifest file "could not find the main class."

    The main class file is inside a folder in the created Jar file, but is not in a package. But when I double-click the Jar file, it says it could not find the main class. I am using Windows. I have tried each of the following lines in the manifest, but none are working:
    Main-Class: Installer
    Main-Class: setupFiles/programFile/Installer
    Main-Class: setupFiles\programFile\Installer
    Main-Class: setupFiles.programFile.InstallerThe main class is inside the setupFiles/programFile directory. Please Help!
    Thanks in advance,
    ~ Tom

    Hi Tom,
    The main class file is inside a folder in the created
    Jar file, but is not in a package. This is the problem. A JAR file is not an arbitrary ZIP file, where you can arrange directories as you like. The structure of a JAR file always has to follow the package structure. So your Installer class must be on the top level and not in directory setupFiles/programFile.
    You might add non-class files in other directores and can access them as resources, but you have to put the class files into their "natural" directories.

  • Jar files and Main-Class attribute

    Sorry, I know there are other topics regarding this argument but none of them helped me solving my problem.
    I've tried a thousand time in every possible way, but I still can't run my application from a jar file. I've got a package called client, whose main class is called Client. The package contains a sub-package called Icons. I've put everything into a jar file and added this manifest:
    Manifest version: 1.0
    Name: client/
    Sealed: True
    Main-Class: client.Client
    But it won't work. I've tried to erase the Sealed part, I've tried "Main-Class: Client" and also "client/Client", I've tried putting into the jar the client directory and I've tried omitting it, but the answer is always the same:
    Failed to load main-class header etc.
    Can anyone help me? Please, I'm almost desperate!
    Thanks

    Here's the verbose-mode description of what I did.
    jar -cfv client.jar clientaggiunto manifesto
    aggiunta in corso di: client/(in = 0) (out= 0)(archiviato 0%)
    aggiunta in corso di: client/.nbattrs(in = 767) (out= 310)(compresso 59%)
    aggiunta in corso di: client/Client.class(in = 533) (out= 340)(compresso 36%)
    aggiunta in corso di: client/Client.java(in = 288) (out= 140)(compresso 51%)
    aggiunta in corso di: client/ClientForm$1.class(in = 691) (out= 383)(compresso 44%)
    aggiunta in corso di: client/ClientForm$10.class(in = 678) (out= 380)(compresso 43%)
    aggiunta in corso di: client/ClientForm$11.class(in = 689) (out= 385)(compresso 44%)
    aggiunta in corso di: client/ClientForm$2.class(in = 686) (out= 379)(compresso 44%)
    aggiunta in corso di: client/ClientForm$3.class(in = 686) (out= 381)(compresso 44%)
    aggiunta in corso di: client/ClientForm$4.class(in = 686) (out= 380)(compresso 44%)
    aggiunta in corso di: client/ClientForm$5.class(in = 686) (out= 383)(compresso 44%)
    aggiunta in corso di: client/ClientForm$6.class(in = 718) (out= 399)(compresso 44%)
    aggiunta in corso di: client/ClientForm$7.class(in = 718) (out= 400)(compresso 44%)
    aggiunta in corso di: client/ClientForm$8.class(in = 718) (out= 399)(compresso 44%)
    aggiunta in corso di: client/ClientForm$9.class(in = 718) (out= 398)(compresso 44%)
    aggiunta in corso di: client/ClientForm.class(in = 33070) (out= 13510)(compresso 59%)
    aggiunta in corso di: client/ClientForm.form(in = 131398) (out= 4521)(compresso96%)
    aggiunta in corso di: client/ClientForm.java(in = 73435) (out= 6863)(compresso 90%)
    aggiunta in corso di: client/Icons/(in = 0) (out= 0)(archiviato 0%)
    aggiunta in corso di: client/Icons/brick.gif(in = 1044) (out= 1049)(compresso 0%)
    aggiunta in corso di: client/Icons/corpo.gif(in = 4011) (out= 3400)(compresso 15%)
    aggiunta in corso di: client/Icons/door.gif(in = 1092) (out= 1097)(compresso 0%)
    aggiunta in corso di: client/Icons/floor.gif(in = 1102) (out= 1107)(compresso 0%)
    aggiunta in corso di: client/Icons/mappa.gif(in = 20901) (out= 20575)(compresso 1%)
    aggiunta in corso di: client/Icons/paesaggio.gif(in = 18962) (out= 18603)(compresso 1%)
    aggiunta in corso di: client/Icons/sole.gif(in = 7063) (out= 6546)(compresso 7%)
    aggiunta in corso di: client/Icons/trap.gif(in = 1062) (out= 1067)(compresso 0%)
    aggiunta in corso di: client/Icons/void.gif(in = 842) (out= 847)(compresso 0%)
    aggiunta in corso di: client/Listener.class(in = 1869) (out= 1136)(compresso 39%)
    aggiunta in corso di: client/Listener.java(in = 2296) (out= 708)(compresso 69%)
    aggiunta in corso di: client/manifesto.txt(in = 62) (out= 58)(compresso 6%)
    aggiunta in corso di: client/ScorciatoieDialog$1.class(in = 740) (out= 391)(compresso 47%)
    aggiunta in corso di: client/ScorciatoieDialog$PopupListener.class(in = 1579) (out= 773)(compresso 51%)
    aggiunta in corso di: client/ScorciatoieDialog.class(in = 3524) (out= 1638)(compresso 53%)
    aggiunta in corso di: client/ScorciatoieDialog.form(in = 8500) (out= 910)(compresso 89%)
    aggiunta in corso di: client/ScorciatoieDialog.java(in = 5676) (out= 1222)(compresso 78%)
    jar umf mainclass.txt client.jar[NOTE: mainclass.txt only contains the line "Main-Class: client.Client"]
    java -jar client.jarFailed to load Main-Class manifest attribute from
    client.jar
    I've also tried to manually create a MANIFEST.MF file that only contained the following lines:
    Manifest Version: 1.0
    Main-Class: client.Client
    guess what was the result?
    java -jar client.jarException in thread "main" java.io.IOException: invalid manifest format
    at java.util.jar.Manifest.read(Manifest.java:193)
    at java.util.jar.Manifest.<init>(Manifest.java:52)
    at java.util.jar.JarFile.getManifest(JarFile.java:158)
    >
    the same procedure with the addition of "Name: client/" before the main-class attribute generated the usual "Failed to load Main-Class manifest attribute" result. So now what?!? I'm getting crazy....

  • Wrap a file into one class

    Hello,
    I want to wrap a file into one classe, how can I do that?
    For example:
    class fileWrapper {
    one buffer for file content(what kind of buffer here?)
    Thanks a lot
    Grace

    The following is not a buffer but I hope it could be of some use.
    import java.io.*;
    public class FileWrapper {
        java.io.File file;
        FileWrapper(java.io.File f) throws java.io.IOException{
           this.file =f;
        FileWrapper(java.lang.String fname) throws java.io.IOException{
          this(new java.io.File(fname));
        // .. next is an example of a method ... You can define other useful methods
        public String readLines() throws java.io.IOException{//read all lines as a String object
           java.io.BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(this.file),"UTF8"));
           StringBuffer buffer = new StringBuffer();
           String temp=null,newLine=System.getProperty("line.separator");
           while((temp=reader.readLine())!=null){
               buffer.append(temp).append(newLine);
           reader.close();
           return String.valueOf(buffer);
    /*public static void main(String[] args) throws java.lang.Exception{
      FileWrapper fw = new FileWrapper("test.txt");
      String str = fw.readLines();
      System.out.println(str);
    }

Maybe you are looking for

  • My MacBook Pro can't find the FireWire port

    My MacBook Pro (OSX 10.6.8) can not find the FireWire port. Until now there hasn't been any problems using the FireWire, but now it just deny any knowledge of it, so to speak. The audio device lights up when I connect it to the MBP (yes, I did connec

  • G3 doesn't recognize drive

    I have an external drive that I used on my G3 but switched it over to my mini when I bought it. I've moved the drive back to the G3 but it doesn't show up on the desktop. System Profiler shows it exists, though. Is there any way I can get it to appea

  • Keyboard shortcut for switching between documents?

    Is there a keyboard shortcut for switching between open documents? That sure would save me a lot of time.

  • Hey...Where go, my audio??

    I completely lost audio output on my Mac about a week ago. I have tried numerous troubleshooting, but to no avail. Granted I am a novice user, my attempts have not been that in depth. What I have checked is: 1) Sound settings in system preferences (o

  • Why do I have so many shared computers listed in finder since upgrading to Yosemite

    Why do I have so many shared computers listed in finder since upgrading to Yosemite? The shared list grows. Why?