Problem using JScrollPane

Hello world, I'm new to Java. I've had one course in college on this language but I think I'm getting a pretty good grasp on it. I'm trying to set up a web-based survey that posts responses to a MySQL database. The survey itself is going to be many questions (40+) so I need to use a scroll pane to display all questions on one page. I've written the program and it works fine in appletviewer, but when I try to open it in a web browser (Firefox) the Java console displays the following error:

java.lang.ClassCastException: layout of JScrollPane must be a ScrollPaneLayout

at javax.swing.JScrollPane.setLayout(Unknown Source)

at WebSurvey.init(WebSurvey.java:71)

at sun.applet.AppletPanel.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

I have no objection to JScrollPane using that layout, and in fact it appears to do so in appletviewer (components are placed properly). If I read the documentation correctly, ScrollPaneLayout is the default option, so that should be what it is using. I'm not intentionally trying to change the layout of the pane but the error suggests that I am. The only thing I can imagine is causing trouble would be the BoxLayout of the pane displayed in the ScrollPane viewport, but surely that wouldn't be it? Here are the relevant bits of the code:

public class WebSurvey extends JApplet implements ActionListener

{

Container windowBox = getContentPane();

JPanel surveyBox = new JPanel();

JScrollPane surveyScroll = new JScrollPane( surveyBox );

JPanel answerSheet = new JPanel();

public void init()

{

// Add Answer Sheet to Survey

answerSheet.setLayout( new BoxLayout( answerSheet, BoxLayout.Y_AXIS ) );

surveyBox.add( answerSheet );

windowBox.add( surveyScroll );

}

}

I know this isn't functional code, I snipped out the boring parts that might lead to distraction and just left the parts dealing with my containers and layouts. Any help would be much appreciated, I think I've tackled the hardest parts (making the program work with MySQL, etc) and I'm so close to nailing this program. Thanks!

[2180 byte] By [michael.paynea] at [2007-11-26 13:42:32]
# 1
What is this line?at WebSurvey.init(WebSurvey.java:71)
ChuckBinga at 2007-7-8 0:00:27 > top of Java-index,Java Essentials,New To Java...
# 2
The error message says you are calling the setLayout() method on a JScrollPane object. Your code says you are calling the setLayout() method on a JPanel object. Hence, the code you are looking at is not the code that threw that exception.
DrClapa at 2007-7-8 0:00:27 > top of Java-index,Java Essentials,New To Java...
# 3

Sorry, I should have assumed you would want to reference that line number :)

Here is the section in question:

70// Add Answer Sheet to Survey

71answerSheet.setLayout( new BoxLayout( answerSheet, BoxLayout.Y_AXIS ) );

72answerSheet.add(nameBox);

This is why I thought it might be some issue with using the JScrollPane to display the JPanel.

To further confuse everyone, I ran the EXACT same compiled code on my computer here at home, also on Firefox browser, and it works fine! I'll try it again when I get back to the office later to see what happens on that machine again. The only difference is my JRE here is 1.5.10 and the malfunctioning one is 1.5.9... could that be the issue or what is going on here?

Thanks for the replies.

michael.paynea at 2007-7-8 0:00:27 > top of Java-index,Java Essentials,New To Java...
# 4

> The only difference

> is my JRE here is 1.5.10 and the malfunctioning one

> is 1.5.9... could that be the issue or what is going

> on here?

No, most likely the issue is that you're compiling the code to location X but running an old version of the code from location Y.

DrClapa at 2007-7-8 0:00:27 > top of Java-index,Java Essentials,New To Java...