David S
David S

Reputation: 187

Java Swing - Modify GridBagConstraints

I got two JPanels in a GridBagLayout, a canvas and a toolbox, and if the user clicks over the toolbox panel I want it to change size (essentially opening it). Is there a (smarter) way to modify the weight of the toolbox constraint without having to remove all the components from the parent panel and re-adding the canvas and toolbox but with modified constraints?

Upvotes: 1

Views: 523

Answers (1)

copeg
copeg

Reputation: 8348

You can change the constraints of a Component already contained in a Container with a GridBagLayout by calling

  1. setConstraints on the GridBagLayout with the appropriate GridBagConstraint object
  2. Calling revalidate and repaint on the Container

Upvotes: 5

Related Questions