I am using gridbaglayout and have a 800x600 Japplet. i want it to stay
800x600 but be able to scroll down because i have too many fields to
fit on 600. I tried using the examples java.sun has it won't work.
can someone point to me a very simple example of scrollpane or
scrollbar usage in a JApplet or tell me an easy way to do this?
thewhoracle schrieb:
> I am using gridbaglayout and have a 800x600 Japplet. i want it to stay
> 800x600 but be able to scroll down because i have too many fields to
> fit on 600. I tried using the examples java.sun has it won't work.
> can someone point to me a very simple example of scrollpane or
> scrollbar usage in a JApplet or tell me an easy way to do this?
Try the following in your JApplet:
public void init()
{
JComponent yourLargeComponent = ....;
JScrollPane scrollPane = new JScrollPane();
scrollPane.getViewport().add(largeComponent);
this.getContentPane().add(scrollPane);
}
Note that you must not add directly to the
JScrollPane/JApplet but to their viewport/contentpane.

Signature
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
> I am using gridbaglayout and have a 800x600 Japplet. i want it to stay
> 800x600 but be able to scroll down because i have too many fields to
> fit on 600. I tried using the examples java.sun has it won't work.
> can someone point to me a very simple example of scrollpane or
> scrollbar usage in a JApplet or tell me an easy way to do this?
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.BorderFactory;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class ScrollPanel extends JApplet {
public ScrollPanel() {
createGUI();
}
private void createGUI() {
JPanel gridpane = new JPanel();
gridpane.setLayout(new GridBagLayout());
// Add some components:
for (int r = 0; r < 40; r++) {
for (int c = 0; c < 3; c++) {
JComponent comp = new JLabel("Label " + r + " " + c);
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(0, 6, 6, 0);
gbc.gridx = c;
gbc.gridy = r;
gbc.weightx = 1.0;
switch (c) {
case 0:
gbc.anchor = GridBagConstraints.WEST;
gbc.insets.left = 0;
break;
default:
case 1:
//gbc.anchor = GridBagConstraints.CENTER;
gbc.anchor = GridBagConstraints.WEST;
break;
case 2:
//gbc.anchor = GridBagConstraints.EAST;
gbc.anchor = GridBagConstraints.WEST;
break;
}
gridpane.add(comp, gbc);
}
}
JScrollPane scrollpane = new JScrollPane();
scrollpane.getViewport().add(gridpane);
JLabel statusbar = new JLabel("Status");
statusbar.setBorder(BorderFactory.createLoweredBevelBorder());
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add(new JButton("North"),
BorderLayout.NORTH);
this.getContentPane().add(scrollpane, BorderLayout.CENTER);
this.getContentPane().add(statusbar, BorderLayout.SOUTH);
}
public void destroy() {
super.destroy();
}
public void init() {
super.init();
}
public void start() {
super.start();
}
public void stop() {
super.stop();
}
}

Signature
Regards,
Roland de Ruiter
___ ___
/__/ w_/ /__/
/ \ /_/ / \