Setting the parent frame of a JFrame

Discussion in 'Java' started by hust6, Aug 25, 2005.

  1. hust6

    hust6 Guest

    Is it possible to set the parent compenent of a JFrame to another
    JFrame? Here is a sample of my code:

    JScrollPane scrollPane = new JScrollPane()

    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame("Title");
    frame.getContentPane().add(scrollPane);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setSize(wid, hgt);
    frame.setVisible(true);
    frame.toFront();

    This is how I want the frame to be, but I can't set the parent frame.
    I tried adding:

    JOptionPane.showMessageDialog(MyParentJFrame,frame.getContentPane());

    as the last line. This set the parent component to the other JFrame,
    but I lost the ability to have my message be scrollable.

    Any help would be greatly appreciate.

    Thanks!
     
    hust6, Aug 25, 2005
    #1
    1. Advertisements

  2. hust6

    Vova Reznik Guest

    hust6 wrote:
    >


    And what is the reason to set parent for JFrame?
     
    Vova Reznik, Aug 25, 2005
    #2
    1. Advertisements

  3. hust6

    hust6 Guest

    The new frame is an error message as a result of something that
    happened in the parent frame, so we would like them to be "tied"
    together.
     
    hust6, Aug 25, 2005
    #3
  4. hust6

    Vova Reznik Guest

    hust6 wrote:
    > The new frame is an error message as a result of something that
    > happened in the parent frame, so we would like them to be "tied"
    > together.
    >

    Use JDialog
     
    Vova Reznik, Aug 25, 2005
    #4
  5. On 25 Aug 2005 07:19:14 -0700, hust6 wrote:

    > The new frame is an error message as a result of something that
    > happened in the parent frame, so we would like them to be "tied"
    > together.


    Why not make 'the new frame' a (J)Dialog instead?

    It can accept a parent, and also specify modality.

    --
    Andrew Thompson
    physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
    "If you don't love me baby, you better act like you do.."
    Screamin' Jay Hawkins 'I Need You'
     
    Andrew Thompson, Aug 25, 2005
    #5
  6. hust6 wrote:
    > The new frame is an error message as a result of something that
    > happened in the parent frame, so we would like them to be "tied"
    > together.
    >

    A Frame (or JFrame) has *no* parent, by definition. What you describe,
    is called Window, which *must* always have a parent. You probably want
    one of its subclasses (JWindow, JDialog).
    However, the most convenient way for popping up a simple error message
    is JOptionPane.showMessageDialog, which creates a modal JDialog
    (including OK-button, error icon) with minimum effort on your side.

    --
    "Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
     
    Thomas Fritsch, Aug 25, 2005
    #6
  7. hust6

    hust6 Guest

    Worked! Thanks for the help!

    Matt
     
    hust6, Aug 25, 2005
    #7
  8. hust6 wrote:
    > Is it possible to set the parent compenent of a JFrame to another
    > JFrame? Here is a sample of my code:
    >
    > JScrollPane scrollPane = new JScrollPane()
    >
    > JFrame.setDefaultLookAndFeelDecorated(true);
    > JFrame frame = new JFrame("Title");
    > frame.getContentPane().add(scrollPane);
    > frame.pack();
    > frame.setLocationRelativeTo(null);
    > frame.setSize(wid, hgt);
    > frame.setVisible(true);
    > frame.toFront();
    >
    > This is how I want the frame to be, but I can't set the parent frame.
    > I tried adding:
    >
    > JOptionPane.showMessageDialog(MyParentJFrame,frame.getContentPane());
    >
    > as the last line. This set the parent component to the other JFrame,
    > but I lost the ability to have my message be scrollable.

    Try
    JOptionPane.showMessageDialog(MyParentJFrame,scrollPane);
    May be this makes the message scrollable.

    >
    > Any help would be greatly appreciate.
    >
    > Thanks!
    >



    --
    "Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
     
    Thomas Fritsch, Aug 25, 2005
    #8
  9. hust6

    Joanna Ochoa

    Joined:
    Sep 29, 2015
    Messages:
    1
    Likes Received:
    0
    Hi, I had the same problem and this worked: setDefaultCloseOperation(HIDE_ON_CLOSE); (On the "child" JFrame )
    I hope it would be usefull.
     
    Joanna Ochoa, Sep 29, 2015
    #9
    1. Advertisements

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Roedy Green
    Replies:
    0
    Views:
    3,486
    Roedy Green
    Jul 30, 2003
  2. Scott Steiner

    Setting background colour of JFrame

    Scott Steiner, May 5, 2005, in forum: Java
    Replies:
    1
    Views:
    27,032
    Roland
    May 5, 2005
  3. azsx
    Replies:
    2
    Views:
    1,352
  4. jakester
    Replies:
    3
    Views:
    2,262
    jakester
    Apr 3, 2007
  5. A Watcher

    Help on setting size of JFrame?

    A Watcher, Feb 22, 2008, in forum: Java
    Replies:
    5
    Views:
    27,722
    thenerdwonder
    Feb 23, 2008
  6. bernd
    Replies:
    0
    Views:
    767
    bernd
    Aug 3, 2008
  7. Stuart Wexler

    Preselecting from parent frame to child frame

    Stuart Wexler, Apr 23, 2004, in forum: Javascript
    Replies:
    1
    Views:
    369
    Mick White
    Apr 23, 2004
  8. Replies:
    2
    Views:
    821
    markspace
    Aug 27, 2012
Loading...