When the content is made visible, also make sure it's scrolled into view.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@1153 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
ray
2003-06-26 05:55:47 +00:00
parent b231e930a4
commit 5c0a9918a2
@@ -1,10 +1,15 @@
//
// $Id: CollapsiblePanel.java,v 1.7 2003/01/15 00:17:37 mdb Exp $
// $Id: CollapsiblePanel.java,v 1.8 2003/06/26 05:55:47 ray Exp $
package com.samskivert.swing;
import java.awt.EventQueue;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.AbstractButton;
import javax.swing.Icon;
@@ -71,6 +76,24 @@ public class CollapsiblePanel extends JPanel
add(comp);
add(_content = content);
// When the content is shown, make sure it's scrolled visible
_content.addComponentListener(new ComponentAdapter() {
public void componentShown (ComponentEvent event)
{
// we can't do it just yet, the content doesn't know its size
EventQueue.invokeLater(new Runnable() {
public void run () {
// The content is offset a bit from the trigger
// but we want the trigger to show up, so we add
// in point 0,0
Rectangle r = _content.getBounds();
r.add(0, 0);
scrollRectToVisible(r);
}
});
}
});
// and start us out not showing
setCollapsed(true);
}