strange JScrollPane problem in JApplet

I've got a JApplet which is giving me a strange problem with the scrollbar of a JScrollPane.The JScrollPane is populated with a JList whose ListModel is a DefaultListModel. I specify to always show the vertical and never show the horizonatal scroll bars.

Once the JList content goes beyond the visible range of the viewport, it seems to be working as usual - the scrollbar reflects the amount of content. However, if I click on the scroll arrows, nothing happens. And, if I click on the scroll bar itself, it disables. Basically, the scrolling portion of the component dies. I don't get any exceptions during runtime or problems compiling the code.

I've tried making the ListModel and JList as dynamic elements (i.e. not members of the class). I've tried adding .validate(). I've tried everything of which I can think. I'm at a loss. The most troubling part of this is that if the project is set up as an application instead of an applet, it works fine.

I'm using J2 1.6.

Here's sample code that reproduces the problem:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

publicclass ScrollTestextends JApplet

{

private DefaultListModel exOddLM;

private JListexOddJL;

private JScrollPaneexOddSP;

private JButton click;

public ScrollTest(){

this.setup();

}

publicvoid init(){

this.setup();

}

publicvoid setup(){

this.setLayout(null);

this.setSize(400, 442);

this.exOddLM =new DefaultListModel();

this.exOddJL =new JList(this.exOddLM);

this.exOddSP =new JScrollPane(this.exOddJL);

this.exOddSP.setBounds(0, 0, 200, 200);

this.exOddSP.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

this.exOddSP.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

this.click=new JButton("add more");

this.click.addMouseListener(new MouseAdapter(){

publicvoid mouseClicked(MouseEvent me){ addMore();}

});

this.click.setBounds(0, 200, 200, 18);

this.add(this.exOddSP);

this.add(this.click);

}

privatevoid addMore(){

for(int x = 0; x < 5; x++){

this.exOddLM.addElement(Integer.toString(x));

}

}

}

[3660 byte] By [TripleDucka] at [2007-11-27 0:51:42]
# 1
You are calling this.setup twice, once in the constructor and once in init.This adds 2 buttons and 2 scroll panes to your applet.Remove the call to this.setup from init.
Rodney_McKaya at 2007-7-11 23:22:42 > top of Java-index,Desktop,Core GUI APIs...
# 2

It had to be something simple, didn't it? (=

Thanks!

I guess I was thinking that an applet wouldn't call the constructor. Don't know why I would have thought that.After removing the double call, it works great.

Thanks again Rodney!!!

You know, this actually explains a good deal of other problems I was having with the actual program (a homework assignment).One of them, I had added a KeyListener to an entry field on the form, and it was giving me all sorts of weird double-letter posts and letter-delete problems.

This also explains why it was working well as an application.

TripleDucka at 2007-7-11 23:22:42 > top of Java-index,Desktop,Core GUI APIs...