If you want to check if the widget is visible on the scroll bar, you can do it this way (similar to Massi's solution):
private boolean isVisibleInScrollPanel(Widget widget, ScrollPanel scrollPanel) { if (widget != null) { int containerTop = scrollPanel.getAbsoluteTop(); int containerBottom = containerTop + scrollPanel.getOffsetHeight(); int widgetTop = widget.getAbsoluteTop(); int widgetBottom = widgetTop + widget.getOffsetHeight(); return ((widgetBottom <= containerBottom) && (widgetTop >= containerTop)); } return false; }
I used this method as follows:
// When the selected widget is invisible, then we ensure it to be visible if (!isVisibleInScrollPanel(widget, scrollPanel)) { scrollPanel.ensureVisible(widget); }
source share