[ Back | Previous | Next ]

How to scroll a panel (as a viewport)?

Package:
javax.swing.*
Product:
Swing
Release:
1.1.x
Related Links:
ComboBox
JDialog
JFileChooser
JFrame
JOptionPane
JProgressBar
JScrollPane
JTable
General
JTree
JWindow
KeyStroke
LayeredPane
UIDefaults
Comment:
/**
 * usage: getPanel().add((new ScoobyDoo().createScrollPane(getPanel(), getHetPanel())));
 *
 */
public JScrollPane createScrollPane(Container c, Container content) {
	JScrollPane sp = new JScrollPane(content);
	dbg("\n" + c + "\n" + content);
	c.setLayout(null);
	this.content = content;
	content.setLayout(new LayoutManager() {
		public Dimension preferredLayoutSize(Container c) {
			return new Dimension(167, 305);
		}
		public void layoutContainer(Container c) {
			Rectangle b = c.getBounds();
			ScrollPanel.this.content.setBounds(b);
			System.out.println("layoutCont:" + c);
		}
		public Dimension minimumLayoutSize(Container c) {
			System.out.println("min.layout:" + c);
			return ScrollPanel.this.content.getSize();
		}
		public Dimension preferredLayoutSize(Container c) {
			System.out.println("preferr:" + c);
			return ScrollPanel.this.content.getSize();
		}
		public void removeLayoutComponent(Component c) {
		}
		public void addLayoutComponent(String s, Component c) {
		}
	});
	sp.setBounds(0, 0, c.getSize().width, c.getSize().height);
	sp.validate();
	return sp;
}