JScrollPane : Java Glossary

JScrollPane
Allows you to display part of a large JPanel and let the user scroll to see all over it. In AWT (Advanced Windowing Toolkit), you use ScrollPane, and in Swing JScrollPane. There 

Tips

Making Visible

Here is how to make the most recently written part of a JTextArea visible:
Here is how to make a row of JTable visible in the scroll region:
// make part of a JTable visible in the scroll region.
// Must run on Swing thread.
final Rectangle r = jTable.getCellRect( rowIndex, colIndex, true );
if ( r != null )
   {
   jTable.scrollRectToVisible( r );
   }

Gotchas

There is a setViewPosition method defined for JScrollPane, JComponent (of the component being scrolled) and Viewport. Each behaves slightly differently.

Learning More

Oracle’s Javadoc on JScrollPane class : available:

Fighting over the Scroller

Any program that uses JScrollPane has a potential problem if it ever sets the position of the scroll using one of the techniques above. The user may also be trying to scroll at the same time. The program should defer to the user, e.g. if the user has recently moved the scroll, or is holding the thumb bar with mouse right now, defer the scroll move to later, and ignore it entirely if there is another scroll setting. This logic properly belongs in JScrollPane. I wonder if anyone has ever tackled this problem or wants to. There might even be a way to introduce and enhanced JScrollPane into arbitrary programs unaware of the problem, with a L&F.


CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/jscrollpane.html J:\mindprod\jgloss\jscrollpane.html
logo
Please email your , letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email. If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, please quote it and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. Threatening to kill me or spouting obscenities has yet to persuade me to change my mind.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.212]
You are visitor number 25,783.