M
Mark_Galeck
Hello, I want to set a length of a horizontal JSlider myself, and
then let the layout manager figure out lay everything out keeping my
length if it can figure out how. Some people say I should not set
sizes myself, but in this situation, letting the manager decide, I
think this is OK?
Anyway, I am not succeeding at all - here is my code boiled down to
the bare minimum - here I am not even using any layout manager. Here
is the JApplet init() method:
public void init() {
JSlider s = new JSlider(0, 400);
add(s);
validate();
Dimension d = s.getSize();
d.width = 400;
s.setSize(d);
validate();
}
I try to do it twice, first in the constructor, then I validate() to
make sure it is really laid out initially, so I can call getSize and
get a meaningful result and then change it and call setSize.
My applet window size is 1000x1000. In the example above, I try first
without a layout manager. Then the slider size is 1000 as well, in
the middle of the applet.
OK - If I try, for example, to use BorderLayout and then first add to
Center, another component, and then this slider to the East - that I
thought would make the center as large as possible (this is how
BorderLayout works) and restrict the slider to the smallest size
possible, so now I hoped the slider would be 400 pixels wide and the
central component 600. No - the center is about 800 and the slider -
200.
What is going on here? Why can't I do this? How??
Please explain to me. Thank you very much! Mark
then let the layout manager figure out lay everything out keeping my
length if it can figure out how. Some people say I should not set
sizes myself, but in this situation, letting the manager decide, I
think this is OK?
Anyway, I am not succeeding at all - here is my code boiled down to
the bare minimum - here I am not even using any layout manager. Here
is the JApplet init() method:
public void init() {
JSlider s = new JSlider(0, 400);
add(s);
validate();
Dimension d = s.getSize();
d.width = 400;
s.setSize(d);
validate();
}
I try to do it twice, first in the constructor, then I validate() to
make sure it is really laid out initially, so I can call getSize and
get a meaningful result and then change it and call setSize.
My applet window size is 1000x1000. In the example above, I try first
without a layout manager. Then the slider size is 1000 as well, in
the middle of the applet.
OK - If I try, for example, to use BorderLayout and then first add to
Center, another component, and then this slider to the East - that I
thought would make the center as large as possible (this is how
BorderLayout works) and restrict the slider to the smallest size
possible, so now I hoped the slider would be 400 pixels wide and the
central component 600. No - the center is about 800 and the slider -
200.
What is going on here? Why can't I do this? How??
Please explain to me. Thank you very much! Mark