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 / September 2004

Tip: Looking for answers? Try searching our database.

JTextArea Scrolling Problem

Thread view: 
Eric - 06 Sep 2004 18:10 GMT
Scenario: I have a utility which uses a JTextArea to capture real-time
events
--------- from applications on our system so that users can see what
is going
         on at any instant and they can also scroll through previous
event
         messages in the JTextArea.  It currently works such that new
messages
         are displayed at the bottom of the JTextArea and the
scrollbar keeps up
         with it.  Which is the desired response if the user has NOT
scrolled
         back up the list. The problem I am trying to solve is stated
below.

Problem: If the user has scrolled to a previous message (up the list)
and new -------- real-time event messages come in, they reset the
scrollbar to the end
        (the bottom) of the list.  This pisses off the user, as you
can
        understand.  

Desirement:  What I would like to occur is that if the user has
scrolled up the -----------  list for the scrollbar to remain at the
position in the list as new
            event messages are appended to the end of the list in the
JTextArea.

Questions: Has anyone ever done this?  Or does anyone know how to do
this?  ---------  Suggestions?

Code:
-----
Below is a listing (non-compilable) of the code that should give you
an idea of what I am doing.

JTextArea EventWin;
EventWin = new JTextArea();

JScrollPane scrollPane;
scrollPane = new JScrollPane(output);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

String event;
BufferedReader EventBuf;
EventBuf = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()), 1000);

event = EventBuf.readLine();

while(event != null)
{
  event = EventBuf.readLine();
  EventWin.append(event + newline);
  EventWin.setCaretPosition(EventWin.getDocument().getLength());
}

Thanks,
--Eric
Paul Lutus - 06 Sep 2004 18:43 GMT
> Scenario: I have a utility which uses a JTextArea to capture real-time
> events
> --------- from applications on our system so that users can see what
> is going
>           on at any instant and they can also scroll through previous
> event

1. Fix your newsreader. Your post is unreadable.

2. Read and save the position of the JScrolllBar that is responsible for the
location in the JTextArea.

3. Add the required text.

4. Restore the saved JScrollBar position.

> Below is a listing (non-compilable) of the code that should give you
> an idea of what I am doing.

Not if it is non-compilable.

Signature

Paul Lutus
http://www.arachnoid.com



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.