I'm building an application with JFrame to show the GUI.
I would like to create several classes, so each class will represent a screen in the application (which I'm navigating between them by the Menu-bar). becuase, each of these screens have JFrame components, like - seveal panels, cotainers, etc, I need these classes to extend JFrame.
The problem is when creating an object from one of these classes, it creates a new JFrame window. what I would like to do it to open it in the current JFrame window. I know that I can use the SetVisible, but I dont want to see the window pop-up, I want it to be open in the same frame.
See How to use internal frames, which may be what you are looking for
JFrame is a top-level component, never nested in an other one. JPanel can be nested inside it.
Try to find info on Swing and Layoutmanagers first.
(InternalFrame, the suggestion of doWhile, is possible, but not the point to start with.)
But internal frames will not help me as the entire frame will appear inside the current frame.
Also, using panel is problematic as a screen should contain several panels, so I need something in higher level than the panel.
I would appreciate other suggestions.
Sorry, I've problems assessing the level of your knowledge. Are you lacking knowhow of LayoutManagers, or are you wanting something very special? It's not "normal" to have classes with each their own JFrame, and it's no problem to have a lot of panels within a Frame making proper use of LayOutManagers. So please refrase your problem.
if your going to help someone, be more constructive about it and not criticize them based on what they are asking. No question is a bad one
Originally Posted by Jodokus
It's not my intention to criticize. I really have trouble estimating what the problem is. Maybe my english is nor subtile enough (my native language is dutch) and may seem "unconstructive", but I try to figure out if Guy want's floating panels (solution: internal frames), or panels embedded in a frame (solution: NOT JFrames).
Agrees that Jodokus is asking for clarification, not criticizing, and his questions are valid:
Does the OP want to change the "view" of a GUI in which case swapping JPanels via CardLayout or perhaps JTabbedPane is the way to go, or does he want multiple windows, in which case, usually one window is the primary one and is a JFrame, and the other windows are often dialog windows such as JDialogs. Also, it is often not a good idea to create gui classes that subclass JFrames (unless you're creating a simple example program) as it decreases the flexibility of your code by tying it to the JFrame, but this recommendation as all of our recommendations can change after the OP clarifies his problem at hand.
Thank you all to your answers. Also thanks for your concern.
I do understand your points, and I do familiar and using Layout Manager and swapping panels which is what I'm doing now.
From your answers and from the searches I did over the web, I understand that Java probably can't provide me what I'm trying to do.
But anyway, let me explain my intention as it worth thinking -
I'm building an application based on JFrame. in the application I have several screens and today I got different method to paint each screen. also I got different method to handle different objects exist inside these screens like - "Submit" buttons, Tables, forms, etc. what I want is to build a class or interface name Screen, and use it (by "extends") to build several classes (one for each screen), so I can get the benefits of OOP.
Hello Guy, welcome back ;>)
The way you describe it now is that you're just experimenting with controls: then there's nothing wrongs with JFrames, but they inherently float around. If you want them contained in a frame (your first post) you'd better use CardLayout (probably containing JPanels containing ...) or, better, TabbedPane (as Fubarable suggested). It should be rather straightforward, following the SwingTutorial (The JFC Swing Tutorial).
I don't know if it's very "OOP", but since everything in Java is an object... Ofcourse it is best to divide your code according to MVC from the start. I use an abstract superclass (your Screen) to do double buffering and defining the drawing, but at first I'd stick to simple drawingclasses extending JPanel.
Ok, I understand the situation.