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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:06:21+00:00 2026-06-13T23:06:21+00:00

With this code I will have the following window. I created 2 panels and

  • 0

With this code I will have the following window. I created 2 panels and added the mainp one to the frame and the panel to the mainp I did this in order to make window resizing dynamic (so the panel wont resize to the frame) I tried making my default panel size wider so that the text fields and label become wider but panel.setsize doesn’t seem to do anything.

enter image description here

// creates the labels
 studId = new JLabel("Student ID");
 studAvg = new JLabel("Student Average");
 studName = new JLabel("Student Name");

 // creates the text fields
 JTextField studIdText = new JTextField();
 JTextField studAvgText = new JTextField();
 JTextField studNameText = new JTextField();

 JPanel mainp = new JPanel();

 JPanel panel = new JPanel();
  panel.setLayout(new GridLayout(3, 2, 2, 2));

            panel.setSize(300, 100);

    // adds to the GridLayout
    panel.add(studId);
    panel.add(studIdText);
    panel.add(studName);
    panel.add(studNameText);
    panel.add(studAvg);
    panel.add(studAvgText);

    mainp.add(panel);
    add(BorderLayout.CENTER,mainp);

    // verifies the textfields
    studIdText.setInputVerifier(new IntVerifier());
    studAvgText.setInputVerifier(new DoubleVerifier());

    setTitle("Student Form");
    setSize(300, 200);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

enter image description here

  • 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-13T23:06:22+00:00Added an answer on June 13, 2026 at 11:06 pm

    using Advise from @Dan and @MADprogrammer and @trashgod i came up with the following

    JTextField studIdText = new JTextField(20);
    
    JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    GridBagConstraints r1 = new GridBagConstraints();
    
    r1.fill = GridBagConstraints.HORIZONTAL;
    r1.weightx = 0.0;
    r1.gridx = 0;
    r1.gridy = 0;
    panel.add(studId,r1);
    
    r1.weightx = 0.5;
    r1.gridx = 1;
    r1.gridwidth = GridBagConstraints.REMAINDER; 
    panel.add(studIdText,r1);
    

    of course you can make GridBagConstraints for every row and just change the gridy

    enter image description here

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

Sidebar

Related Questions

I have this following code which will return all the current semesters. How do
I have this code which will include template.php file from inside each of these
I have the this code that will create excel file and work sheet then
i have this code that will check the array contains the specific string and
I have this code that will check for if the class more-results are in
I have searched but can't find why this simple code will fail in Drools
I have this code: <script id=toModify > Invalid javascript that will cause errors </script>
I have this piece of code which I'm hoping will be able to tell
I have created a rudimentary EasterEgg within my code to activate when the following
This code will get us all the properties of a class: Dim myPropertyInfo As

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.