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 8284845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:15:39+00:00 2026-06-08T11:15:39+00:00

I’m trying to set the size of a gridlayout jpanel. Here is the code:

  • 0

I’m trying to set the size of a gridlayout jpanel. Here is the code:

JFrame myFrame = new JFrame();    
    myFrame.setLayout(new FlowLayout());  
    myFrame.setLocation(400, 100);
    myFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 
    JLabel jlMins = new JLabel("Number of minutes for tutoring session (should be a positive decimal number):  0.0");
    JLabel jlEarnings = new JLabel("Earnings in dollars and cents received (should be positive decimal number):  0.0");
    jtfMins = new JTextField(20); 
    jtfEarnings = new JTextField(20);
    JPanel jpMins = new JPanel(new BorderLayout());
    JPanel jpEarnings = new JPanel(new BorderLayout());
    jpMins.setPreferredSize(new Dimension(300,50));
    jpEarnings.setPreferredSize(new Dimension(300,50));
    jpMins.add(jlMins,BorderLayout.NORTH);
    jpMins.add(jtfMins,BorderLayout.CENTER);
    jpEarnings.add(jlEarnings,BorderLayout.NORTH);
    jpEarnings.add(jtfEarnings,BorderLayout.CENTER);
    JButton jbQuit = new JButton("Quit");
    JButton jbEnter = new JButton("Enter");
    JButton jbReport = new JButton("Run Report");
    jbQuit.setActionCommand("quit");
    jbEnter.setActionCommand("enter");
    jbReport.setActionCommand("report");
    jbQuit.addActionListener(this);
    jbEnter.addActionListener(this);
    jbReport.addActionListener(this);
    JPanel jpButtons = new JPanel(new GridLayout(4,1,0,20)); 
    jpButtons.setSize(new Dimension(50,150));
    jpButtons.add(jbEnter);  
    jpButtons.add(jbReport);
    jpButtons.add(jbQuit); 
    JPanel jpNorth = new JPanel(new BorderLayout());
    jpNorth.add(jpMins,BorderLayout.NORTH); 
    jpNorth.add(jpEarnings,BorderLayout.CENTER);
    jpNorth.add(jpButtons,BorderLayout.SOUTH);
    jtaReports = new JTextArea();
    jtaReports.setColumns(40);
    jtaReports.setRows(10);
    jtaReports.setLineWrap(true);
    JScrollPane jspReports = new JScrollPane(jtaReports);
    jspReports.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    JPanel jpSouth = new JPanel();
    jpSouth.setPreferredSize(new Dimension(350,200)); 
    jpSouth.add(jspReports); 
    JPanel jpMain = new JPanel(new BorderLayout()); 
    jpMain.add(jpNorth,BorderLayout.NORTH);
    jpMain.add(jpSouth,BorderLayout.SOUTH);
    jpMain.setPreferredSize(new Dimension(500,500));
    myFrame.setContentPane(jpMain);  
    myFrame.pack();
    myFrame.setVisible(true);  

The panel name is jpButtons. Of the above code I’m talking mainly about this section:

   JButton jbQuit = new JButton("Quit");
JButton jbEnter = new JButton("Enter");
JButton jbReport = new JButton("Run Report");
jbQuit.setActionCommand("quit");
jbEnter.setActionCommand("enter");
jbReport.setActionCommand("report");
jbQuit.addActionListener(this);
jbEnter.addActionListener(this);
jbReport.addActionListener(this);
JPanel jpButtons = new JPanel(new GridLayout(4,1,0,20)); 
jpButtons.setSize(new Dimension(50,150));
jpButtons.add(jbEnter);  
jpButtons.add(jbReport);
jpButtons.add(jbQuit); 

How exactly does setSize, and setPreferredSize work or how to get them to work properly on jpanel, components, etc.

  • 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-08T11:15:41+00:00Added an answer on June 8, 2026 at 11:15 am

    scaling and positioning is handled by the layout manager; let it do its job.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.