i'm using gridbaglayout and finding it very frustrating (must use it for assignment).
im using the constrains.gridy which is set to 1 right now, i want it to go a bit lower, so i change it to 2, but it makes the component go much lower than I want it to, and if I go say 1.5 it gives me an error when i compile saying "possible loss of precision."
i just want to move my component a bit lower, i tried GridBagConstraints.SOUTH as well and it has no effect on its location, please help.
GridBagLayout is the most complex but the most useful layout manager in Swings. When using GridBagLayout, you need to understand GridBagConstraints because the positioning and other aspects like padding etc are adjusted using attributes of this class.
While gridx and gridy are used to specify the row and column values where the components are placed, there are many other parameters that decide the final look and feel. In your case, you may want to look at the 'insets' because this constraint specifies the expernal padding.
You can still use gridy as 1 and add some 'inset' (The value is specified as an Insets object - e.g . new Insets(2,2,2,2) ) to the components to give some external padding. You can adjust the values for top, left, bottom, and right insets to give the necessary padding to your component.
Hope this helps!
If you simply want to get your component lower you must try to put that component on a panel and then put the panel on top of the container. Let me know if that helps.
JPanel panel = new JPanel();
thanks to you both, will give it a try!
by the way do you know how to increase and decrease the size of componants in the gridbaglayout?
edit: riz how can I put a component into a panel?
Container c = getContentPane();
JPanel NorthPanel = new JPanel();
This should do it..