This makes JComponent.scrollRectToVisible() behave more elegantly when
there are non-JComponents in the tree. This can be important, because
there actually are some of these even in Swing (like the CellRendererPane).
2006-08-17 Roman Kennke <[EMAIL PROTECTED]>
* javax/swing/JComponent.java
(scrollRectToVisible): Handle intermediate non-JComponents
more gracefully.
/Roman
Index: javax/swing/JComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JComponent.java,v
retrieving revision 1.142
diff -u -1 -2 -r1.142 JComponent.java
--- javax/swing/JComponent.java 29 Jul 2006 22:33:51 -0000 1.142
+++ javax/swing/JComponent.java 17 Aug 2006 15:11:18 -0000
@@ -2568,25 +2568,25 @@
// This is step 4 from above comment. KeyboardManager maintains mappings
// related to WHEN_IN_FOCUSED_WINDOW bindings so that we don't have to
// traverse the containment hierarchy each time.
if (KeyboardManager.getManager().processKeyStroke(current, keyStroke, e))
e.consume();
}
protected boolean processKeyBinding(KeyStroke ks,
KeyEvent e,
int condition,
boolean pressed)
- {
+ {
if (isEnabled())
{
Action act = null;
Object cmd = null;
InputMap map = getInputMap(condition);
if (map != null)
{
cmd = map.get(ks);
if (cmd != null)
{
if (cmd instanceof ActionListenerProxy)
act = (Action) cmd;
@@ -2732,27 +2732,43 @@
RepaintManager.currentManager(this).addInvalidComponent(this);
}
}
/**
* Calls <code>scrollRectToVisible</code> on the component's parent.
* Components which can service this call should override.
*
* @param r The rectangle to make visible
*/
public void scrollRectToVisible(Rectangle r)
{
- Component p = getParent();
- if (p instanceof JComponent)
- ((JComponent) p).scrollRectToVisible(r);
+ // Search nearest JComponent.
+ int xOffs = getX();
+ int yOffs = getY();
+ Component p;
+ for (p = getParent(); p != null && ! (p instanceof JComponent);
+ p = p.getParent())
+ {
+ xOffs += p.getX();
+ yOffs += p.getY();
+ }
+ if (p != null)
+ {
+ r.x += xOffs;
+ r.y += yOffs;
+ JComponent jParent = (JComponent) p;
+ jParent.scrollRectToVisible(r);
+ r.x -= xOffs;
+ r.y -= yOffs;
+ }
}
/**
* Set the value of the [EMAIL PROTECTED] #alignmentX} property.
*
* @param a The new value of the property
*/
public void setAlignmentX(float a)
{
if (a < 0.0F)
alignmentX = 0.0F;
else if (a > 1.0)