Hi *,

i have solved my problem by adding an extension to the ulcscrollbar. it simply 
adds an container listener to the containers of the scrollbar and calls  
scrollbar.setValue(0) any time an component is added. this is done in 
swingutils.invoke later to ensure that the adding process is finished. 
otherwise the adding of the new component forces the scrollpane to scroll down 
again. i know the code itself is maybe not the nicest and most performant but 
it works. any advice, sugestion or help is welcome.

here is my extension class (client):

import java.awt.Component;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;

import javax.swing.SwingUtilities;

import com.ulcjava.base.client.UIComponent;
import com.ulcjava.base.client.UIContainer;
import com.ulcjava.base.client.UIScrollPane;
import com.ulcjava.base.client.UiJScrollPane;
import com.ulcjava.base.shared.internal.Anything;

/**
 * client widget. scrolls always to to if a component is added to an container 
placed in the scrollpane
 * 
 * @author <a href="mailto:[EMAIL PROTECTED]">Robert Munsky</a>
 */
public class UITopScrollableScrollPane extends UIScrollPane {
        /**
         * 
         * [EMAIL PROTECTED]
         */
        protected void addComponent(com.ulcjava.base.client.UIComponent 
component,
                        java.lang.Object constraints, int index) {
                super.addComponent(component, constraints, index);
                if (component instanceof UIContainer) {
                        UIContainer boxPane = (UIContainer) component;
                        ContainerListener containerListener = new 
ContainerListener() {

                                public void componentRemoved(ContainerEvent e) {
                                        tryToScrollToTop();
                                }

                                public void componentAdded(ContainerEvent e) {
                                        tryToScrollToTop();
                                }

                                private void tryToScrollToTop() {
                                        SwingUtilities.invokeLater(new 
Runnable() {

                                                public void run() {
                                                        scrollToTop();
                                                }
                                        });
                                }

                        };
                        
boxPane.getBasicContainer().addContainerListener(containerListener);
                }
        }
        /**
         * konstr
         *
         */
        public UITopScrollableScrollPane() {
                super();
        }

        /**
         * 
         * [EMAIL PROTECTED]
         */
        public void handleRequest(String request, Anything args) {
                if (request.equals("scrollToTop")) { //$NON-NLS-1$
                        scrollToTop();
                } else {
                        super.handleRequest(request, args);
                }
        }

        /**
         * scrollt to top
         * 
         * @author <a href="mailto:[EMAIL PROTECTED]">Robert Munsky</a>
         */
        public void scrollToTop() {
                Component container = getBasicComponent();
                if (container != null && (container instanceof UiJScrollPane)) {

                        final UiJScrollPane scrollPane = (UiJScrollPane) 
container;
                        SwingUtilities.invokeLater(new Runnable() {

                                public void run() {
                                        
scrollPane.getVerticalScrollBar().setValue(0);
                                }

                        });
                }
        }

}
 


> -----Ursprüngliche Nachricht-----
> Von: Munsky, Robert 
> Gesendet: Donnerstag, 27. Juli 2006 09:38
> An: '[email protected]'
> Betreff: ulcscrollbar --> force to scroll to top
> 
> 
> Hello *,
> 
> first of all thanks to the ulc community for the fast and 
> good help. it is very nice to work with the canoo framework 
> and have such a good support and community background. thiis 
> is one reason, beside the technical aspects, which let 
> recommend the framework to other developers.
> 
> after all the nice words there is a question:
> 
> i add dynamicaly a lot of componets to a box pane which lays 
> inside a scrollpane. after adding all comps tzo the inner 
> boxpane the scrollpane always scrolls to the end. thats not 
> what the user expects, he wants to see the beginning. i have 
> tried som methods such as 
>               
> fScrollPane.getVerticalScrollBar().setPosition() and some mor 
> but nothing helps. I think there is some background mecanic 
> which works different. i do not want to try it with native 
> swing and hope to find an answer here. if not i will try it 
> in swing and do an extension to ulc. but i think there must 
> be a way or a workaround as always. maybe someone had the 
> same problem and can deliver a work around or a code snippet?
> 
> Thanks in advance,
> 
> Robert
> 
_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer

Reply via email to