I\'ve got the next code:
listModel = new DefaultListModel();
listModel.addElement(dateFormat.format(new Date()) + \": Msg1\");
messageList = new
I used JScrollPane
with JTextArea
. I avoided force scroll down by scrolling only when JScrollBar max
value changed:
JScrollPane scrollPane = new JScrollPane(jTextArea);
verticalScrollBarMaximumValue = scrollPane.getVerticalScrollBar().getMaximum();
scrollPane.getVerticalScrollBar().addAdjustmentListener(
e -> {
if ((verticalScrollBarMaximumValue - e.getAdjustable().getMaximum()) == 0)
return;
e.getAdjustable().setValue(e.getAdjustable().getMaximum());
verticalScrollBarMaximumValue = scrollPane.getVerticalScrollBar().getMaximum();
}
);
I suppose, there is better solution to filter events without extra variables, and would appreciate if somebody post it.