I am working on a little Swing application and I want to disable all possible scrolling in a scrollpane but autoscroll. The code i have is below:
private void removeScrollBar(JScrollPane scrollPane){
scrollPane.setBounds(10, 35, 250, 525);
scrollPane.setBackground(new Color(1, 0, 0, 0));
scrollPane.getVerticalScrollBar().setPreferredSize(new Dimension(0, 0));
scrollPane.getViewport().setBorder(null);
scrollPane.setViewportBorder(null);
scrollPane.setBorder(null);
scrollPane.setWheelScrollingEnabled(false);
}
Basically when I scroll while the cursor is above the scrollPane, it disables the autoscrolling, which is handled by a JTextArea Caret. The code for that is below:
((DefaultCaret) textArea.getCaret()).setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
How can I fix this?