Results 1 to 4 of 4
  1. #1
    yalondg is offline Member
    Join Date
    Jan 2011
    Posts
    20
    Rep Power
    0

    Default JDialog and "adding a window to a container" error

    I am attempting to create a GPA Calculator. After requesting input from the user regarding thier grades, my plan was to have a JDialog pop up and display thier GPA ( Grade Point Average). The program runs fine untill i click on the "Calculate" Button at which point the following error appears on the console:
    Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: adding a window to a container
    at java.awt.Container.checkNotAWindow(Container.java: 431)
    at java.awt.Container.addImpl(Container.java:1039)
    at java.awt.Container.add(Container.java:365)
    at messageBox.<init>(messageBox.java:43)
    at GPACalculatorFrame$1ButtonListener.actionPerformed (GPACalculatorFrame.java:288)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:2028)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2351)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.jav a:6373)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
    at java.awt.Component.processEvent(Component.java:613 8)
    at java.awt.Container.processEvent(Container.java:208 5)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4735)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2143)
    at java.awt.Component.dispatchEvent(Component.java:45 65)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4621)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4282)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4212)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2129)
    at java.awt.Window.dispatchEventImpl(Window.java:2478 )
    at java.awt.Component.dispatchEvent(Component.java:45 65)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.j ava:679)
    at java.awt.EventQueue.access$000(EventQueue.java:85)
    at java.awt.EventQueue$1.run(EventQueue.java:638)
    at java.awt.EventQueue$1.run(EventQueue.java:636)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$2.run(EventQueue.java:652)
    at java.awt.EventQueue$2.run(EventQueue.java:650)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 649)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:188)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)
    The only line in the error that points to my code points to this
    GPACalculator kad = new GPACalculator(lo);
    messageBox message = new messageBox(kad);
    Does anyone know what might be causing this problem and how to fix it

    p.s to my credit if anything doesn't really make sense in this post its probably due to the fact that im exhausted by two nights in a row of nearly no sleep

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: JDialog and "adding a window to a container" error

    Moved from New to Java.

    The error means exactly what the message says: you can't add a top level window to a Container. Since we haven't a clue what's in your GPACalculator and (badly-named*) messageBox classes, we can't shed any more light on the problem than that.

    Why do you even have a custom class for a message box? If it does what its name implies, you should probably be using the static methods of JOptionPane and not reinventing the wheel.

    db

    * Code Conventions for the Java Programming Language: Contents -- class names start with an uppercase letter.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    yalondg is offline Member
    Join Date
    Jan 2011
    Posts
    20
    Rep Power
    0

    Default Re: JDialog and "adding a window to a container" error

    Great suggestions and thank you, solved the problem

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: JDialog and "adding a window to a container" error

    And you will share your solution for the benefit of others who face a similar problem and discover this thread, won't you?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 3
    Last Post: 03-24-2011, 07:18 AM
  2. Replies: 1
    Last Post: 11-20-2009, 08:58 PM
  3. Replies: 1
    Last Post: 10-20-2008, 08:35 AM
  4. Replies: 0
    Last Post: 05-24-2008, 09:51 AM
  5. Replies: 0
    Last Post: 05-24-2008, 09:50 AM

Posting Permissions

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