Trouble adding scrollbar to applet...

Hey,

I'm just trying to add a scrollbar to my applet for some increased functionality, but I can't seem to get the **** thing to show up in the applet. I know you're thinking this is a very stupid question because it's usually very easy to do, but I have no idea why it's not showing up when I run the applet. Any help would be great...

publicclass TraceDemoextends Appletimplements MouseListener

{

....

....

private Scrollbar scroll =new Scrollbar(Scrollbar.VERTICAL, 0, 1, 0, 11);

....

....

public TraceDemo(){}// Construct applet

publicvoid init(){// Initialize applet

try{

jbInit();

}

catch (Exception e){

e.printStackTrace();

}

}

privatevoid jbInit()throws Exception{

scroll.setLocation(60, 335);

addMouseListener(this);

this.setLayout(null);

this.setSize(new Dimension(700, 700));

this.add(scroll);

.....

[1862 byte] By [stogey25a] at [2007-11-27 10:32:20]
# 1

Don't add a Scrollbar, add a ScrollPane, which has it's own ScrollBars. Then add what you want to scroll to the ScrollPane. You can set the scroll policy of the ScrollPane to determine when and if the scroll bars appear.

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/ScrollPane.html

hunter9000a at 2007-7-28 18:16:06 > top of Java-index,Java Essentials,Java Programming...
# 2

Well, thanks, that worked, the only problem is that it gave me a horizontal scrollbar as well. I only need a vertical scrollbar though. Is there a way to get rid of the horizontal one?

stogey25a at 2007-7-28 18:16:06 > top of Java-index,Java Essentials,Java Programming...
# 3

> Well, thanks, that worked, the only problem is that

> it gave me a horizontal scrollbar as well. I only

> need a vertical scrollbar though. Is there a way to

> get rid of the horizontal one?

You can set the horizontal or vertical scrollbar's policy to determine when it appears:

http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JScrollPane.html#setHorizontalScrollBarPolicy(int)

Set it to ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER.

hunter9000a at 2007-7-28 18:16:06 > top of Java-index,Java Essentials,Java Programming...
# 4

Oops, forgot you were using awt instead of swing.

The ScrollPane class has a getHAdjustable() method that returns an Adjustable, which is actually a ScrollPaneAdjustable. I started looking at that class, but didn't see how to adjust the policy, although the ScrollPane api says that's the class that determines the policy.

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/ScrollPaneAdjustable.html

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/ScrollPane.html#getHAdjustable()

hunter9000a at 2007-7-28 18:16:06 > top of Java-index,Java Essentials,Java Programming...
# 5

Move up to Swing.

BigDaddyLoveHandlesa at 2007-7-28 18:16:06 > top of Java-index,Java Essentials,Java Programming...
# 6

> Move up to Swing.

++

hunter9000a at 2007-7-28 18:16:06 > top of Java-index,Java Essentials,Java Programming...
# 7

I would also add: write applications not applets -- there's no advantage to writing an applet. But one thing at a time, and switching to Swing is the bigger win.

BigDaddyLoveHandlesa at 2007-7-28 18:16:06 > top of Java-index,Java Essentials,Java Programming...