Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8903507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:53:11+00:00 2026-06-15T01:53:11+00:00

What I am trying to do is organize five seperate JPanel’s within the frame.

  • 0

What I am trying to do is organize five seperate JPanel’s within the frame. Here is what the output is supposed to look like: There will be one panel across the top. Two panels directly below the top panel that vertically split the space and then another two panels that split the remaining space horizontally.

enter image description here

I cannot figure out how to organize the panels like described above and I think it is because I just don’t know the proper syntax. So any help or advise is greatly appreciated here is the code I have thus far.

import java.lang.String.*;
import java.lang.Exception.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Display extends JFrame implements ActionListener{
// instance variables
private static final int FRAME_WIDTH = 400;
private static final int FRAME_HEIGHT = 350;

private static final int FRAME_X_ORIGIN = 150;
private static final int FRAME_Y_ORIGIN = 150;

private static final int BUTTON_WIDTH = 90;
private static final int BUTTON_HEIGHT = 30;

private JButton readFile;
private JButton exit;
private JButton stats;
private JButton blank;

private JCheckBox avgHomeworkScore;
private JCheckBox avgTestScore;
private JCheckBox sdHomeworkScore;
private JCheckBox sdTestScore;

private JRadioButton buttonOne;
private JRadioButton buttonTwo;
private JRadioButton buttonThree;
private JRadioButton buttonFour;

private JPanel header;
private JPanel statistics;
private JPanel courses;
private JPanel display;
private JPanel action;

public static void main(String[] args){
    Display frame = new Display();
    frame.setVisible(true);
}


public Display(){

    Container contentPane;


    //Set the frame properties
    setSize         (FRAME_WIDTH, FRAME_HEIGHT);
    setResizable    (false);
    setTitle        ("CSCE155A Course Offerings Viewer");
    setLocation     (FRAME_X_ORIGIN, FRAME_Y_ORIGIN);

    contentPane = getContentPane();
    contentPane.setLayout(new GridLayout());
    contentPane.setBackground( Color.white );

    //header





    //Create and Place the Buttons on the frame
    readFile = new JButton("Read File");
    readFile.setBounds(4, 285, BUTTON_WIDTH, BUTTON_HEIGHT);


    exit = new JButton("Exit");
    exit.setBounds(100, 285, BUTTON_WIDTH, BUTTON_HEIGHT);


    stats = new JButton("Stats");
    stats.setBounds(195, 285, BUTTON_WIDTH, BUTTON_HEIGHT);


    blank = new JButton("Clear");
    blank.setBounds(290, 285, BUTTON_WIDTH, BUTTON_HEIGHT);


    action = new JPanel(new FlowLayout());
    action.setBackground(Color.blue);
    action.add(readFile); 
    action.add(exit);
    action.add(stats);
    action.add(blank);
    contentPane.add(action);

    //Register this frame as an Action listener of the buttons
    readFile.addActionListener(this);
    exit.addActionListener(this);
    stats.addActionListener(this);
    blank.addActionListener(this);

    //Create and Place the checkboxes on the frame
    avgHomeworkScore = new JCheckBox();
    avgHomeworkScore.setMnemonic(KeyEvent.VK_H);
    contentPane.add(avgHomeworkScore);
    avgHomeworkScore.setSelected(true);

    avgTestScore = new JCheckBox();
    avgTestScore.setMnemonic(KeyEvent.VK_T);
    avgTestScore.setSelected(true);

    sdHomeworkScore = new JCheckBox();
    sdHomeworkScore.setMnemonic(KeyEvent.VK_S);
    sdHomeworkScore.setSelected(true);

    sdTestScore = new JCheckBox();
    sdTestScore.setMnemonic(KeyEvent.VK_D);
    sdTestScore.setSelected(true);

    statistics = new JPanel(new GridLayout(0,1));
    contentPane.add(statistics);
    statistics.add(avgHomeworkScore);
    statistics.add(avgTestScore);
    statistics.add(sdHomeworkScore);
    statistics.add(sdTestScore);

    avgHomeworkScore.addActionListener(this);
    avgTestScore.addActionListener(this);
    sdHomeworkScore.addActionListener(this);
    sdTestScore.addActionListener(this);



    //create the radio buttons
    buttonOne = new JRadioButton();
    buttonOne.setMnemonic(KeyEvent.VK_1);
    buttonOne.setSelected(true);

    buttonTwo = new JRadioButton();
    buttonTwo.setMnemonic(KeyEvent.VK_2);

    buttonThree = new JRadioButton();
    buttonThree.setMnemonic(KeyEvent.VK_3);

    buttonFour = new JRadioButton();
    buttonFour.setMnemonic(KeyEvent.VK_4);

    ButtonGroup group = new ButtonGroup();
    group.add(buttonOne);
    group.add(buttonTwo);
    group.add(buttonThree);
    group.add(buttonFour);

    buttonOne.addActionListener(this);
    buttonTwo.addActionListener(this);
    buttonThree.addActionListener(this);
    buttonFour.addActionListener(this);

    courses = new JPanel(new GridLayout(0,1));
    courses.setBackground(Color.blue);
    courses.add(buttonOne);
    courses.add(buttonTwo);
    courses.add(buttonThree);
    courses.add(buttonFour);
    contentPane.add(courses);

    //Exit program when the viewer is closed
    setDefaultCloseOperation(EXIT_ON_CLOSE);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:53:12+00:00Added an answer on June 15, 2026 at 1:53 am

    Use a layout manager. Never set the bounds, sizes and locations of your panels and other components. That’s the job of the layout manager. Layout managers are explained in details in the Swing tutorial (as everything else, BTW).

    You could use a BorderLayout for the main panel, and another for the bottom panel, for example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of divs I'm trying to organize here. The ones I'm
I am trying to organize my JavaScript. What I would like to do is
I am trying to organize my application into packages because it will have several
I'm trying to organize filter chain of EventQueue.dispatchEvent . Something like java.io.FilterInputStream or javax.servlet.Filter
I am trying to organize nob-blocking read-write functionality with serial port in Linux. Here
I'm trying to work out how to organize an android application that will have
I'm trying to organize data I am given from a text file, there are
I am trying to organize a Zip Archive into an array so that I
I have Python nested list that I'm trying to organize and eventually count number
I'm trying to jump through some hoops to organize data in a special way.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.