Results 1 to 4 of 4
  1. #1
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default IllegalArgumentException: adding a window to a container

    I have made a JFrame called PlayWindow (Class file- PlayWindow)

    This has got a main with some Frame functionality and its got a second panel class inside called ButtonPanel (Class file- PlayWindow)
    This file i can run seperated from the rest.

    In this window with the ButtonPanel i want to add a PlayGround panel called PlayPanel (Class file - PlayPanel)

    In the StartHandler (Class file - StartHandler) i start this as follows:

    Java Code:
    PlayWindow form = new PlayWindow(new PlayPanel(game.getPlayground(), 30, 30, 20, 20));
    This doesn't seem to work, i get an IlligalArgumentException.
    Seperated from eachother it does work. The Playground functionallity does work with this code

    Java Code:
    PlayPanel panel = new PlayPanel(spel.getPlayground(), 30, 30, 20, 20);
    I get the following error:

    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 javax.swing.JLayeredPane.addImpl(JLayeredPane.java :212)
    at java.awt.Container.add(Container.java:927)
    at javax.swing.JRootPane.setContentPane(JRootPane.jav a:608)
    at javax.swing.JFrame.setContentPane(JFrame.java:671)
    at controller.StartHandler.startGame(StartHandler.jav a:67)
    at view.Paneel$StartButtonHandler.actionPerformed(Sta rtForm.java:169)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318)
    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:6267)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
    at java.awt.Component.processEvent(Component.java:603 2)
    at java.awt.Container.processEvent(Container.java:204 1)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4630)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2099)
    at java.awt.Component.dispatchEvent(Component.java:44 60)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4577)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4238)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2478 )
    at java.awt.Component.dispatchEvent(Component.java:44 60)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 599)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)
    BUILD SUCCESSFUL (total time: 4 seconds)

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

    Default

    The error tells you all you need to know to clear up the problem.
    adding a window to a container
    You can't do that.

    db

  3. #3
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    Thanks for the reply. I had figured out myself this won't work.

    But what i want is not so strange.

    1. I have a frame + panel with some buttons, because i need a frame for the buttons.
    2. I have a PlayPanel (drawn Playground)

    This two i want to combine.
    What is the best way to do this?

  4. #4
    aborgeld is offline Senior Member
    Join Date
    Dec 2010
    Location
    The Hague
    Posts
    114
    Rep Power
    0

    Default

    I would think about MDI. Thanks for your zooming in on the error.
    It gave me a little idea.

    If there are any other ideas, your welcome.

    Kind regards,

    André

Similar Threads

  1. Adding multiple components to 1 container index
    By mmcnitt in forum AWT / Swing
    Replies: 3
    Last Post: 03-07-2011, 04:59 PM
  2. Help with adding a Container within a Container
    By JoKeR313 in forum New To Java
    Replies: 4
    Last Post: 01-02-2011, 05:59 AM
  3. How to center a window with Container
    By fernandoj in forum AWT / Swing
    Replies: 5
    Last Post: 05-10-2010, 12:00 AM
  4. proper use of IllegalArgumentException
    By vendetta in forum New To Java
    Replies: 1
    Last Post: 01-16-2010, 08:43 PM
  5. Replies: 3
    Last Post: 04-22-2009, 12:01 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
  •