• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can JFrame be added to a container?

 
Igor Mechnikov
Ranch Hand
Posts: 100
Chrome Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please explain.

Thank you.
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried it? What happens?
 
Igor Mechnikov
Ranch Hand
Posts: 100
Chrome Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49380
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4567
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49380
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Igor Mechnikov
Ranch Hand
Posts: 100
Chrome Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the explanation to this?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49380
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read my earlier post?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic