1

Why is it impossible to add JFrame to a JFrame? It's just adding a Component to a Container. How Java prohibits me from doing so? Yes, I know doing it doesn't make sense, but the point of my question is to understand Swing mechanism - how it works under the hood.

user107986
  • 1,461
  • 1
  • 17
  • 24
  • 1
    JFrame is kind-of desktop window and it´s senseless to embed one inside another. There´re ways, please follow http://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-bad-practice – eduyayo Sep 02 '14 at 11:31
  • 2
    Have you read [*Using Top-Level Containers*](http://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html)? – Catalina Island Sep 02 '14 at 11:52
  • Yes. As I said, I know it's wrong to even think about adding JFrame to JFrame. But they never say why it doesn't work. – user107986 Sep 02 '14 at 11:54
  • 2
    A top level container is a special type of container, which is responsible for making a connection to the native peer, the frame border can also be supplied by the OS...all of which can complicate the process... – MadProgrammer Sep 02 '14 at 12:37
  • Looking for http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html ? – Marco13 Sep 02 '14 at 12:44

2 Answers2

1

JFrame is a top-level container and is therefore compareable to the root element of a XML file. The specification allows only one of them.

DevOli
  • 11
  • 1
  • 1
    **The specification allows only one of them.**. You might like to reword that. You can have multiple completely separate JFrames (although this is not a particularly good idea see [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-bad-practice)) – DavidPostill Sep 02 '14 at 16:29
0

JFrame can add JInternalFrame not same lick JFrame The JFrame class is incompatible with Frame. JInternalFrame is very similar to setting up the GUI for a JFrame. JInternalFrame also provides other API, such as pack, that makes it similar to JFrame.