Sorry to come back with this ; I recall that I have a main Jpanel associated
to a main JScrollPane and in this mainJPanel a collection of JPanels each
containing a JTree inside and a JScrollPaneOfJtree associated to view the
JTree as desired.
Now I want to be able to display a Jpanel containing a JTree by scrolling
the mainJScrollPane.
As I said earlier I succeeded with the basic method of using a vertical
scrollBar and calculating the position position of the vertical slider.
As someone proposed to use the method ;
scrollRectToVisible(RectangleToBeDisplayed);
I did this (1) :
Rectangle RectangleToBeDisplayed = JScrollPaneOfJtree.getBounds();
then this :
mainJScrollPane.scrollRectToVisible(RectangleToBeDisplayed);
which has no effect at all on the display (claimed JPanel may stay
invisible) but does not bug.
Now if I do this instead which for me does not make sense (2) :
Rectangle RectangleToBeDisplayed = JScrollPaneOfJtree.getBounds();
JscrollPaneOfTJree.scrollRectToVisible(RectangleToBeDisplayed);
Sometimes it works other times it does not ! So it is caotic
Can the method scrollRectToVisible() be applied in the present case and can
I fix (1) to get it working.
Thanks.
From the docs:
"JComponent.scrollRectToVisible
public void scrollRectToVisible(Rectangle aRect)
Forwards the scrollRectToVisible() message to the JComponent's
parent. Components that can service the request, such as JViewport,
override this method and perform the scrolling.
Parameters:
aRect - the visible Rectangle
See Also:
JViewport"
Is the parent of the JPanel a JViewport?
Go back and look at the code example I wrote for you in the previous
thread for how to do this.
--
Knute Johnson
email s/nospam/knute2009/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
>Sometimes it works other times it does not ! So it is chaotic
Sounds like you might be tying up the EDT thread so the event to
scroll the JScrollPane never gets handled.
Look at all your event handlers to make sure the complete very
quickly.
--
Roedy Green Canadian Mind Products
http://mindprod.com
"Patriotism is fierce as a fever, pitiless as the grave, blind as a stone, and as irrational as a headless hen."
~ Ambrose Bierce (born: 1842-06-24 died: 1914 at age: 71)
That might have been me.
> I did this (1) :
> Rectangle RectangleToBeDisplayed = JScrollPaneOfJtree.getBounds();
> then this :
> mainJScrollPane.scrollRectToVisible(RectangleToBeDisplayed);
Don't call scrollRectToVisible on the scroll pane. Call it on the
component you want to make visible. Recall my original answer:
> panelToMakeVisible.scrollRectToVisible(Rectangle(0, 0,
> getWidth(), getHeight());
To understand this behaviour, just read the docs.
It propagates the call to its parent component. It is not even the
JScrollPane which eventually handles it, it is the JViewport.
Cheers,
Simon
Excellent! In Knute's example, replace the first with the second:
1) vp.setViewPosition(panels[n].getLocation());
2) panels[n].scrollRectToVisible(new Rectangle(0, 0, ...));
These have slightly different results when scrolling vertically in a
viewport that is taller than the panel. The former scrolls the panel to
the top of the viewport; the latter scrolls just enough to get the panel
into view.
As an alternative to implementing Scrollable, it's also possible set the
scroll bar's unit increment:
sp.getVerticalScrollBar().setUnitIncrement(...);
<http://java.sun.com/docs/books/tutorial/uiswing/components/
scrollpane.html#scrollable>
--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>