-
2 Attachment(s)
GridBagLayoutProblem
I started making a small dictionary app for practice but i'm stuck at
the very beginning . I just don't know how to reduce the space between the
Container and the first Component that i add, the more i resize the
window the space is larger. I tried setting the weightx and weighty
constraints, but still no change. Any help?
I'v attached the source code and screenshot.
I want the JTextField component to be the first in right after the window bar with a very small amount of space.
-
Re: GridBagLayoutProblem
To add space around a component use the ipadx and ipady values.
Having said that, using GridBagLayout for such a simple problem seems like an over kill to me. Have you looked at the Box container which uses BoxLayout and has methods for adding fixed size invisible components (struts).
-
Re: GridBagLayoutProblem
You could give the main panel a BorderLayout and add your two components to a sub-panel which you then add to the NORTH of the main panel:
Code:
...
panel.setLayout(new BorderLayout());
JPanel panelNorth = new JPanel();
panel.add(panelNorth, BorderLayout.NORTH);
rec = new JTextField(16);
potrazi = new JButton("Potrazi");
panelNorth.add(rec);
panelNorth.add(potrazi);
...
This will guarantee they always stay at the top.
If you plan to throw one away, you will throw away two...
C. Zerouni
-
Re: GridBagLayoutProblem
Oops, just realised I misread the question, I thought the OP was trying to add space between the components.