Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java UI not running as expected

  • 16-08-2010 2:35pm
    #1
    Registered Users, Registered Users 2 Posts: 576 ✭✭✭


    Hi guys,

    I've run into a problem in Java that is really starting to get me annoyed. There is probably an easy solution to it, but I just can't get it to work.
    I have written a class which extends JFrame. Most of the time the application finishes after the super() call from my classes constructor. However some times the UI loads up as expected. I think there is a race condition happening, but I'm not sure. I have reduced the code to a very simple class:

    [PHP]
    import java.awt.Color;
    import javax.swing.JFrame;

    public class Test extends JFrame
    {
    public Test()
    {
    super("test");
    setBackground(Color.white);
    setSize(200, 200);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pack();
    setVisible(true);
    System.out.println("UI Loaded");
    }
    public static void main(String[] args)
    {
    System.out.println("loading UI");
    Test t = new Test();
    }
    }
    [/PHP]

    Most of the time I run the application it usually prints: "loading UI".
    If I debug the code through Eclipse I get as far as the super() call in the constructor, then the application terminates. However some times it works and prints out "UI Loaded".
    This problem is really frustrating me, any help would be very much appreciated.


Comments

  • Registered Users, Registered Users 2 Posts: 391 ✭✭EoghanConway


    Works fine for me. Doesn't seem to be a problem with the code itself as you're not doing anything odd. If it randomly crashes after calling super I would suspect the problem is somewhere else - perhaps you are compiling the class with an newer version of the jdk and trying to execute on an older jre (with an older swing lib).


  • Registered Users, Registered Users 2 Posts: 576 ✭✭✭pts


    Thanks for looking at it so quickly. It doesn't crash as such, it just terminates normally in, or just after the super() call.

    I think I'm using JavaSE-1.6 for compiling and running. Do you know how I can check these settings in Eclipse?

    EDIT: When it terminates it returns exit value: -1073740791. After a bit of searching I found this post: http://forums.netbeans.org/ntopic14111.html which recommends using the "-J-Dsun.java2d.d3d=false option" option. This didn't work, but "-Dsun.java2d.d3d=false" does. This option seems to fix the issue.


Advertisement