March 19th, 2009, 07:34 AM
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.
March 19th, 2009, 03:29 PM
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).
March 19th, 2009, 04:41 PM
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:
This will guarantee they always stay at the top.
JPanel panelNorth = new JPanel();
rec = new JTextField(16);
potrazi = new JButton("Potrazi");
If you plan to throw one away, you will throw away two...
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.
March 19th, 2009, 05:08 PM
Oops, just realised I misread the question, I thought the OP was trying to add space between the components.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.