Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / October 2005

Tip: Looking for answers? Try searching our database.

scrollbar question..

Thread view: 
Frances - 07 Oct 2005 04:02 GMT
how do you get scrollbar to go along w/bottom end of text content in a
JTextPane?  i.e., if there is a lot of text in JTextPane I can't see
text at bottom (beyond height of JTextPane..) I have to scroll down to
see where text ends, but I would like scrollbar to 'move' as text is
inserted so end of text is always visible...

I found a JScrollBar class, where I read the following:

  An implementation of a scrollbar. The user positions the knob
  in the scrollbar to determine the contents of the viewing area.
  The program typically adjusts the display so that the end of
  the scrollbar represents the end of the displayable contents,
  or 100% of the contents.

it seems this is what I'm looking for, just can't find how to set this
up..  I mean if I have a JScrollPane that already includes a scrollbar
how do I use/implement this JScrollBar class? (if I need to...  but
don't know if I do..)  thank you..

Frances
Michael Rauscher - 08 Oct 2005 15:42 GMT
Frances schrieb:

> it seems this is what I'm looking for, just can't find how to set this
> up..  I mean if I have a JScrollPane that already includes a scrollbar
> how do I use/implement this JScrollBar class? (if I need to...  but
> don't know if I do..)  thank you..

You don't need to use JScrollBar directly if you use JScrollPane. The
latter displays the scrollbars accordingly to the "scrollbar policy". By
default JScrollPane displays scrollbars as needed.

E.g.

// Test.java
import javax.swing.*;

public class Test {
    public static final void main( String args[] ) {
        JPanel panel = new JPanel();
        panel.add(new JLabel("A Label that is larger than the frame"));
        JFrame frame = new JFrame("Test");
        frame.getContentPane().add(new JScrollPane(panel));
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}
// EOF: Test.java

If you compile and run this class, you'll get a frame that is large
enough to display the whole label. As soon as you set the window to a
little smaller size, the scrollbar(s) get displayed.

Bye
Michael
waqas ahmed - 11 Oct 2005 04:03 GMT
Use the following method:

textArea.setCaretPosition(textArea.getDocument().getLength());

> how do you get scrollbar to go along w/bottom end of text content in a
> JTextPane?  i.e., if there is a lot of text in JTextPane I can't see
[quoted text clipped - 16 lines]
>
> Frances


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.