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.
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).
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
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.