Results 1 to 8 of 8
  1. #1
    Robertito is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default Dynamic trees using Swing

    Hi all,

    This is a Swing question, but as I'm completely new at this, I thought I'd best post here.

    I'm trying to use Swing to create a Dynamic Tree which will access and modify an XML file. I've found what seems to be a great way to get started here: How to Use Trees (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components), but it doesn't work on the web page, or when I download it and run it from the hard drive.

    Is there something obviously wrong with this code, or am I better off looking elsewhere to make this work? If the latter, do you have any suggestions where I could look?

    Thanks for your help.

    Rob

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    it doesn't work on the web page, or when I download it and run it from the hard drive.
    What error are you encountering? The details help others to be able to help you. I could have saved a lot of time if you had posted the errors from attempting to run the jnlp.

    Here's an alternative:
    -- download the file http://download.oracle.com/docs/cd/E...icTreeDemo.jar
    -- In a command prompt, navigate to the folder where you saved the jar and execute "java -cp DynamicTreeDemo.jar DynamicTreeDemo" (without the quotes).

    db

  3. #3
    Robertito is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default

    Thanks for your reply Daryl.

    I should have specified that when I said it didn't work from the hard drive, I meant that it didn't work when I tried to import it into Netbeans. When I followed your instructions it worked fine when executed from the command line.

    Having said that, trying to compile it from the command line using "javac DynamicTreeDemo.jar" (which is what I would have done without your guidance) generated an error. I don't even know how to extract that error from the command prompt easily.

    So, my list of things to learn before I even have a look at this code is:
    - learn more about compiling
    - find a nicer command line tool
    - figure out how to use Netbeans more effectively, or just code by hand

    The good news is that I can do all of this on my own!

    Thanks,

    Rob

  4. #4
    santeron is offline Member
    Join Date
    Apr 2011
    Location
    Athens, Greece
    Posts
    52
    Rep Power
    0

    Default

    to run a .jar file you need to write java -jar DynamicTreeDemo
    check here for more info Running JAR-Packaged Software (The Java™ Tutorials > Deployment > Packaging Programs in JAR Files)

    In my opinion learning about compiling at first won't help you. You just need the basic functions. What troubles do you have with NetBeans?

  5. #5
    Robertito is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default

    In Netbeans I get the below and then nothing happens.

    init:
    deps-jar:
    Compiling 2 source files to G:\call\Resource Team\Projects\LessonPlanEditor\Java\components-DynamicTreeDemoProject\build\classes
    compile:
    run:
    java.lang.NoClassDefFoundError: components/DynamicTreeDemo
    Caused by: java.lang.ClassNotFoundException: components.DynamicTreeDemo
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)
    Could not find the main class: components.DynamicTreeDemo. Program will exit.
    Exception in thread "main" Java Result: 1
    BUILD SUCCESSFUL (total time: 1 second)

    Which is more or less the same as what I get when I use the web start:

    java.lang.ClassNotFoundException: components.DynamicTreeDemo
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
    at com.sun.javaws.Launcher.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

    Don't worry, I'm not going to learn about the ins and outs of compiling, just the basics.

    Also, compiling with java -jar DynamicTreeDemo.jar gives me "Failed to load Main-Class manifest attribute from DynamicTreeDemo.jar".

  6. #6
    santeron is offline Member
    Join Date
    Apr 2011
    Location
    Athens, Greece
    Posts
    52
    Rep Power
    0

    Default

    don't use the .jar at the end of the file.
    Is it the downloaded file db told you or you have write that?

  7. #7
    Robertito is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default

    Hi Santeron,

    It's the Dynamic Tree Demo Project from that website.

    Also, without the .jar at the end of the file, I just get:
    "Unable to access jarfile DynamicTreeDemo"

    Rob

  8. #8
    Robertito is offline Member
    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    Default

    Duh, sorry, just reread your post Santeron. Thought you were referring to Netbeans

    It is the file that db advised me to download. Works when I use
    "java -cp DynamicTreeDemo.jar DynamicTreeDemo", but not when I use "java -jar DynamicTreeDemo" or the variations thereof (ie. incorrectly including the .jar).

    I'm happy to go away and figure out some more intelligent questions to ask. Thanks for your help, though.

Similar Threads

  1. HELP!! Binary trees
    By Get_tanked in forum New To Java
    Replies: 4
    Last Post: 03-24-2011, 06:09 PM
  2. Binary trees
    By girgishf in forum Advanced Java
    Replies: 15
    Last Post: 11-20-2010, 04:29 PM
  3. Need help with Trees...(8-puzzle)
    By ventrue in forum New To Java
    Replies: 2
    Last Post: 03-23-2009, 11:04 PM
  4. Game Trees
    By javaBoy1 in forum Advanced Java
    Replies: 0
    Last Post: 12-27-2008, 12:20 AM
  5. Help With Tournament Trees
    By wiggsfly in forum New To Java
    Replies: 2
    Last Post: 10-26-2008, 09:38 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •