Results 1 to 2 of 2
  1. #1
    maverik_vz is offline Member
    Join Date
    Mar 2009
    Posts
    1
    Rep Power
    0

    Default HELP with jPanels

    Using netbeans I've created new JFrame object with JPanel inside. Now I want to add new Jpanel object and add it to a previous JPanel.
    Something like this:

    Java Code:
    package p;
    public class mainFrame extends javax.swing.JFrame {
         public mainFrame() {
             super("New Frame");
             JPanel panel1 = new JPanel();
             add(panel1);
             panel2 p2=new panel2();
             panel1.add(p2);
             pack();
    }}
    
    public class panel2 extends javax.swing.JPanel {
         public panel2() {
            jLabel2 = new javax.swing.JLabel();
            jLabel1 = new javax.swing.JLabel();
            add(jLabel1);add(jLabel2);
    }}
    
    public class Main  {
    
        public static void main(String[] args) {
               mainFrame M = new mainFrame();
               M.setVisible(true);
    }}
    Of course, the new panel2 won't show in the mainFrame...please help...

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

    Default

    The problem is with your use of layout manager. You should read the Sun Swing tutorial on this subject which you can find here: Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI with JFC/Swing)

Similar Threads

  1. JList and JPanels
    By JetsYanks in forum New To Java
    Replies: 8
    Last Post: 12-25-2009, 02:11 PM
  2. Help with overlapping JPanels
    By xcallmejudasx in forum New To Java
    Replies: 2
    Last Post: 03-09-2009, 10:19 PM
  3. Managing jPanels in jSplitPane
    By calexander in forum Advanced Java
    Replies: 6
    Last Post: 11-13-2008, 07:06 PM
  4. Problems with JPanels and displaying
    By Mastergeek666 in forum AWT / Swing
    Replies: 1
    Last Post: 01-19-2008, 12:32 AM
  5. How to add Images to JPanels?
    By Soda in forum New To Java
    Replies: 3
    Last Post: 12-08-2007, 05:54 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
  •