Question

I have a JScrollPane with a View. I'm doing a chat application , it's why i need to have my ScrollBar to the Maximum(). To get the right Maximum of the View i have to validate before. When I validate my ScrollPane an automatic repaint is doing. I don't want this repaint because it makes a double repaint when i set the ScrollBar to the Maximum : when the ScrollBar is at the top and a another when it is a the bottom.

my code :

Main.getWindow().getMainPanel().getScrollPaneCenter().validate();
scrollPaneCenter.getVerticalScrollBar().setValue(scrollPaneCenter.getVerticalScrollBar().getMaximum());

PS : I want to disable the repaint of my conponent or maybe you have a solution to have a reversed JScrollPane( to always have the ScrollBar to Bottom) .

Was it helpful?

Solution

I'm doing a chat application

I'm guessing your are using a a JTextArea or JTextPane.

it's why i need to have my ScrollBar to the Maximum().

You don't need to validate or set the scrollbar manually. You juat append the text to the bottom of the Document. See Text Area Scrolling for a couple of solutions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top