Constraints

Suppose that after the following code I have changed the values of a,b,c,d and I want to see the appropriate change in the view. How can I perform this task ? Thanks !

JTable table =new JTable(3, 5);

JPanel panel =new JPanel(new GridBagLayout());

GridBagConstraints c =new GridBagConstraints();

int a = 1, b = 2, c = 3, d = 4;

c.gridx = 2;

c.gridy = 3;

c.insets =new Insets(a, b, c, d);

panel.add(table, c);

[665 byte] By [leonarda] at [2007-11-26 20:09:08]
# 1
panel.revalidate(); should make the Layout figure out where everything needs to be..and if you aren't getting a completely fresh view after that..then trypanel.repaint();-Js
JSnakea at 2007-7-9 23:12:10 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thanks for so quick response !Maybe I didn't understand something, but how revalidate or repaint can help if I change only the 4 integer variables a,b,c,d ? I must change something in panel too, to give a reason to a new view.... But what should I change ?
leonarda at 2007-7-9 23:12:10 > top of Java-index,Desktop,Core GUI APIs...
# 3

the problem is, that the layout makes a clone of the constraints, so changing the constraints makes no sense. but you can get them by calling GridBagLayout.getConstraints(Component comp)

, then change the constraints (or just create new ones), then call again setConstraints with the new constraints

Al-Cepia at 2007-7-9 23:12:10 > top of Java-index,Desktop,Core GUI APIs...
# 4

BTW you shouldn't name your local constraints c AND a local int c... just for reference.

Al-Cepi is right.. set the constraints using setConstraints then call revalidate() if everything doesn't snap into place like it should. And like I said before.. if your screen isn't updating its display according to you, then call repaint() and see if that helps any.

GridBagLayout is evil. I always suggest trying to figure out a way to use one of many other layout managers.

http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html

Good Luck.

-Js

JSnakea at 2007-7-9 23:12:10 > top of Java-index,Desktop,Core GUI APIs...
# 5
Great !!It works !Thanks a lot !
leonarda at 2007-7-9 23:12:10 > top of Java-index,Desktop,Core GUI APIs...