aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes adding a window to a container Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "adding a window to a container" Watch "adding a window to a container" New topic
Author

adding a window to a container

Pranay Narotam
Greenhorn

Joined: Oct 08, 2008
Posts: 23
Hi all

I have a table screen, and if a user right clicks on a specific row, than a pop up menu will appear, and if a
user chooses an option from the pop up menu, than another screen will appear displaying information relating to
the table row.

This is all working fine. The screen appears and displays the relevant information. However, when the screen appears,
I get an exception telling me "ADDING A WINDOW TO A CONTAINER". And, the whole application freezes.

This is snippets from the code that i am using:




and this is the exception that im getting
Exception occurred during event dispatching:
java.lang.IllegalArgumentException: adding a window to a container
at java.awt.Container.addImpl(Container.java:1010)
at java.awt.Container.add(Container.java:928)
at javax.swing.JFrame.addImpl(JFrame.java:479)
at java.awt.Container.add(Container.java:351)



Thanks
Your help will be greatly appreciated

pranay


I AM A HUMAN BEING
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> This is snippets from the code that i am using:

if you don't know what the problem is, how do you know it's in those snippets?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

What is "TariffBaseLookupProperties" extending? I strongly suspect JFrame because of

Your problem is because of
JFrame is a "top level container" and as such it cannot be "added' to any other container.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Pranay Narotam
Greenhorn

Joined: Oct 08, 2008
Posts: 23
Hi

When I debug through the code the exception comes up by



and sorry if I didn't make it clear. but my problem is that the whole program freezes when
this specific screen is loaded screen is loaded. I do not know why this is happening.

For "TariffBaseLookupProperties" class, I extended JFrame.

Thanks

pranay

Pranay Narotam
Greenhorn

Joined: Oct 08, 2008
Posts: 23
Hi

Thanks Maneesh. It is extending JFrame. So if i shouldn't extend JFrame, than
what should i extend?


Thanks
pranay
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

How about JPanel?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

If it will only be used inside windows, extend JPanel. You can always add that to another JFrame / JDialog if needed.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Pranay Narotam
Greenhorn

Joined: Oct 08, 2008
Posts: 23
Hi

Thanks Rob and Maneesh. It does work, and i no longer get an exception.

But now I discovered another problem.

The screen comes up when you select it from the popup menu. but it is only
focusable when i close the previous window.
I cannot close or do anything to that screen unless the previous screen is closed.
I did use the setFocusable() and setEnabled() methods but I still can't do anything to
the screen.

Any ideas as to why this is happening will be greatly appreciated.

Thanks again for your help to my previous problem.

pranay
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

How about posting your code so we can figure out whats going wrong?
 
Don't get me started about those stupid light bulbs.
 
subject: adding a window to a container