CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 32
  1. #1
    Join Date
    May 2009
    Posts
    115

    GUI .jar problems

    Hi,

    I've been trying to construct a GUI using netbeans. However, today was the 1st time I ran it via the .jar file. The GUI loaded up fine, but the minute I tried to make it load a file and hit next, I got this error:

    Code:
    (Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    The place I got this error is within a Jtextarea where I display the console System output. The irnonic thing is that it does do what its supposed to (loads data into a mySQL table), but it gives me this problem. And I have no idea why.

    Before, it was giving me a slightly different error when I was using setCursor, I erased that part of the code hoping that it was giving the error. But unfortunately not ....
    Despite that output, I am able to go around the other features of my GUI. But the output message in the textarea never gets updated, it stays the same as above. Even though, it should as I perform different functions ...
    Last edited by worldChanger; July 9th, 2009 at 01:41 PM.

  2. #2
    Join Date
    May 2009
    Posts
    115

    Re: GUI .jar problems

    The code that enables my to throw the system console outputs into the Jtextarea:

    Code:
        import java.awt.*;
        import java.io.*;
        import javax.swing.*;
    
        public class SystemConsole extends JFrame {
            PipedInputStream piOut;
            PipedInputStream piErr;
            PipedOutputStream poOut;
            PipedOutputStream poErr;
            JTextArea systemConsole;
    
            public SystemConsole(JTextArea systemOutput ) throws IOException {
    
                systemConsole=systemOutput;
    
                // Set up System.out
                piOut = new PipedInputStream();
                poOut = new PipedOutputStream(piOut);
                System.setOut(new PrintStream(poOut, true));
    
                // Set up System.err
                piErr = new PipedInputStream();
                poErr = new PipedOutputStream(piErr);
                System.setErr(new PrintStream(poErr, true));
               
                // Create reader threads
                new ReaderThread(piOut).start();
                new ReaderThread(piErr).start();
            }
    
            class ReaderThread extends Thread {
                PipedInputStream pi;
    
                ReaderThread(PipedInputStream pi) {
                    this.pi = pi;
                }
    
                public void run() {
                    final byte[] buf = new byte[1024];
                    try {
                        while (true) {
                            final int len = pi.read(buf);
                            if (len == -1) {
                                break;
                            }
                   SwingUtilities.invokeLater(new Runnable() {
                                public void run() {
                                    systemConsole.append(new String(buf, 0, len));
    
                                    // Make sure the last line is always visible
                                    systemConsole.setCaretPosition(systemConsole.getDocument().getLength());
    
                                    // Keep the text area down to a certain character size
                                    int idealSize = 1000;
                                    int maxExcess = 500;
                                    int excess = systemConsole.getDocument().getLength() - idealSize;
                                    if (excess >= maxExcess) {
                                        systemConsole.replaceRange("", 0, excess);
                                    }
                                }
                            });
                        }
                    } catch (IOException e) {
                    }
                }
            }
        }

  3. #3
    Join Date
    Oct 2008
    Posts
    77

    Re: GUI .jar problems

    do you have JARs for libraries you are using, perhaps SwingWorker?

  4. #4
    Join Date
    May 2009
    Posts
    115

    Re: GUI .jar problems

    Hey postmortem,

    I do have a few jars that I use in my lib folder. I created the project via Netbeans so it auto creates a .jar file within the dist folder.

    Dist
    -- .jar file
    -- lib
    ------ JDBC

    However, there isn't a jar for SwingWorker.

    Thanks a lot for your reply! I've been trying various things but nothing seems to work. I'll look into an alternative way of creating my .jar file ....

  5. #5
    Join Date
    May 2009
    Posts
    115

    Re: GUI .jar problems

    2 More Questions :

    Q1 : The TextArea where the output comes seems to be "eating" some of the text, Eg: If it had to say Database user created, it says tabase user created. The code, above is the one that creates the system console within the textarea. I'm not sure what could be going wrong.

    Q2 : When the user presses the "X" button on my Jframe, the application closes. Fair enough. I know it does this because of setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);. However, I want it to perform another function before closing. I want it to save the stuff by calling a fucntion saveSession(). How would, I go about doing this. Would I need to set the setDefaultCloseOperation to Do noting on close and then create my own close method?

  6. #6
    Join Date
    May 2009
    Posts
    115

    Re: GUI .jar problems

    When the file is loading, if I call setCursor and set it to wait. The error msg changes slightly: It becomes:

    Code:
    Button$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    However, when I added SwingWorker 1.2 as an external jar to the project, this is what I get:

    Code:
     java.awt.LightweightDispatcher.processMouseEvent(Unknown Sourc	at java.awt.LightweightDispatcher.processMouseEvent(Unk	a	at java.awt.LightweightDispatcher.processMouseEvent(Unk	a	at java.awt.LightweightDispatcher.processMouseEvent	a	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	a	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

  7. #7
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: GUI .jar problems

    Quote Originally Posted by worldChanger View Post
    Q2 : When the user presses the "X" button on my Jframe, the application closes. Fair enough. I know it does this because of setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);. However, I want it to perform another function before closing. I want it to save the stuff by calling a fucntion saveSession(). How would, I go about doing this. Would I need to set the setDefaultCloseOperation to Do noting on close and then create my own close method?
    Try putting a WindowListener on your frame (e.g. a subclass of WindowAdapter). You can override the windowClosed(..) notification method to do any last-minute stuff.

    Any programming problem can be solved by adding a level of indirection...
    Anon.
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  8. #8
    Join Date
    May 2009
    Posts
    115

    Re: GUI .jar problems

    Hey dlorde - Thanks, that worked perfectly. Any suggestions as to why I'm getting these error msges for my GUI though?

    I've tried almost everthing that I think might have hindered it. I disabled the system output from showing in the textarea, but still no avail. I'm using Cardlayouts for a panel in my GUI. Could this be a problem?

  9. #9
    Join Date
    May 2009
    Posts
    115

    Re: GUI .jar problems

    Based on the msges it seems that I might be missing the library for AWT and Swing, I guess.

    I was searching to download swingall.jar on Google, but unfortunately, I can't find it anywhere to include it into my library path. I however found SwingLayout-1.0.1 at http://www.findjar.com/jar/net.java....1.0.1.jar.html, I included it within my library but it still doesn't work.

    AWT doesn't seem to have any .jar files that I could include in my libraries. I just think that this is probably just a library issue. There's one that I'm not including ... I used the Netbeans GUI Editor to make the GUI ...

    Ah, I'm out of ideas guys ... can anyone give me some ideas? The GUI runs perfectly when I run it as a project in Netbeans ... but acts up when its executed via its .jar file. I haven't moved the jar file. I run it in the same palce where Netbeans creates it.

    Currently the libraries include :
    -swing Worker
    - App Frame work
    - JDBC
    Last edited by worldChanger; July 10th, 2009 at 02:10 PM.

  10. #10
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: GUI .jar problems

    Quote Originally Posted by worldChanger View Post
    There's one that I'm not including ... I used the Netbeans GUI Editor to make the GUI ...
    If you used any non-Swing components, you'll have to include the jar for them. Most of us tend to avoid using GUI builders for anything non-trivial because they generally tie you to a particular IDE by producing a mass of otherwise unmaintainable code.

    If you use a GUI builder, you really ought to find out what it involves - I'm sure there must be Netbeans help files or docs that will tell you what libraries you need. Look for 'How To Deploy GUI Applications' or something similar.

    Computer Science is a science of abstraction -creating the right model for a problem and devising the appropriate mechanizable techniques to solve it...
    A. Aho and J. Ullman
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  11. #11
    Join Date
    May 2009
    Posts
    115

    Re: GUI .jar problems

    Hi dlorde,

    The following JAR files might be needed by your deployed applications:

    swing-layout-1.0.3.jar. This library contains the various layout-related extensions, such as the GroupLayout layout manager. This library is included in version 6 of the Java Platform, so you do not need to package it with your application if you are deploying it to environments that have version 6 of the JRE.

    appframework-1.0.3.jar and swing-worker-1.1.jar. These libraries represent the Swing Application Framework. They are needed if you use the Java Desktop Application template in creating your application. As of JDK 6, the Swing Application Framework is not part of the Java Platform.

    Beans Binding. This library contains support for the beans binding. If your application is created with the Database shell of the Java Desktop Application template or you have used the Bind dialog box in creating your application, your application needs this library. As of JDK 6, the Beans Binding library is not part of the Java Platform.
    That was the information within the help file. I included all these libaries, however the error still remains.

    I tried running the program using ANT based on a friends advice, and surprisingly it runs perfectly fine. So, I just browse to the project folder and type in ant run via command prompt and it works great. That's quite surprising ...

    However, I want to eliminate the use of needing anything other than the .jar file to run. So I'm going to look-up on how I can use ANT to build a stand-alone .jar file. I hope this can be done?

  12. #12
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: GUI .jar problems

    Yes, Ant can build a stand-alone jar file - it's what Netbeans uses to build jars - as you will probably already know, having read the Netbeans help docs on deploying a jar file outside the IDE and managing the classpath. You can even change the Ant script from within Netbeans - see the help docs on customising the Ant script.

    Time is an excellent teacher; but eventually it kills all its students...
    Anon.
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  13. #13
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: GUI .jar problems

    I tried running the program using ANT based on a friends advice, and surprisingly it runs perfectly fine. So, I just browse to the project folder and type in ant run via command prompt and it works great. That's quite surprising ...
    Presumably the ant build file has a target called 'run' that is setting the classpath to the correct values when starting the jar.

    If you find the ant build file (probably called build.xml) and look at the target called 'run' you will be able to see what the classpath settings are. You need to take these settings and add them to the manifest file used when building the jar. They will need to be on a line starting 'Class-Path:' and ending with a newline.

    I'm not a Netbeans expert but I believe you can do all this from within NetBeans. Check the help system for creating your own manifest files.

  14. #14
    Join Date
    May 2009
    Posts
    115

    Re: GUI .jar problems

    Yes, Ant can build a stand-alone jar file - it's what Netbeans uses to build jars - as you will probably already know, having read the Netbeans help docs on deploying a jar file outside the IDE and managing the classpath. You can even change the Ant script from within Netbeans - see the help docs on customising the Ant script.
    Thanks dlorde, will read up on this ASAP.


    Presumably the ant build file has a target called 'run' that is setting the classpath to the correct values when starting the jar.

    If you find the ant build file (probably called build.xml) and look at the target called 'run' you will be able to see what the classpath settings are. You need to take these settings and add them to the manifest file used when building the jar. They will need to be on a line starting 'Class-Path:' and ending with a newline.

    I'm not a Netbeans expert but I believe you can do all this from within NetBeans. Check the help system for creating your own manifest files.
    Hey Keang - Few things I noticed:

    *When, I do ant run. It automatically deletes a folder created by netbeans called dist that has the standalone .jar file as well as lib folder that contain the required libraries
    *The build.xml folder doesn't seem to have any relevant code its entirely full of comments. However, it imports a file called build-impl.xml that has uncommented code. This looked relevant to me, but it doesn't list the path to the class-path ... or maybe I'm blind!
    Code:
      ====================
                    JAR BUILDING SECTION
                    ====================
                
      --> 
    - <target depends="init" name="-pre-pre-jar">
      <dirname file="${dist.jar}" property="dist.jar.dir" /> 
      <mkdir dir="${dist.jar.dir}" /> 
      </target>
    - <target name="-pre-jar">
    - <!--  Empty placeholder for easier customization. 
      --> 
    - <!--  You can override this target in the ../build.xml file. 
      --> 
      </target>
    - <target depends="init,compile,-pre-pre-jar,-pre-jar" name="-do-jar-without-manifest" unless="manifest.available">
      <j2seproject1:jar /> 
      </target>
    - <target depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available" name="-do-jar-with-manifest" unless="manifest.available+main.class">
      <j2seproject1:jar manifest="${manifest.file}" /> 
      </target>
    - <target depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class" name="-do-jar-with-mainclass" unless="manifest.available+main.class+mkdist.available">
    - <j2seproject1:jar manifest="${manifest.file}">
    - <j2seproject1:manifest>
      <j2seproject1:attribute name="Main-Class" value="${main.class}" /> 
      </j2seproject1:manifest>
      </j2seproject1:jar>
      <echo>To run this application from the command line without Ant, try:</echo> 
      <property location="${build.classes.dir}" name="build.classes.dir.resolved" /> 
      <property location="${dist.jar}" name="dist.jar.resolved" /> 
    - <pathconvert property="run.classpath.with.dist.jar">
      <path path="${run.classpath}" /> 
      <map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}" /> 
      </pathconvert>
      <echo>${platform.java} -cp "${run.classpath.with.dist.jar}" ${main.class}</echo> 
      </target>
    - <target depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class+mkdist.available" name="-do-jar-with-libraries">
      <property location="${build.classes.dir}" name="build.classes.dir.resolved" /> 
    - <pathconvert property="run.classpath.without.build.classes.dir">
      <path path="${run.classpath}" /> 
      <map from="${build.classes.dir.resolved}" to="" /> 
      </pathconvert>
    - <pathconvert pathsep="" property="jar.classpath">
      <path path="${run.classpath.without.build.classes.dir}" /> 
    - <chainedmapper>
      <flattenmapper /> 
      <globmapper from="*" to="lib/*" /> 
      </chainedmapper>
      </pathconvert>
      <taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs" /> 
    - <copylibs compress="${jar.compress}" jarfile="${dist.jar}" manifest="${manifest.file}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
      <fileset dir="${build.classes.dir}" /> 
    - <manifest>
      <attribute name="Main-Class" value="${main.class}" /> 
      <attribute name="Class-Path" value="${jar.classpath}" /> 
      </manifest>
      </copylibs>
      <echo>To run this application from the command line without Ant, try:</echo> 
      <property location="${dist.jar}" name="dist.jar.resolved" /> 
      <echo>${platform.java} -jar "${dist.jar.resolved}"</echo> 
      </target>
    - <target name="-post-jar">
    - <!--  Empty placeholder for easier customization. 
      --> 
    - <!--  You can override this target in the ../build.xml file. 
      --> 
      </target>
      <target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-post-jar" description="Build JAR." name="jar" />
    *Oh and Netbeans creates its own Manifest file with the project but all its contents include are:
    Code:
    Manifest-Version: 1.0
    X-COMMENT: Main-Class will be added automatically by build
    -----

    Thanks A LOT for your replies guys, I'm going to do some more reading up on this and hope to solve this problem. I was extremely relieved to realize that ANT works at least, which probably means the project is okay.

  15. #15
    Join Date
    Oct 2008
    Posts
    77

    Re: GUI .jar problems

    are you running java 6 or 5? netbeans has option to create swing layout extensions as java 6 code or import from swing layout.

    Note: If you create your application using JDK 6 but you need the application to also run on Java SE 5, you can have the IDE generate its code to use the Swing Layout Extensions library instead of the classes in Java SE 6. Open the ContactEditorUI class in the GUI Editor. In the Inspector, expand the ContactEditorUI node and choose Form ContactEditorUI. In the Properties window, change the value of the Layout Generation Style property to Swing Layout Extensions Library.
    http://www.netbeans.org/kb/60/java/quickstart-gui.html

Page 1 of 3 123 LastLast

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured