Simple Validation API small Icon Position Lossed

  3 posts   Feedicon  
Replies: 2 - Last Post: February 21, 2012 20:18
by: Fitzgerald
showing 1 - 3 of 3
 
Posted: January 24, 2012 09:42 by malikbadar
1- Small icon not disappear when panel removed.
2- if the text component is inside the scroll pane, and if icon of incorrect value appears, it will not readjust its position with movement of scroll bar as text component does.
Below code works when component is resized only but not move.
decoratedComponent.addComponentListener(new ComponentAdapter() {

@Override
public void componentMoved(ComponentEvent evt) {
tryDecorationIcon();
}

@Override
public void componentResized(ComponentEvent evt) {
tryDecorationIcon();
}
});
 
Posted: February 21, 2012 01:55 by Fitzgerald
I'm having the same issue. Is there any hope of a fix? I tried a few work-arounds, but I am not very experienced with Swing, so I had no luck.

Thanks,

Stephen
 
Posted: February 21, 2012 20:18 by Fitzgerald
I think I fixed it!

In the constructor for ToolTippedIconLabel I checked the decoratedComponent's enclosing containers and added a change listener to the JViewport, if I found one.

That fixed the scrolling issue, but then the icons were drawn, even when they were scrolled out of the window, so I added a check of the JViewport's viewRect to see if the icon was truly supposed to be visible, and if not, set the icon to null and returned false from tryDecorationIcon().

It's not well tested, but it seems to work in my Netbeans platform application with scrolling views...

The changes are all in org.netbeans.validation.api.ui.swing.SimpleDefaultDecorator.java:

In ToolTippedIconLabel constructor, right after the ComponentAdapter is added :

decoratedComponent.addComponentListener(new ComponentAdapter() {
...
});

/*
* ================================================================
* SBF 21 Feb 12 - Add a change listener to the containing JViewport, if found.
* This forces a redraw if the decoratedComponent is scrolled.
*/
JViewport viewPort = getViewPortFor(decoratedComponent);
if (viewPort != null) {
((JViewport) viewPort).addChangeListener(new ChangeListener() {

@Override
public void stateChanged(ChangeEvent e) {
tryDecorationIcon();
}
});
}
/*==================== End : SBF - 21 Feb 12 ==================*/

At the very end of ToolTippedIconLabel.tryDecorationIcon(), just before returning true:

/*
* ===============================================================
* SBF 21 Feb 12 Only draw the icon if it has not been scrolled out of visiblity.
*/

JViewport viewPort = getViewPortFor(decoratedComponent);
if (viewPort != null) {

int iconWidth = this.getIcon().getIconWidth();
int iconHeight = this.getIcon().getIconHeight();

Point iconPos = new Point(decoratedComponent.getLocation());
iconPos.translate(transl.x, transl.y);
Rectangle iconRect = new Rectangle(iconPos.x, iconPos.y, iconWidth, iconHeight);

Rectangle viewPortRect = viewPort.getViewRect();
Rectangle visRect = iconRect.intersection(viewPortRect);

if (visRect.height <= iconHeight / 2 || visRect.width <= iconWidth / 2) {
this.setIcon(null);
return false;
}
}
/*
* ================== End: SBF 21 Feb 12 =========================
*/

return true;
}

I also added a convenience method to ToolTippedIconLabel to find the enclosing JViewport of a JComponent:

/*
* ====================================================================
* SBF 21 Feb 12 Find the JViewport that contains a JComponent
*/
private JViewport getViewPortFor(JComponent comp) {
Container c = comp.getParent();
while (c != null && !(c instanceof JViewport) && !(c instanceof RootPaneContainer)) {
c = c.getParent();
}
return c instanceof JViewport ? (JViewport) c : null;
}
/*
* ==================== End : SBF - 21 Feb 12 =========================
*/
Replies: 2 - Last Post: February 21, 2012 20:18
by: Fitzgerald
  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120518.3c65429)
 
 
Close
loading
Please Confirm
Close