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();
}
}
You need to update the GridBagLayout:
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.