Oh, and though I haven't compiled your example, you will probably need
to set the weighty to something non-zero and set the c.fill to
GridBagConstraints.BOTH. GridBadLayout is really quite complex and
there are lots of "gotchas" to be wary of. For this example you might
be able to get away with GridLayout, which is much simpler (though of
course less flexible).
Ryan
Hello Ryan,
thanks for the hints, I`ve tried them but no success. The best I can
reach is to display the components not to fill the whole paint area, but
they`ll appear in the middle. Can you please give a sample code? As
mentioned the layout is OK with the exception that they should appear in
the top of the window.
Thank you.
Daniel
> Trying anchoring the components:
>
[quoted text clipped - 16 lines]
> Sign up for the RapidJ beta!
> http://www.codecanvas.com.au/rapidj/
Ryan Dillon - 30 Mar 2005 23:37 GMT
Hi Daniel
Maybe this will help?
public void init() {
setLayout(new BorderLayout());
ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
Panel p = new Panel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.NORTH;
c.weightx = 1.0;
c.weighty = 0.0;
for (int i = 0; i < 3; i++) {
c.gridwidth = 1;
if (i==2) {
c.weighty = 1.0; // Give last row left over y space
}
Button button1 = new Button("test");
p.add(button1, c);
Label l = new Label("test");
p.add(l, c);
Button button2 = new Button("test");
c.gridwidth = GridBagConstraints.REMAINDER;
p.add(button2, c);
}
sp.add(p);
add(sp);
}
Cheers
Ryan
Ryan Dillon - 30 Mar 2005 23:44 GMT
Hi Daniel
I'm not sure exactly how you want it to look, but try this:
public void init() {
setLayout(new BorderLayout());
ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
Panel p = new Panel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.NORTH;
c.weightx = 1.0;
c.weighty = 0.0;
for (int i = 0; i < 3; i++) {
c.gridwidth = 1;
if (i==2) {
c.weighty = 1.0; // Give last row left over y space
}
Button button1 = new Button("test");
p.add(button1, c);
Label l = new Label("test");
p.add(l, c);
Button button2 = new Button("test");
c.gridwidth = GridBagConstraints.REMAINDER;
p.add(button2, c);
}
sp.add(p);
add(sp);
}
Cheers
Ryan
Ryan Dillon - 30 Mar 2005 23:53 GMT
Hi Daniel,
(If this message appears three times, blame Google Groups beta!).
Try the following, it might be what you are looking for?
public void init() {
setLayout(new BorderLayout());
ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
Panel p = new Panel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.NORTH;
c.weightx = 1.0;
c.weighty = 0.0;
for (int i = 0; i < 3; i++) {
c.gridwidth = 1;
if (i==2) {
c.weighty = 1.0; // Give last row left over y space
}
Button button1 = new Button("test");
p.add(button1, c);
Label l = new Label("test");
p.add(l, c);
Button button2 = new Button("test");
c.gridwidth = GridBagConstraints.REMAINDER;
p.add(button2, c);
}
sp.add(p);
add(sp);
}
Cheers
Ryan
Daniel Tahin - 01 Apr 2005 13:17 GMT
Hello Ryan,
all of your messages appear ;-).
Great, this works and does exactly what I need!
Thank you for the support ;-).
Kind regards
Daniel
> Hi Daniel,
>
[quoted text clipped - 40 lines]
> Cheers
> Ryan
Ryan Dillon - 31 Mar 2005 00:11 GMT
Hi Daniel,
(If this message appears three times, blame Google Groups beta!).
Try the following, it might be what you are looking for?
public void init() {
setLayout(new BorderLayout());
ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
Panel p = new Panel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.NORTH;
c.weightx = 1.0;
c.weighty = 0.0;
for (int i = 0; i < 3; i++) {
c.gridwidth = 1;
if (i==2) {
c.weighty = 1.0; // Give last row left over y space
}
Button button1 = new Button("test");
p.add(button1, c);
Label l = new Label("test");
p.add(l, c);
Button button2 = new Button("test");
c.gridwidth = GridBagConstraints.REMAINDER;
p.add(button2, c);
}
sp.add(p);
add(sp);
}
Cheers
Ryan
Hello Ryan,
thanks for the hints, I`ve tried them but no success. The best I can
reach is to display the components not to fill the whole paint area, but
they`ll appear in the middle. Can you please give a sample code? As
mentioned the layout is OK with the exception that they should appear in
the top of the window.
Thank you.
Daniel
> Trying anchoring the components:
>
[quoted text clipped - 16 lines]
> Sign up for the RapidJ beta!
> http://www.codecanvas.com.au/rapidj/
Ryan Dillon - 31 Mar 2005 00:22 GMT
Hi Daniel,
(If this message appears three times, blame Google Groups beta!).
Try the following, it might be what you are looking for?
public void init() {
setLayout(new BorderLayout());
ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
Panel p = new Panel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.anchor = GridBagConstraints.NORTH;
c.weightx = 1.0;
c.weighty = 0.0;
for (int i = 0; i < 3; i++) {
c.gridwidth = 1;
if (i==2) {
c.weighty = 1.0; // Give last row left over y space
}
Button button1 = new Button("test");
p.add(button1, c);
Label l = new Label("test");
p.add(l, c);
Button button2 = new Button("test");
c.gridwidth = GridBagConstraints.REMAINDER;
p.add(button2, c);
}
sp.add(p);
add(sp);
}
Cheers
Ryan