Hi all,
I'm trying to create a JApplet that contains a large, scrollable JPanel. Eventually the JPanel will contain custom drawn items, but the first step is to just make the thing scrollable. However, the scroll bars are not activated unless I set them to always visible, and even then the actual bars that allow scrolling are not present. This is the first time I'm trying to write an applet, so I'm not sure whether the problem is with the JPanel, the JScrollPane, or the JApplet.
Strangely enough, if I change the width and height of the applet in the html calls, the scroll bars do activate. Why is that? Since I'm adding the JPanel to the JScrollPane, and the JScrollPane to the JApplet, why would the JScrollPane seem to scroll the whole applet and not just the JPanel? I know I'm misunderstanding something here, but I'm not sure what.
Anyway, here's a compilable example that demonstrates what I'm talking about:
import javax.swing.JApplet;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import java.awt.Container;
import java.awt.Color;
public class TestApplet extends JApplet{
public void init(){
JPanel panel = new JPanel();
panel.setSize(1000,1000);
panel.setBackground(Color.GREEN);
JScrollPane scrollPane = new JScrollPane(panel);
Container pane = this.getContentPane();
pane.add(scrollPane);
}
public void start(){}
public void stop(){}
public void destory(){}
}
And here's the applet tag I'm using to launch it in a browser:
<APPLET CODE="TestApplet.class" WIDTH=100 HEIGHT=100>