Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem using JScrollPane

807599Dec 28 2006 — edited Dec 29 2006
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!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 26 2007
Added on Dec 28 2006
4 comments
929 views