?
Solved

Build frame with sections of different size

Posted on 2011-10-12
4
Medium Priority
?
180 Views
Last Modified: 2012-05-12
---------------------------------------------------
|                                                                     |
|                                                                     |
|                      red                                          |
|                                                                     |
|                                                                     |
|                                                                     |
---------------------------------------------------
|                       blue                                        |
---------------------------------------------------
|                      white                                       |
---------------------------------------------------
|                      orange                                     |
---------------------------------------------------

How to code to generate a frame containing 4 sections as shown?

Thank you


0
Comment
Question by:Mike Eghtebas
  • 2
  • 2
4 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36959324
You use the BorderLayout() and then put red panel to center and make another panel which should have gridlaout
and add three panels to that second panel and then place that second panel to the south location of BorderLayout
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 36959339
FYI the text Red, White, etc. will not show. The background need to be colored as shown
0
 
LVL 47

Accepted Solution

by:
for_yan earned 2000 total points
ID: 36959349
import javax.swing.*;
import java.awt.*;

public class FrameWithSections extends JFrame {

    public  FrameWithSections () {
        JPanel bigPanel = new JPanel();
        JPanel secondPanel = new JPanel();
        JPanel blue = new JPanel();
        JPanel white = new JPanel();
        JPanel orange = new JPanel();

        bigPanel.setBackground(Color.red);
        blue.setBackground(Color.blue);
         white.setBackground(Color.white);
         orange.setBackground(Color.orange);


        secondPanel.setLayout(new GridLayout(3,1));
        secondPanel.add(blue);
        secondPanel.add(white);
        secondPanel.add(orange);

        Container c = this.getContentPane();
        c.setLayout(new BorderLayout());
        c.add(bigPanel);
        c.add(secondPanel, BorderLayout.SOUTH);
        this.setSize(200,200);
        this.setVisible(true);



    }

    public static void main(String[] args) {

        new FrameWithSections();
    }

}

Open in new window

0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 36959520
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month8 days, 11 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question