Help a newbie Java programmer - component placement

D

Dan Rifkin

I've programmed other languages, now I'm learning Java. I have a simple
applet based on a sample from Sun's jdk 6.0.11. I'm trying to add a scroll
bar.

public class DrawTest extends Applet{
DrawPanel panel;
DrawControls controls;
Scrollbar scrollbar;
public void init()
{
setLayout(new BorderLayout());
panel = new DrawPanel();
controls = new DrawControls(panel);
scrollbar = new Scrollbar(Scrollbar.HORIZONTAL);
add("Center", panel);
add("North", controls);
add(scrollbar);
scrollbar.move(50, 50);
scrollbar.resize(80, 20);
}

<snip>

If I add the scroll bar with add ("South", scrollbar); it's
placed at the south end of the applet, extending from
right to left.

If I add it as above, it takes up the entire app window
except for the component on the north side, as if it's
ignoring the move() and resize() methods. What I want
to do is have two scroll bars on the applet window that
I can place next to each other, or otherwise arbitrarily
size and place.

If I comment out the setLayout(), the scrollbar appears
in a different place, but still seems to ignore move()
and size().

Thanks for any help!
 
M

Michael Rauscher

xpost+fup2 comp.lang.java.help

Dan said:
public class DrawTest extends Applet{
DrawPanel panel;
DrawControls controls;
Scrollbar scrollbar;
public void init()
{
setLayout(new BorderLayout());
panel = new DrawPanel();
controls = new DrawControls(panel);
scrollbar = new Scrollbar(Scrollbar.HORIZONTAL);
add("Center", panel);
add("North", controls);
add(scrollbar);
scrollbar.move(50, 50);
scrollbar.resize(80, 20);
}

If I add the scroll bar with add ("South", scrollbar); it's
placed at the south end of the applet, extending from
right to left.

If I add it as above, it takes up the entire app window
except for the component on the north side, as if it's
ignoring the move() and resize() methods. What I want

You should read a bit about layout managers:

to do is have two scroll bars on the applet window that
I can place next to each other, or otherwise arbitrarily
size and place.
Why?


If I comment out the setLayout(), the scrollbar appears
in a different place, but still seems to ignore move()
and size().

Sure, because Applet uses FlowLayout by default.

Bye
Michael
 
A

Andrew Thompson

I've programmed other languages, now I'm learning Java.  I have a simple
applet ..

There is no such thing as a simple applet.
Start with applications (based on a Frame or
JFrame).
..based on a sample from Sun's jdk 6.0.11.  I'm trying to add a scroll
bar.

What do the scroll bars do?
public class DrawTest extends Applet{ ....
<snip>

If I add the scroll bar with add ("South", scrollbar); it's
placed at the south end of the applet, extending from
right to left.

If I add it as above, it takes up the entire app window
except for the component on the north side, as if it's
ignoring the move() and resize() methods.

The scrollbars would be conforming to the
existing layout.
.. What I want
to do is have two scroll bars on the applet window that
I can place next to each other, or otherwise arbitrarily
size and place.

Be careful here. If you arbitrarily size
components, they may not work on another
system where the component would naturally
be a larger size.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top