aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Can JFrame be added 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 "Can JFrame be added to a container?" Watch "Can JFrame be added to a container?" New topic
Author

Can JFrame be added to a container?

Igor Mechnikov
Ranch Hand

Joined: Feb 13, 2011
Posts: 100

Please explain.

Thank you.


String knock = "\u042F \u0418\u0433\u043e\u0440\u044c";
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4465
    
    8

Have you tried it? What happens?
Igor Mechnikov
Ranch Hand

Joined: Feb 13, 2011
Posts: 100

Matthew Brown wrote:Have you tried it? What happens?


Have not tried.
Just wanted to verify an answer from a self-quiz.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
Go through the documentation for Container and see what parameters its add methods take.

And I shall move you to our GUIs forum.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4465
    
    8

Ilya Mechnikov wrote:Have not tried.
Just wanted to verify an answer from a self-quiz.

Well, the easiest, and most reliable, way to verify it is to try it. Try compiling and running the following, see what happens:
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
So, I went into the API and could find nothing in add() which explained that behaviour. There was a link in add() to something else which does explain that behaviour, but I think the documentation could be improved a bit there.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

I think the documentation could be improved

I agree. I also feel it's counter-intuitive that the last component added goes to the bottom, and not the top, of the stacking order.


luck, db
There are no new questions, but there may be new answers.
Igor Mechnikov
Ranch Hand

Joined: Feb 13, 2011
Posts: 100

Matthew Brown wrote:
Ilya Mechnikov wrote:Have not tried.
Just wanted to verify an answer from a self-quiz.

Well, the easiest, and most reliable, way to verify it is to try it. Try compiling and running the following, see what happens:


Thank you much.
I look forward to being able to produce code snippets for testing purposes, until then I must rely on the kindness of strangers.
The code compiled but had runtime errors:
run JFrameInAContainerTest
java.lang.IllegalArgumentException: adding a window to a container
at java.awt.Container.addImpl(Container.java:1061)
at java.awt.Container.add(Container.java:377)
at JFrameInAContainerTest.main(JFrameInAContainerTest.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:271)

Thank you again!

budsy remo
Ranch Hand

Joined: Sep 20, 2008
Posts: 103
what is the explanation to this?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
Have you read my earlier post?
 
Consider Paul's rocket mass heater.
 
subject: Can JFrame be added to a container?