Results 1 to 8 of 8
  1. #1
    Nubkadiya is offline Member
    Join Date
    May 2010
    Posts
    9
    Rep Power
    0

    Default opening a Jframe form in a top of a new form

    i want to add a jframe form to a new Jform to a specific size. is it possible. can someone help me

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default

    Where is the class JForm defined? I don't see it in the JDK API doc.

  3. #3
    Nubkadiya is offline Member
    Join Date
    May 2010
    Posts
    9
    Rep Power
    0

    Default

    JFrame frame = new JFrame();

    JLabel lblimage = new JLabel(new ImageIcon(image));
    lblimage.setVisible(true);
    //

    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(lblimage);
    // // add more components here
    frame.add(mainPanel);
    //
    frame.setSize(300, 500);
    frame.setVisible(true);

    so this image is in my one form. i want to show it in another form. i mean the whole form should display in top of the other form.

    is it possible. can you please guide me

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,556
    Rep Power
    23

    Default

    What do you mean by "form"?
    There are windows that display on a computer's screen and there are JFrame classes that are used in programs that want to display a window.

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default

    Quote Originally Posted by Nubkadiya View Post
    JFrame frame = new JFrame();

    JLabel lblimage = new JLabel(new ImageIcon(image));
    lblimage.setVisible(true);
    //

    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(lblimage);
    // // add more components here
    frame.add(mainPanel);
    //
    frame.setSize(300, 500);
    frame.setVisible(true);

    so this image is in my one form. i want to show it in another form. i mean the whole form should display in top of the other form.

    is it possible. can you please guide me
    You can't put a top level JComponent (e.g. a JFrame) inside another JComponent. Try it, it'll throw an Exception. You have to think of other JComponents and e.g. the CardLayout or a JDesktop component and JInternalFrames ...

    kind regards,

    Jos

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

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    Quote Originally Posted by JosAH View Post
    You can't put a top level JComponent (e.g. a JFrame) inside another JComponent. Try it, it'll throw an Exception. You have to think of other JComponents and e.g. the CardLayout or a JDesktop component and JInternalFrames ...

    kind regards,

    Jos
    Um, JFrame (and JDialog) do not inherit from JComponent, which is the ancestor of all light weight components. Top level windows are (almost by definition) heavy weight.

    The rule is that you cannot add a Window to a Container. The code behind that is found in Component.java line 430 - 432
    Java Code:
            if (comp instanceof Window) {
                throw new IllegalArgumentException("adding a window to a container");
            }
    db

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default

    Quote Originally Posted by Darryl.Burke View Post
    Um, JFrame (and JDialog) do not inherit from JComponent, which is the ancestor of all light weight components. Top level windows are (almost by definition) heavy weight.
    Your right of course; my fingers were thinking for themselves again; bad, fingers! Don't do that again!

    kind regards,

    Jos ;-)

Similar Threads

  1. Replies: 1
    Last Post: 03-22-2010, 09:03 AM
  2. Replies: 0
    Last Post: 10-31-2009, 09:24 AM
  3. Replies: 10
    Last Post: 08-12-2009, 04:02 PM
  4. Replies: 6
    Last Post: 11-28-2008, 06:55 AM
  5. Jtree link to JFrame Form
    By daniel50096230 in forum NetBeans
    Replies: 4
    Last Post: 09-16-2008, 06:53 AM

Tags for this Thread

Posting Permissions

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