Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4311614
Votes 12
Synopsis findComponentAt() should check for isShowing() instead of isVisible()
Category java:classes_awt
Reported Against 1.2.2
Release Fixed 1.5(tiger)
State 10-Fix Delivered, request for enhancement
Priority: 4-Low
Related Bugs
Submit Date 10-FEB-2000
Description




java version "1.2.2"
Classic VM (build Linux_JDK_1.2.2_RC2, native threads, sunwjit)

findComponentAt( int x , int y ) finds all components which contains the
coordinates x and y and are visible. In some cases the component found is
visible but its parent container isn't, i.e. the component is not showing
on the screen. findComponentAt() should check for isShowing() instead of
isVisible(), see workaround.

The attached workaround may be the solution for the following bug reports, too:
  Bug ID: 4193463 DnD problems in tabbed pane
  Bug ID: 4283790 Container.findComponentAt() behavior does not meet the doc
  Bug ID: 4196100 findComponentAt() not working properly with JTabbedPane
(Review ID: 101070) 
======================================================================
Work Around




Overwrite findComponentAt in your container components:

  public Component findComponentAt(int x, int y) {
    if (!contains(x, y)) {
      return null;
    }
    int ncomponents = this.getComponentCount();
    Component component[] = this.getComponents();
    for (int i = 0 ; i < ncomponents ; i++) {
      Component comp = component[i];
      if (comp != null) {
	Point p = comp.getLocation();
	if (comp instanceof Container) {
	  comp = ((Container)comp).findComponentAt(x - p.x,
						   y - p.y);
	} else {
	  comp = comp.locate(x - p.x, y - p.y);
	}
	if (comp != null && comp.isShowing()) {
	  return comp;
	}
      }
    }
    return this;
  }
======================================================================
Evaluation
See also 4144852 for a similar request.  
  xxxxx@xxxxx   2000-05-16




We suggest some refactoring of source Container.java for better 
productivity removing useless recursions. All the bugs concerned with are not 
reproducible or closed.
There are some bad consequences are possible so more tests need to be run.
======================================================================
Comments
  
  Include a link with my name & email   

Submitted On 04-MAY-2000
mcr3
You might improove performance by in the following way:

   public Component findComponentAt(int x, int y) {
	if (!contains(x, y)) {
	    return null;
	}
        int ncomponents = this.ncomponents;
        Component component[] = this.component;
        for (int i = 0 ; i &lt; ncomponents ; i++) {
            Component comp = component[i];
            if (comp != null) {
		if (comp.isVisible()) {
		    if (comp instanceof Container) {
			comp = ((Container)comp).findComponentAt(x - comp.x,
								 y - comp.y);
		    } else {
			comp = comp.locate(x - comp.x, y - comp.y);
		    }
		    if (comp != null) {
			return comp;
		    }
		}
            }
        }
	return this;
    }

Since you can prune the search-tree by checking the
visibility before making going deeper.



PLEASE NOTE: JDK6 is formerly known as Project Mustang