hello

I developed a chatting application with GUI.

when the TextArea is full and if any new text is added, the JScrollBar will not scroll
down automatically.

I struggled a lot to make it scroll automaticaly but ended with dashing hopes


how to make the JScollBar to scroll down automatically.


i will be thankful for any help..

Did you try

DefaultCaret caret = (DefaultCaret)textArea.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

?

Did you try

DefaultCaret caret = (DefaultCaret)textArea.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

?

Thanks for your help.

I tried it and its working

but i want the newly added text to be at the top (or somewhere middle but not bottom) of the TextArea.

how to fix it ?

I'm confused. You want to insert the new text (eg) at the top while automatically scrolling to the bottom so the user doesn't see the new text? Maybe we need a more precise description of the desired insert/scroll behaviour.

I'm confused. You want to insert the new text (eg) at the top while automatically scrolling to the bottom so the user doesn't see the new text? Maybe we need a more precise description of the desired insert/scroll behaviour.

the JScrollBAr should be scrolled in such a way that the text should appear in the just below the center of the JTextArea and remaining bottom part leaving empty.

it is not compulsory that the scroll bar should scroll completely bottom

my intention is that the user should see a small lines of space after the end of the appended text.

OK, I understand that, thanks.
But I'm stll confused by
"i want the newly added text to be at the top (or somewhere middle but not bottom) of the TextArea."
or when you said "TextArea"did you mean "scrollpane viewport", and the text is always appended at the bottom of the text area??

You may be able to ensure some space at the bottom by settting a suitably large border...
textArea..setBorder(BorderFactory.createEmptyBorder(2, 2, 60, 2));

OK, I understand that, thanks.
But I'm stll confused by
"i want the newly added text to be at the top (or somewhere middle but not bottom) of the TextArea."
or when you said "TextArea"did you mean "scrollpane viewport", and the text is always appended at the bottom of the text area??

yes i mean the view port

If the border solution doesn't suit, then I guess you will need to move the viewport explicitly down a few lines after appending text.

If the border solution doesn't suit, then I guess you will need to move the viewport explicitly down a few lines after appending text.

how can i move the view port down ??

setValue(..) on the vertical scroll bar.
How did the textarea border idea work? - I like it better.

setValue(..) on the vertical scroll bar.
How did the textarea border idea work? - I like it better.

The textarea border is working but the JScrollBar n is not scrolling down when the border is

added. however the scrollbar scrolls when the text is added.

setValue(..) on the vertical scroll bar.
How did the textarea border idea work? - I like it better.

Here's the picture when i add the border. the border is not visible since the scrollbar doesn't move down

The 1st image is what i am getting when i add the border


But i want my border to be appear as present in the 2nd image..

OK, i guess it's setting the vertical scroll bar value then.
(ps I'm offline now until tomorrow, good luck)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.