Hi Robert,

You say that you have a box pane which is in a scroll pane. After you have
completed adding components to the box pane the scroll pane is not scrolling
to the top, i.e. it shows the last added component.

I created a small snippet to test this (see end of this mail). I have a box
pane in a scroll pane and I add number of buttons to the box pane. The
scroll pane always scrolls to the top after all the buttons are added. So
this is contradictory to what you say. Could you please modify the snippet
to demo your case?

Now however, in the snippet, if you don't want the scroll pane to scroll to
the top automatically, i.e., after adding all the components, you want to
scroll to the last added component, you could use scrollToVisible() method.
(Just uncomment the code in the snippet).

I think, even in your case you could invoke scrollToVisible() on the first
component that is added to the box pane in a scroll pane.

I hope this helps.

Thanks and regards,

Janak

>-----Original Message-----
>From: [EMAIL PROTECTED]
>[mailto:[EMAIL PROTECTED] Behalf Of
>[EMAIL PROTECTED]
>Sent: Thursday, July 27, 2006 11:14 AM
>To: [email protected]
>Subject: [ULC-developer] AW: ulcscrollbar --> force to scroll to top -->
>found workaround
>
>
>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

import com.ulcjava.base.application.AbstractApplication;
import com.ulcjava.base.application.BorderFactory;
import com.ulcjava.base.application.ULCBoxPane;
import com.ulcjava.base.application.ULCButton;
import com.ulcjava.base.application.ULCContainer;
import com.ulcjava.base.application.ULCFrame;
import com.ulcjava.base.application.ULCScrollPane;
import com.ulcjava.base.application.event.ActionEvent;
import com.ulcjava.base.application.event.IActionListener;
import com.ulcjava.base.application.util.Color;
import com.ulcjava.base.development.DevelopmentRunner;

public class ScrollToViewTest extends AbstractApplication {
        private ULCBoxPane componentContainer;

    public void start() {
        ULCFrame frame = new ULCFrame("ScrollToViewTest");
        frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);
        frame.setContentPane(createContentPane());
        frame.setSize(300,300);
        frame.setVisible(true);
    }

    private ULCContainer createContentPane() {

        ULCBoxPane container = new ULCBoxPane(true);

        ULCScrollPane scrollPane = new ULCScrollPane();
        scrollPane.setBorder(BorderFactory.createLineBorder(Color.yellow,
3));
        scrollPane.setOpaque(true);
        scrollPane.setBackground(Color.orange);

        componentContainer = new ULCBoxPane();
        componentContainer.setColumns(5);
        componentContainer.setBorder(BorderFactory.createLineBorder(Color.re
d, 3));

        scrollPane.setViewPortView(componentContainer);

        ULCBoxPane buttonBox = new ULCBoxPane(false);

        ULCButton b = new ULCButton("AddButtons");
        b.addActionListener(new IActionListener() {
                        public void actionPerformed(ActionEvent event) {
                ULCButton but = null;
                for (int i=0; i < 50; i++) {
                    but = new ULCButton("Button" + i);
                        componentContainer.add(but);
                    }
                // Uncomment following line to scroll to the last button
                // but.scrollToVisible();
                        }
        });
        buttonBox.add(b);
        ULCButton b1 = new ULCButton("RemoveButtons");
        b1.addActionListener(new IActionListener() {
                        public void actionPerformed(ActionEvent event) {
                        componentContainer.removeAll();
                        }
        });
        buttonBox.add(b1);

        container.add(ULCBoxPane.BOX_EXPAND_EXPAND, scrollPane);
        container.add(ULCBoxPane.BOX_CENTER_CENTER, buttonBox);
        return container;
    }


    public static void main(String[] args) {
        DevelopmentRunner.setApplicationClass(ScrollToViewTest.class);
        DevelopmentRunner.main(args);
    }

 }


_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer

Reply via email to