Results 1 to 12 of 12
  1. #1
    frguy is offline Member
    Join Date
    Jan 2011
    Posts
    5
    Rep Power
    0

    Default Multiple JFrames

    Hello,
    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.

    Thanks, Guy.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default

    See How to use internal frames, which may be what you are looking for

  3. #3
    Jodokus's Avatar
    Jodokus is offline Senior Member
    Join Date
    Jan 2011
    Location
    Amsterdam, the Netherlands
    Posts
    230
    Rep Power
    4

    Default

    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.)

  4. #4
    frguy is offline Member
    Join Date
    Jan 2011
    Posts
    5
    Rep Power
    0

    Default

    Thanks guys.
    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.

    Thanks, Guy.

  5. #5
    Jodokus's Avatar
    Jodokus is offline Senior Member
    Join Date
    Jan 2011
    Location
    Amsterdam, the Netherlands
    Posts
    230
    Rep Power
    4

    Default

    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.

  6. #6
    rdjava's Avatar
    rdjava is offline Member
    Join Date
    Jan 2011
    Posts
    38
    Rep Power
    0

    Default

    Quote Originally Posted by Jodokus View Post
    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

  7. #7
    Jodokus's Avatar
    Jodokus is offline Senior Member
    Join Date
    Jan 2011
    Location
    Amsterdam, the Netherlands
    Posts
    230
    Rep Power
    4

    Default

    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).

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  9. #9
    Jodokus's Avatar
    Jodokus is offline Senior Member
    Join Date
    Jan 2011
    Location
    Amsterdam, the Netherlands
    Posts
    230
    Rep Power
    4

    Default

    Thank you, Fubarable.

  10. #10
    frguy is offline Member
    Join Date
    Jan 2011
    Posts
    5
    Rep Power
    0

    Default

    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.

    thanks, Guy.

  11. #11
    Jodokus's Avatar
    Jodokus is offline Senior Member
    Join Date
    Jan 2011
    Location
    Amsterdam, the Netherlands
    Posts
    230
    Rep Power
    4

    Default

    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.

  12. #12
    frguy is offline Member
    Join Date
    Jan 2011
    Posts
    5
    Rep Power
    0

Similar Threads

  1. Help: passing data from multiple JFrames
    By newicons in forum New To Java
    Replies: 5
    Last Post: 06-26-2010, 03:55 PM
  2. Replies: 4
    Last Post: 11-13-2009, 01:30 PM
  3. help with jframes
    By pao09 in forum AWT / Swing
    Replies: 0
    Last Post: 04-15-2009, 03:10 PM
  4. jframes
    By ddj in forum AWT / Swing
    Replies: 0
    Last Post: 03-24-2009, 04:15 PM
  5. two JFrames
    By kirtesh4u in forum New To Java
    Replies: 0
    Last Post: 11-17-2008, 09:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •