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