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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:24:09+00:00 2026-06-15T17:24:09+00:00

I use GridBagConstraints to update my layout, when a button have been clicked, some

  • 0

I use GridBagConstraints to update my layout, when a button have been clicked, some input fields will appear.

private class EventListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            input_panel.removeAll();
               String str = e.getActionCommand();
               System.out.print(str);

               JLabel jl = new JLabel("Label ");
            // Create constraints
               GridBagConstraints textFieldConstraints = new GridBagConstraints();
               GridBagConstraints labelConstraints = new GridBagConstraints();

               labelConstraints.gridx = 0;
               labelConstraints.gridy = 0;

               input_panel.add(jl,textFieldConstraints);
        }
    }

This function successfully runs, however, there is a strange problem, when I click the button, it do update, but not show immediately, I must need to resize the window to see it. What happens?

  • 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-15T17:24:11+00:00Added an answer on June 15, 2026 at 5:24 pm
    input_panel.add(jl,textFieldConstraints);
    input_panel.revalidate(); //try to add this
    input_panel.repaint(); // and this
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Use Case: I have some repo on GitHub, someone forked it and added new
i have to writing an applet, in left side i must use an panel
use javascript or other method ? have any recommendation?
My goal is to have my components resize according to my GridBagConstraints, but for
I have a filereader and need to use the text for the text of
I'm new to Java Swing and I have been struggling to start the GridBagLayout
Use a hidden field will fix my issue... i got it.. Hi All, I
In attempting to make some Swing code more readable, I have made an InlineGridBagConstraints
I have a class extending JPanel that I want to embed into a JFrame
I am trying to use the gridx and gridy constraints to position my button.

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.