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

  • SEARCH
  • Home
  • 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 849471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:06:35+00:00 2026-05-15T07:06:35+00:00

This is making me very angry, I have worked on this for 2 days,

  • 0

This is making me very angry, I have worked on this for 2 days, have 2 books open and have looked through them, and STILL can’t get this program to run the way I want it run. I’m getting to the point where if this doesn’t help, I quit.

I want a SIMPLE Frame application.
It has a JComboBox centered at the top.
Next to it is a text field big enough to show numeric digits such as “$49.99”
Below it is a spot for a Text area showing terms of service
Below that is the checkbox agreeing to the terms of service
Below that is 2 buttons “Accept” and “Decline”

I Have worked on this for 2 days, here is the coding:

public class Bar extends JFrame implements ActionListener
{
    public Bar(final JFrame frame)
    {
        String[] tests = { "A+ Certification", "Network+ Certification", "Security+ Certification", "CIT Full Test Package" };
        JButton button = new JButton("Click Meh");
        add(new JLabel("Welcome to the CIT Test Program "));
        add(new JLabel("Please select which Test Package from the list below."));
        frame.setVisible(true);
        frame.setSize(250,250);
        JPanel pane1 = new JPanel(new FlowLayout());
        JPanel pane2 = new JPanel(new FlowLayout());

        JMenuBar menuBar = new JMenuBar();
        JMenu fileMenu = new JMenu("File");
        JMenu editMenu = new JMenu("Edit");
        JMenu helpMenu = new JMenu("Help");
        menuBar.add(fileMenu);
        menuBar.add(editMenu);
        menuBar.add(helpMenu);
        JMenuItem newMenu = new JMenuItem("New  (Ctrl+N)");
        JMenuItem openMenu = new JMenuItem("Open  (Ctrl+O)");
        JMenuItem saveMenu = new JMenuItem("Save  (Ctrl+S)");
        saveMenu.addActionListener(this);
        JMenuItem exitMenu = new JMenuItem("Exit  (Ctrl+W)");
        JMenuItem cutMenu = new JMenuItem("Cut  (Ctrl+X)");
        JMenuItem copyMenu = new JMenuItem("Copy  (Ctrl+C)");
        JMenuItem pasteMenu = new JMenuItem("Paste  (Ctrl+V)");
        JMenuItem infoMenu = new JMenuItem("Help  (Ctrl+H)");
        fileMenu.add(newMenu);
        fileMenu.add(openMenu);
        fileMenu.add(saveMenu);
        fileMenu.add(exitMenu);
        editMenu.add(cutMenu);
        editMenu.add(copyMenu);
        editMenu.add(pasteMenu);
        helpMenu.add(infoMenu);
        frame.setJMenuBar(menuBar);
        JComboBox packageChoice =  new JComboBox(tests);
        frame.add(packageChoice);


    }

     public void actionPerformed(ActionEvent e)
  {
  Object source = e.getSource();
  {
  }

}

EDIT:
Forgot to add the second program

public class JFrameWithPanel
{
    public static void main(String[] args)
    {
         JPanel panel = new Bar(new JFrame("CIT Test Program"));
    }
}

How do I get this to have everything where I want it and show up? I’m very confused because of this and now barely even get how Frames work.

  • 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-05-15T07:06:35+00:00Added an answer on May 15, 2026 at 7:06 am

    Components in Swing have to be laid out in a certain order.

    You start with a JFrame. The only components that are placed in the JFrame are a JMenuBar and a JPanel. You do not add any other components in a JFrame. You add components in a JPanel.

    Here’s Nick’s code, reorganized to define the components in the correct order. I used GridLayout because it was quicker. You should use GridBagLayout, as Nivas said.

    public class Bar {
    
        private static final long serialVersionUID = 1L;
    
        public Bar(final JFrame frame) {
            JMenuBar menuBar = buildMenuBar();
            frame.setJMenuBar(menuBar);
    
            JPanel masterPanel = new JPanel(new GridLayout(2, 1));
    
            JPanel pane1 = new JPanel(new GridLayout(3, 1));
            pane1.add(new JLabel("Welcome to the CIT Test Program "));
            pane1.add(new JLabel("Please select which Test Package from the list below."));
            JButton button = new JButton("Click Me");
            pane1.add(button);
    
            JPanel pane2 = new JPanel(new GridLayout(1, 1));
            String[] tests = { "A+ Certification", "Network+ Certification",
                    "Security+ Certification", "CIT Full Test Package" };
            JComboBox packageChoice = new JComboBox(tests);
            pane2.add(packageChoice);
    
            masterPanel.add(pane1);
            masterPanel.add(pane2);
    
            frame.add(masterPanel);
            frame.pack();
    
            frame.setVisible(true);
    //      frame.setSize(250, 250);
    
        }
    
        public JMenuBar buildMenuBar() {
            JMenuBar menuBar = new JMenuBar();
            JMenu fileMenu = new JMenu("File");
            JMenu editMenu = new JMenu("Edit");
            JMenu helpMenu = new JMenu("Help");
            menuBar.add(fileMenu);
            menuBar.add(editMenu);
            menuBar.add(helpMenu);
            JMenuItem newMenu = new JMenuItem("New  (Ctrl+N)");
            JMenuItem openMenu = new JMenuItem("Open  (Ctrl+O)");
            JMenuItem saveMenu = new JMenuItem("Save  (Ctrl+S)");
            saveMenu.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    // TODO Auto-generated method stub
    
                }
            });
            JMenuItem exitMenu = new JMenuItem("Exit  (Ctrl+W)");
            JMenuItem cutMenu = new JMenuItem("Cut  (Ctrl+X)");
            JMenuItem copyMenu = new JMenuItem("Copy  (Ctrl+C)");
            JMenuItem pasteMenu = new JMenuItem("Paste  (Ctrl+V)");
            JMenuItem infoMenu = new JMenuItem("Help  (Ctrl+H)");
            fileMenu.add(newMenu);
            fileMenu.add(openMenu);
            fileMenu.add(saveMenu);
            fileMenu.add(exitMenu);
            editMenu.add(cutMenu);
            editMenu.add(copyMenu);
            editMenu.add(pasteMenu);
            helpMenu.add(infoMenu);
            return menuBar;
        }
    }
    

    I moved the JMenuBar code into its own method so, hopefully, the rest of the code is easier to understand.

    I have a master JPanel, that all of the other components are added to.

    I used another JPanel to hold the two JLabels and the JButton.

    I used a third JPanel to hold the JComboBox.

    The basic pattern is as follows:

    • Define the JPanel.
    • Define the components.
    • Add the components to the JPanel.
    • Add the JPanel to the master JPanel
    • Add the master JPanel to the JFrame.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was making this very simple lex program (just an introductory program). But on
I'm making this game where I'm trying to pair people. So I have this
I'm making this method retrieve records from the Data Base. As you can see
I'm making this little project with fwrite (long story, and I can't use DB's).
This should be simple. I'm making a very basic app, based on the Utility
I'm still learning about MySQL. I may be making a very basic error, and
Ok, I'm making a very basic vb.net winforms app, essentially you can drag files
I've been at this for a while and I'm making very slow progress mostly
I'm very new to bash scripting and I'm trying to practice by making this
This is very simple linq and I am just beginning with it. I have

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.