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 frame = new JFrame("Title");
    frame.setSize(wid, hgt);

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


    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.

    hust6, Aug 25, 2005
    1. Advertisements

  2. hust6

    Vova Reznik Guest

    And what is the reason to set parent for JFrame?
    Vova Reznik, Aug 25, 2005
    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"
    hust6, Aug 25, 2005
  4. hust6

    Vova Reznik Guest

    Use JDialog
    Vova Reznik, Aug 25, 2005
  5. Why not make 'the new frame' a (J)Dialog instead?

    It can accept a parent, and also specify modality.
    Andrew Thompson, Aug 25, 2005
  6. 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, Aug 25, 2005
  7. hust6

    hust6 Guest

    Worked! Thanks for the help!

    hust6, Aug 25, 2005
  8. Try
    May be this makes the message scrollable.
    Thomas Fritsch, Aug 25, 2005
  9. hust6

    Joanna Ochoa

    Sep 29, 2015
    Likes Received:
    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
    1. Advertisements

Ask a Question

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.