Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: JFrame + JPanel design question

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    22
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default JFrame + JPanel design question

    I'm creating a game. So far, I have a Login frame that pops up and requests user name and password. It then verifies with a MySQL database and if the correct information is entered the Login window closes and a new chat lobby frame pops up. All of that is working great.

    Now I want to design my Chat Lobby. I'm having trouble with all the tutorials and documentation online concerning jPanels and Layout Managers.

    I've included an image of what I want the base layout of my frame to be.

    Panel 1 - I want this panel to be resizeable horizontally, but fixed to ~100 pixels vertically. This panel will include a couple jLabels.

    Panel 2 - I want this panel to be resizeable vertically, but fixed to ~100 pixels 150 pixels horizontally. This panel will include a jLabel at the top and a jScrollPane with the names of people logged into the chat room.

    Panel 3 - I want this panel to be resizeable both horizontally and vertically. This panel will include a jTextArea for all the chat.

    Panel 4 - I want this panel to be resizeable horizontally, but fixed to ~100 pixels vertically. This panel will include a couple jLabels, maybe a jButton or two and a jTextField for the user's chat.

    Panel 5 - I want this panel to be fixed to ~200 pixels vertically and ~150 pixels horizontally. This panel will include a jLabel and a few jButtons.

    The plan is, if I can set everything up right, jPanels 1, 3 and 4 will be the same width as each other at all times, but the width will change based on the width of the frame. jPanels 1 and 4 will be fixed vertically, but not horizontally. jPanels 2 and 5 will be fixed at a specific width no matter what the frame size is.

    I'm having trouble with jPanels. When I put a jPanel inside of another jPanel, nothing shows up correctly.

    I considered putting jPanels 1, 3 and 4 within a leftSidePanel... and jPanels 2 and 5 within a rightSidePanel. Then putting the leftSidePanel and rightSidePanel inside an overallPanel.

    Am I doing something wrong? Is this a bad way to set up my frame, panels and the components within them?

    Is it ok to put panels inside of panels?
    Attached Images Attached Images


  2. #2
    Junior Member
    Join Date
    Nov 2013
    Posts
    22
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: JFrame + JPanel design question

    I'm still stuck on this and can't figure out what I'm doing wrong. I've been coding and reading and experimenting for almost 24 hours on this one.

    When the frame pops up, everything is in the perfect position. I have the frame set so that it can't be made any smaller, but I want to allow the frame size to be increased and/or maximized. That's where I'm encountering the problems. The panels aren't increasing the

    The left 3 panels (red, white, blue) are enclosed in the pink panel. They are acting exactly the way I want them vertically, but their size is fixed horizontally for some reason. When I increase the height of the window/frame, it's doing what I want. When I make the window/frame wider, the left panels don't increase their width, which is what I want them to do.

    The right two panels (green, yellow) are enclosed in the gray panel. I have the right panels fixed horizontally, which is what I want, but the top right panel (green) isn't resizing vertically when I increase the frame/window height.

    Here's what I have so far. I tried using something other than setPreferredSize, but setMinimumSize, setMaximumSize, etc just make it worse. I can't figure it out and this is the closest I've got. Am I using the wrong Layout Manager? I've tried a few of them, but this is the one that makes sense to me based on what 'm trying to do.

    import java.awt.*;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Toolkit;
    import javax.swing.BorderFactory;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
     
    public class ChatRoomBuild {
     
        JPanel mainPanel = new JPanel();
        JFrame frame = new JFrame("Welcome to Chat");
        JPanel leftPanel = new JPanel();
        JPanel rightPanel = new JPanel();
        JPanel topLeftPanel = new JPanel();
        JPanel topRightPanel = new JPanel();
        JPanel centerLeftPanel = new JPanel();
        JPanel bottomLeftPanel = new JPanel();
        JPanel bottomRightPanel = new JPanel();
     
        public ChatRoomBuild()
        {
                Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                //frame.setSize(screenSize);
                //frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                //frame.setSize(800,600);
                frame.setMinimumSize(new Dimension (1010,600));
                frame.setVisible(true);    // FIRST visible = true
                frame.setResizable(true); // THEN  resizable = true
     
                topLeftPanel.setLayout(new BorderLayout());
                topRightPanel.setLayout(new BorderLayout());
                centerLeftPanel.setLayout(new BorderLayout());
                bottomLeftPanel.setLayout(new BorderLayout());
                bottomRightPanel.setLayout(new BorderLayout());
     
                leftPanel.setLayout(new BorderLayout());
                leftPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
     
                rightPanel.setLayout(new BorderLayout());
                rightPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
     
                mainPanel.setBackground(Color.black);
                topLeftPanel.setBackground(Color.red);
                topRightPanel.setBackground(Color.green);
                centerLeftPanel.setBackground(Color.white);
                bottomLeftPanel.setBackground(Color.blue);
                bottomRightPanel.setBackground(Color.yellow);
                leftPanel.setBackground(Color.PINK);
                rightPanel.setBackground(Color.LIGHT_GRAY);
     
                leftPanel.add(topLeftPanel, BorderLayout.NORTH);
                rightPanel.add(topRightPanel, BorderLayout.NORTH);
                leftPanel.add(centerLeftPanel, BorderLayout.CENTER);
                leftPanel.add(bottomLeftPanel, BorderLayout.SOUTH);
                rightPanel.add(bottomRightPanel, BorderLayout.SOUTH);
     
                mainPanel.setLayout(new BorderLayout());
                mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
     
                mainPanel.add(leftPanel, BorderLayout.WEST);
                mainPanel.add(rightPanel, BorderLayout.EAST);
     
                frame.add(mainPanel);
     
                topLeftPanel.setPreferredSize(new Dimension (798,100));
                topRightPanel.setPreferredSize(new Dimension (180,395));
                //centerLeftPanel.setPreferredSize(new Dimension (798,100));
                bottomLeftPanel.setPreferredSize(new Dimension (798,100));
                bottomRightPanel.setPreferredSize(new Dimension (180,140));
                leftPanel.setPreferredSize(new Dimension (798,100));
                rightPanel.setPreferredSize(new Dimension (180,10));
     
        }
     
        public static void main(String[] args) 
        {
            new ChatRoomBuild();
        }
     
    }

  3. #3
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: JFrame + JPanel design question

    BorderLayout doesn't quiet fit your requirements. A combination of layouts will be more appropriate. Here is something I hashed out quickly using three BoxLayouts; one for the left, one for the right and one to hold the left and right. You will have to tweak things to get it resizing correctly but this should put you on the right path.

    You may want to look into GridBagLayout's because you can assign weights to the components x & y using GridBagConstraints. It'll make the resizing a little more intuitive.


    import java.awt.*;
     
    import javax.swing.BorderFactory;
    import javax.swing.BoxLayout;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
     
    public class ChatRoomJFrame extends JFrame {
     
     
    	JPanel leftPanel;
    	JPanel leftTop;
    	JPanel leftCenter;
    	JPanel leftBottom;
    	JPanel rightTop;
    	JPanel rightBottom;
    	JPanel rightPanel;
     
        public ChatRoomJFrame(String title)
        {
        	super(title);
        	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        	setSize(1010,600);
        	setMinimumSize(new Dimension (1010,600));
        	setVisible(true);   
        	setResizable(true);
        }
     
        public void addComponentsToPane(final Container pane) 
        {
     
        	leftPanel = new JPanel();  //Contains all panels on the left
        	leftTop = new JPanel();
        	leftCenter = new JPanel();
        	leftBottom = new JPanel();
     
        	rightPanel = new JPanel();  //Contains all panels on the right
        	rightTop = new JPanel();
        	rightBottom = new JPanel();
     
        	leftPanel.setBackground(Color.black);
        	leftTop.setBackground(Color.PINK);
        	leftCenter.setBackground(Color.white);
        	leftBottom.setBackground(Color.blue);
        	rightTop.setBackground(Color.green);
        	rightBottom.setBackground(Color.yellow);
     
        	leftPanel.setMinimumSize(new Dimension (800, 500));
        	leftPanel.setPreferredSize(new Dimension (800, 500));
        	leftTop.setMinimumSize(new Dimension (798,100));
        	leftTop.setMaximumSize(new Dimension (798,100));
        	leftTop.setPreferredSize(new Dimension (798,100));
        	leftCenter.setMinimumSize(new Dimension (768, 300));
        	leftCenter.setPreferredSize(new Dimension (768, 300));
        	leftBottom.setMinimumSize(new Dimension (798,100));
        	leftBottom.setMaximumSize(new Dimension (798,100));
        	leftBottom.setPreferredSize(new Dimension (798,100));
        	rightBottom.setMaximumSize(new Dimension (180,140));
        	rightBottom.setMinimumSize(new Dimension (180,140));
        	rightBottom.setPreferredSize(new Dimension (180,140));
     
     
        	leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS));
        	leftPanel.add(leftTop);
        	leftPanel.add(leftCenter);
        	leftPanel.add(leftBottom);
     
        	rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.PAGE_AXIS));
        	rightPanel.add(rightTop);
        	rightPanel.add(rightBottom);
     
        	JPanel rootPanel = new JPanel();
        	rootPanel.setLayout(new BoxLayout(rootPanel, BoxLayout.LINE_AXIS));
        	rootPanel.add(leftPanel);
        	rootPanel.add(rightPanel);
     
        	pane.add(rootPanel);
        }
     
     
        private static void createAndShowGUI() {
     
        	ChatRoomJFrame frame = new ChatRoomJFrame("Welcome to Chat");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.addComponentsToPane(frame.getContentPane());
            frame.pack();
            frame.setVisible(true);
        }
     
        public static void main(String[] args) 
        {
        	 javax.swing.SwingUtilities.invokeLater(new Runnable() {
                 public void run() {
                     createAndShowGUI();
                 }
             });
        }
     
    }

  4. The Following User Says Thank You to ChristopherLowe For This Useful Post:

    Psyclone625 (November 6th, 2013)

  5. #4
    Junior Member
    Join Date
    Nov 2013
    Posts
    22
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: JFrame + JPanel design question

    Thanks! I KINDA got it to work by cheating before I saw this, but didn't truly understand what I was doing becuase I used NetBeans 'drag & drop' to lay everything out. I only did it because I was desperate, but I was trying to avoid that because really want to build it via code so I can learn. This is exactly what I need.

    Thanks!

    Out of curiosity, what does the following code do exactly?

    javax.swing.SwingUtilities.invokeLater(new Runnable() {
                 public void run() {
                     createAndShowGUI();
                 }
             });

    I see NetBeans use it all the time when it creates a JFrame. I've been trying to do the coding by myself and in my main of my initial class that I run prior to calling this JFrame. I've just been using...

    new ChatRoomJFrame();
     
    or
     
    ChatRoomJFrame frame = new ChatRoomJFrame("Welcome to Chat");

    ...to call the constructor or other methods. Usually, in the constructor I would do something like call the createAndShowGUI() method. Everything seems to work fine when I do it that way, which is the way it was done in a majority of the tutorials I tried, but most of the tutorials are very small snippets.

    I'm curious because I'm actually using another JFrame (Login.java) with a UserName and Password JTextBox to have users log in. When they click OK, it checks the MySQL database table to verify the username and password is correct. This is all working great. If the username and password exist and are correct, that frame is closing and opening this ChatRoomJFrame (ChatRoom.java) and passing in their userIDNumber and userName. All of that is getting passed in correctly as well; however, I don't have a main method in this new class. My constructor for the ChatRoomJFrame looks like this...

        public ChatRoomJFrame (int userID, String userName) {
            initComponents();
            setVisible(true);
        }

    The second frame pops up and is populated with everything, including the userID and userName I passed in from my Login frame when I called this object. I don't have anything in my code that resembles "javax.swing.SwingUtilities.invokeLater(new Runnable() { ..." similar to what is in that main method you used and which I keep seeing in NetBeans. Is that ok?

  6. #5
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: JFrame + JPanel design question

    I used NetBeans 'drag & drop' to lay everything out.
    Netbeans auto-generate's the graphical interface, similarly but not as clearly or robustly as Visual Studio does. The issue with it is later on when you want to modify the view it will be a real nightmare of tangled, autogen'd code. I'm not disagreeing with the decision because as you know, layouts can be really confusing but just be aware it may bite you later down the track.

    Out of curiosity, what does the following code do exactly?
    Swing/AWT GUI's run of a separate thread called the Event Dispatching Thread. It's what stops the GUI from hanging while the main thread is under load. Just copy and paste this snippet when the main method to creates a GUI.


    I'm curious because I'm actually using another JFrame .... All of that is getting passed in correctly as well; however, I don't have a main method in this new class. My constructor for the ChatRoomJFrame looks like this...
    That's fine. You will only have one public static void main(String[] args) function in your program because it only has the one entry point. Just pass the parameters to the constructor as you are doing.

  7. The Following User Says Thank You to ChristopherLowe For This Useful Post:

    Psyclone625 (November 6th, 2013)

  8. #6
    Junior Member
    Join Date
    Nov 2013
    Posts
    22
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: JFrame + JPanel design question

    Thanks... I'm trying not to use Netbeans auto-generating graphical interface for that exact reason and trying to write all the code by hand. I tried learning Java a couple years ago and used Netbeans and ran into that problem after my code got pretty big. I ran into the exact problems you're talking about and ended up setting my project aside after I had spent about 4 months on it because it was just a big mess and I had too much trouble trouble-shooting everything. After a couple years, I'm now starting over from scratch, but have a much firmer grasp on Java since I'm not a 100% beginner. That was my first introduction to OOP and I was kinda lost. Now I clearly understand it a lot better and the coding is 10x easier this time around.

    Will Visual Studio eliminate that issue? or will it just be to a lesser extent?

  9. #7
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: JFrame + JPanel design question

    Will Visual Studio eliminate that issue? or will it just be to a lesser extent?
    Since your code clearly illustrates intermediate level I would strongly recommend branching off into other languages. C# .NET is very powerful so it's worth being familiar with at the least. As to your question, the .NET IDE and framework were designed together with a drag and drop GUI builder at it's heart whereas Netbeans needs to work against a lot of Swings design philosophies to achieve drag and drop GUI's. So yes, .NET GUI's won't get as tangled up as Netbeans does but that isn't to say it will be a walk in the park. I came from a Java background and have run into all sorts of problems with .NET that make me wish I was using Java.

    My rule of thumb is .NET for quick, easy Windows apps and Java for technical, experimental, mobile or R&D. Just my opinion on the subject, all coders will have one and none are correct for everyone.

  10. The Following User Says Thank You to ChristopherLowe For This Useful Post:

    Psyclone625 (November 6th, 2013)

  11. #8
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: JFrame + JPanel design question

    I've never been a fan of the auto-gen gui builders. I've also never really been a fan of java's available layout managers, so I created my own. SpringLayout is by far the most flexible layout manager java has to offer, but it is a nightmare to try to manually code with, so I just leveraged it and wrote a handful of helper methods. It's far from perfect, and has plenty of drawbacks which I could probably fix if I cared enough, but it gets the job done.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  12. The Following User Says Thank You to aussiemcgr For This Useful Post:

    Psyclone625 (November 6th, 2013)

  13. #9
    Junior Member
    Join Date
    Nov 2013
    Posts
    22
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: JFrame + JPanel design question

    Thanks for the responses ChristopherLowe and aussiemcgr.

    Based on your insight and suggestions, I think I'm just going to keep plugging away without the auto-gen gui builders and stick with java for now. I clearly still have a lot to learn and the gui-builders sound like they're just going to cause me trouble down the road.

    I've got my login frame and chat frame up and running, although the chat frame isn't exactly the way I want it yet. I wanted to get both of those up before I start my next adventure... networking. This is the part that really stumped me last time because I built the chatroom, and a huge portion of my game, then tried to network it afterwards. This time through, I'm going to build them both together. I just wanted to get a simple chat room up and running so I had something to begin testing with that was going to remain part of my program.

    Again, thanks for all the input and quick responses!!!

  14. #10
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: JFrame + JPanel design question

    I would suggest a modular approach by building the GUI part of the program and the networking part of the program separately, and then wiring the networking part into the GUI. The reason I suggest that is: if the network is separate from the GUI, it allows you to test the network part of your program without relying on your GUI being 100% functional. Also, you would be able to create a test class with several hard-coded cases which you can run to test your network part, instead of having the manually enter everything through the GUI during each test.
    After you know your GUI operates as it should, and you know your network part operates as it should, you can wire them together and test the entire product. This should yield less bugs in the end, as most of the more complex issues should have been solved when you tested each part individually.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  15. The Following User Says Thank You to aussiemcgr For This Useful Post:

    Psyclone625 (November 13th, 2013)

  16. #11
    Junior Member
    Join Date
    Nov 2013
    Posts
    22
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Re: JFrame + JPanel design question

    Thanks aussie. That's my plan with the networking.

    As for my initial question, thanks to the help from this forum, I was able to get the panels to operate the way I wanted using BorderLayout.

    ChatLobby.jpg

    I created a mainPanel, which contained a leftPanel and rightPanel. The leftPanel had more 3 panels within it and the rightPanel had two additional panels within it.

    The structure was something like this...

    Main Panel
    • Left Panel (BordarL
      • jpanel1
      • jpanel2
      • jpanel3
    • Right Panel
    • jpanel4
    • jpanel5


    Here's the code...

    package sqlconnect;
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Frame;
    import javax.swing.*;
    import javax.swing.border.EmptyBorder;
     
    public class Panels extends JFrame
    {
            JPanel panelRoot            = new JPanel();
     
            JPanel panelLeftMain        = new JPanel();
            JPanel panelRightMain       = new JPanel();
     
            JPanel panelLeftTop         = new JPanel();
            JPanel panelLeftCenter      = new JPanel();
            JPanel panelLeftBottom      = new JPanel();
     
            JPanel panelRightTop        = new JPanel();
            JPanel panelRightBottom     = new JPanel();
     
            JLabel labelTemp1           = new JLabel("panelLeftTop");
            JLabel labelTemp2           = new JLabel("panelLeftCenter");
            JLabel labelTemp3           = new JLabel("panelLeftBottom");
            JLabel labelTemp4           = new JLabel("panelRightTop");
            JLabel labelTemp5           = new JLabel("panelRightBottom");
     
    //--------------------------------------------------------------------------------------------------------------------------------        
     
            public Panels()
            {
     
                    buildChatFrame();                                               // Create the frame, position it and handle closing it
     
            }
     
    //--------------------------------------------------------------------------------------------------------------------------------        
     
            public void buildChatFrame()
            {
                    this.setSize(1000,700);                                         // Set frame size
                    this.setMinimumSize(new Dimension(1000,700));                   // Set minimum frame size
                    this.setLocationRelativeTo(null);                               
                    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    this.setTitle("Welcome to...");
     
                    this.setExtendedState(Frame.MAXIMIZED_BOTH);                    // Maximize window
                    //this.setUndecorated(true);                                    // True full screen, no X button in top right.  Add exit button to dispose/exit
     
                    panelRoot.setLayout(new BorderLayout());                        // Set border between other sub-panel components, but not parent
                    panelRoot.setBorder(new EmptyBorder(6,6,6,6));                  // Set border of panel but not components inside (Top, Left, Bottom, Right)
                    panelRoot.setBackground(Color.red);
     
                    buildLeftPanel();
                    buildRightPanel();
     
                    panelRoot.add(panelLeftMain, BorderLayout.CENTER);              // Apply layout manager to LeftMain panel
                    panelRoot.add(panelRightMain, BorderLayout.EAST);               // Apply layout manager to RightMain panel
                    this.add(panelRoot);
                    this.setVisible(true);
            }
     
    //--------------------------------------------------------------------------------------------------------------------------------        
     
            public void buildLeftPanel()
            {
                    // Build sub-components
                    buildLeftTopPanel();
                    buildLeftCenterPanel();
                    buildLeftBottomPanel();
     
                    panelLeftMain.setLayout(new BorderLayout(6,6));                 // Set gap of panel components
                    panelLeftMain.setBorder(new EmptyBorder(0,0,0,3));              // Set border of panel but not components inside (Top, Left, Bottom, Right)
                    panelLeftMain.setOpaque(false);                                 // Set panel background to transparent
     
                    // Panel height & width
                    panelLeftTop.setPreferredSize(new Dimension(1,90));             // Set default panel width & height
                    panelLeftBottom.setPreferredSize(new Dimension(1,150));         // Set default panel width & height
     
                    // Temporary background colors to see the individual panels easier
                    panelLeftTop.setBackground(new Color(30, 30, 30));
                    panelLeftCenter.setBackground(new Color(30, 30, 30));
                    panelLeftBottom.setBackground(new Color(30, 30, 30));
     
                    panelLeftMain.add(panelLeftTop, BorderLayout.NORTH);            // Anything that isn't CENTER will not resize
                    panelLeftMain.add(panelLeftCenter, BorderLayout.CENTER);        // CENTER constraint will expand & contract on resize
                    panelLeftMain.add(panelLeftBottom, BorderLayout.SOUTH);         // Anything that isn't CENTER will not resize
            }
     
    //--------------------------------------------------------------------------------------------------------------------------------
     
            public void buildRightPanel()
            {
                    // Build sub-components
                    buildRightTopPanel();
                    buildRightBottomPanel();
     
                    panelRightMain.setLayout(new BorderLayout(6,6));                // Set gap of panel components
                    panelRightMain.setBorder(new EmptyBorder(0,3,0,0));             // Set border of panel but not components inside (Top, Left, Bottom, Right)
                    panelRightMain.setOpaque(false);                                // Set panel background to transparent
     
                    // Panel height & width
                    panelRightBottom.setPreferredSize(new Dimension(200,100));      // Set panel width & height
     
                    // Temporary background colors to see the individual panels easier
                    panelRightTop.setBackground(new Color(30, 30, 30));
                    panelRightBottom.setBackground(new Color(30, 30, 30));
     
                    panelRightMain.add(panelRightTop, BorderLayout.CENTER);         // CENTER constraint will expand & contract on resize
                    panelRightMain.add(panelRightBottom, BorderLayout.SOUTH);       // Anything that isn't CENTER will not resize
            }
     
    //--------------------------------------------------------------------------------------------------------------------------------
     
            public void buildLeftTopPanel()
            {
                    panelLeftTop.setLayout(new BorderLayout(10,10));                // Set gap of panel components
                    panelLeftTop.setBorder(new EmptyBorder(10,10,10,10));           // Set insets of panel components
     
                    labelTemp1.setForeground(Color.white);
     
                    panelLeftTop.add(labelTemp1, BorderLayout.NORTH);
            }
     
    //--------------------------------------------------------------------------------------------------------------------------------
     
            public void buildLeftCenterPanel()
            {
                    panelLeftCenter.setLayout(new BorderLayout(10,10));             // Set gap of panel components
                    panelLeftCenter.setBorder(new EmptyBorder(10,10,10,10));        // Set insets of panel components
     
                    labelTemp2.setForeground(Color.white);
     
                    panelLeftCenter.add(labelTemp2, BorderLayout.NORTH);
            }
     
    //--------------------------------------------------------------------------------------------------------------------------------        
     
            public void buildLeftBottomPanel()
            {
                    panelLeftBottom.setLayout(new BorderLayout(10,10));             // Set gap of panel components
                    panelLeftBottom.setBorder(new EmptyBorder(10,10,10,10));        // Set insets of panel components
     
                    labelTemp3.setForeground(Color.white);
     
                    panelLeftBottom.add(labelTemp3, BorderLayout.NORTH);
            }
     
    //--------------------------------------------------------------------------------------------------------------------------------
     
            public void buildRightTopPanel()
            {
                    panelRightTop.setLayout(new BorderLayout(10,10));               // Set gap of panel components
                    panelRightTop.setBorder(new EmptyBorder(10,10,10,10));          // Set insets of panel components
     
                    labelTemp4.setForeground(Color.white);
     
                    panelRightTop.add(labelTemp4, BorderLayout.NORTH);
            }
     
    //--------------------------------------------------------------------------------------------------------------------------------
     
            public void buildRightBottomPanel()
            {
                    panelRightBottom.setLayout(new BorderLayout(10,10));             // Set gap of panel components
                    panelRightBottom.setBorder(new EmptyBorder(10,10,10,10));        // Set insets of panel components
     
                    labelTemp5.setForeground(Color.white);
     
                    panelRightBottom.add(labelTemp5, BorderLayout.NORTH);
            }
     
    //--------------------------------------------------------------------------------------------------------------------------------
     
            public static void main(String[] args)
            {
                new Panels();
            }
     
    }

    Now I just gotta add components and maybe some sub-panels to each of the 5 panels displayed and figure out which LayoutManager to use for each at that level. That shouldn't be a problem though.

Similar Threads

  1. Calling a JPanel into another Jpanel in a JFrame
    By aknessy in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 17th, 2013, 10:14 AM
  2. Replies: 5
    Last Post: February 15th, 2013, 05:01 PM
  3. how to design a sliding menu in a jpanel
    By cnjiru in forum AWT / Java Swing
    Replies: 6
    Last Post: June 7th, 2012, 11:07 AM
  4. Having trouble with Jpanel design view forms :(
    By WorldsTallestMidget in forum What's Wrong With My Code?
    Replies: 8
    Last Post: June 10th, 2011, 03:31 PM
  5. JPanel in JFrame
    By maele in forum AWT / Java Swing
    Replies: 2
    Last Post: March 8th, 2010, 04:12 AM