Sreenivas Kothapalli
unread,Nov 27, 2010, 8:38:49 AM11/27/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to jmatter
I created a class OnFocusScroller and modified
com.u2d.view.swing.FormView class like this.
public class FormView extends JXPanel implements IFormView
{
....
private OnFocusScroller _scroller;
....
// Added the following code to layItOut() wherever JScollPane is
used
// Note that there are two locations where it is used within the
method.
private void layItOut()
{
....
if (tabbedPane().getTabCount() > 0)
{
....
JScrollPane scrollPane = new JScrollPane(mainPane);
this._scroller = new OnFocusScroller(scrollPane);
tabbedPane().insertTab(_ceo.type().mainTabCaption(), null,
scrollPane, "", 0);
...
}
else
{
// whether the formview is in expandable tree or not, use
scrollpane
JScrollPane scrollPane = new JScrollPane(mainPane);
this._scroller = new OnFocusScroller(scrollPane);
add(scrollPane, BorderLayout.CENTER);
}
}
private void attach(ComplexObject ceo)
{
....
if( this._scroller != null ) {
this._scroller.setScrollingEnabled(true);
}
...
}
private void detach()
{
...
if( this._scroller != null ) {
this._scroller.setScrollingEnabled(false);
}
....
}
}
class OnFocusScroller implements java.beans.PropertyChangeListener
{
JScrollPane _scrollPane = null;
public OnFocusScroller(JScrollPane scrollPane)
{
this._scrollPane = scrollPane;
}
/**
* Enable automatic scrolling on the form.
*
* @param scrollingEnabled enable/disable scrolling
*/
public void setScrollingEnabled(boolean scrollingEnabled)
{
KeyboardFocusManager.getCurrentKeyboardFocusManager()
.removePropertyChangeListener("permanentFocusOwner", this);
if (scrollingEnabled)
{
KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addPropertyChangeListener("permanentFocusOwner", this);
}
}
@Override
public void propertyChange(PropertyChangeEvent evt)
{
if( this._scrollPane == null ) {
return;
}
Component component = (Component) evt.getNewValue();
if (component == null) {
return;
}
// Make sure the component with focus is in the viewport
JComponent view = (JComponent)
this._scrollPane.getViewport().getView();
if (! SwingUtilities.isDescendingFrom(component, view)) {
return;
}
// Scroll the viewport
Rectangle bounds = component.getBounds();
bounds = SwingUtilities.convertRectangle(component.getParent(),
bounds, view);
view.scrollRectToVisible(bounds);
}
}