Results 1 to 2 of 2
  1. #1
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Question Trouble adding JPanel to JFrame with NetBeans IDE

    Hi, I've designed some JFrame forms in netbeans which I intended to add to the main JFrame. Then I realised thats not possible so I created a new JPanel form and then copy+pasted the contents and source code of the minor JFrame form to the JPanel form.

    Now I need to add the JPanel form to the main JFrame but whatever I've tried won't get the JPanel to display... Please tell me what I am doing wrong?

    I tried this way:
    //productsPanel is a JPanel in the main JFrame
    productsPanel.add(new ProductsViewer());

    I also tried this:
    ProductsViewer myProductsViewer = new ProductsViewer();
    productsPanel.add(myProductsViewer);
    myProductsViewer.setVisible(true);


    And I also tried to use these two methods after adding the JPanel to the JFrame:
    productsPanel.validate();
    productsPanel.repaint();


    Nothing seems to get this JPanel to show.

    Please help!!

    Thanks

  2. #2
    JavaForums's Avatar
    JavaForums is offline Administrator
    Join Date
    Dec 2006
    Posts
    876
    Rep Power
    10

    Default

    You seem to do it in reverse. You need to add JPanel to JFrame like this:

    Java Code:
    myProductsViewer.add(productsPanel);
    myProductsViewer.setVisible(true);

Similar Threads

  1. Adding JButton to JPanel
    By razmyasdfg in forum AWT / Swing
    Replies: 8
    Last Post: 05-24-2011, 12:03 AM
  2. Adding a jpanel to a customized Jpanel Class
    By trishtren in forum AWT / Swing
    Replies: 7
    Last Post: 04-05-2011, 07:52 PM
  3. Adding Jpanel ontop of another Jpanel
    By Manfizy in forum AWT / Swing
    Replies: 4
    Last Post: 03-05-2011, 11:34 PM
  4. adding integer to the JPanel
    By navid in forum New To Java
    Replies: 2
    Last Post: 12-18-2010, 05:26 PM
  5. I am having trouble with scrollbars in netbeans 5.5.1
    By ineedhelp in forum New To Java
    Replies: 2
    Last Post: 03-13-2009, 07:56 PM

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
  •