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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:10:40+00:00 2026-06-04T02:10:40+00:00

I have a gridbag layout where I initialize an gbc.insets = Insets(0,0,0,); Later I

  • 0

I have a gridbag layout where I initialize an gbc.insets = Insets(0,0,0,);
Later I want to resize this inset when some action happens.
I’ve tried changing the value and then doing a repaint() but that does not work?
What do I need to do? Thank you very much!

class myGraph {

    private Insets myInsets = new Insets(0,0,0,0);

    ...
    gbc.insets = myInsets; // setting Gridbag constraints.



    Action Listener {

        ............... 
        myInsets.top =30;
        myInsets.bottom =40;
        myGraph.repaint();
    }
}
  • 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-04T02:10:42+00:00Added an answer on June 4, 2026 at 2:10 am

    You need to update the GridBagLayout:

    GridBagLayout layout = new GridBagLayout();
    JPanel panel = new JPanel(layout);
    ...
    layout.setConstraints(myComponent, anotherConstraint);
    // do this for all the components you want to update
    panel.revalidate();
    panel.repaint();
    

    GridBagLayout clones your constraints when you add components, so you need to tell the LayoutManager that you want to change those constraints. Simply modifying the consraints value will have absolutely no effect.

    Btw, repaint() is just to perform “painting” operations, not layout. Use revalidate() instead.

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

Sidebar

Related Questions

I want getMinimumSize to return weight=0 to cheat GridBagLayout.ipadx I have tried: public class
I want to have the following layout: (i.e. jbutton and jlabel are placed at
Trying to use GridBagLayout. I have the method called buildLabel. This creates three label.
have written this little class, which generates a UUID every time an object of
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I want to layout my JPane like so: ------- | | | | |
I have a very simple JLabel with a quite long text. The parent layout
I have a main frame and 3 panels. I want to add those 3
So I have this class. We'll call it ProcessBox. I have another class called
I have a problem with GridBagLayout. My components doesnt want to look like i

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.