Skip to main content

Auto scroll down in container

7 replies [Last post]
iluminacja
Offline
Joined: 2010-01-08
Points: 0

Hi guys,

I would like to make auto scroll down in my container, how can I do that? This container shuldn't be focusable. I have heard about something like scrollRectToVisible, but I didn't realise how it works in some example. Could you help me?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
iluminacja
Offline
Joined: 2010-01-08
Points: 0

Ok, mayby another question. There is possible to set max size for container? I mean, max visible size? Because althaugh my container is scrollable, it stretch to the whole display. If I put this to a Form, with BorderLayout to Centre, it will fill the BorderLayout.North area too. And of course, why if I set rect which I want to visible, it doesn't work? Everytime, it scroll down, just I except, but it also streched in vertical. For example, my component(container) at first occupy dimension (100,200). So my rect to visible is 0,0,100,200. To scroll down, when my container have dimension (100,400), I set my rect to (0,200,100,200), so I expect to see bottom part of my component. But that doesn't happen. I see bottom part, but unfortunately vissible is for example rect (0,100,100,300). So my container curtain the other component in my Form. There is any possible solution? Sorry for spam, but this is very important to me. Withaut this, I cant continue my project :(

myinstinct
Offline
Joined: 2008-10-24
Points: 0

"If I put this to a Form, with BorderLayout to Centre, it will fill the BorderLayout.North area too."

Something else must be wrong here - BorderLayout is designed to stretch the CENTER to fill all unused areas - if it's filling the NORTH, then it must be empty.

maybe as a test, leave out the CENTER and see if the NORTH shows up

myinstinct
Offline
Joined: 2008-10-24
Points: 0

"if it's filling the NORTH, then it must be empty."

OR

maybe you are painting over it

iluminacja
Offline
Joined: 2010-01-08
Points: 0

[b]EDIT:[/b] Omg, now I know what is wrong. I have forgotten to invoke this.setScrollable(true). That is default to Form but not to my container :)

Message was edited by: iluminacja

iluminacja
Offline
Joined: 2010-01-08
Points: 0

Hi again,

I did that functionality in very simple way, but I am not sure that it is enough eficient. Here is my code :

public void scrollDown()
{
rect = new Rectangle(getScrollX(), getScrollY(), getWidth(), this.getLayoutHeight());
this.scrollRectToVisible(rect, this);
this.repaint();
}

But, I supposse that in this way I repaint whole content pane but it is not necessary, because I see only part of it. So, if I calculated parameters to rect, wchich are already visible, and then use repaint() it would be more efficient?

vprise
Offline
Joined: 2003-11-07
Points: 0

You will always need to repaint the entire form when scrolling it.

iluminacja
Offline
Joined: 2010-01-08
Points: 0

Hi , I am exhausted looking for answer to my question. Functionality which I made works, but only if this container is the only one component in my Form. If I i add three Component in this way

addComponent(BorderLayout.SOUTH,new TextField());
addComponent(BorderLayout.NORTH,new Label("xxxx"));
addComponent(BorderLayout.CENTER,);

south component works (to be honest, I dont know why), but north component is hiden by container. Could someone help me to solve this problem? And of course if its necessary to understand my problem, I can write here my code. And how use or maybe how override method scrollRectToVisible()?