0

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?

rhbvkleef
  • 214
  • 3
  • 12
  • Have a look at [Why JScrollPane does not react to mouse wheel events?](http://stackoverflow.com/questions/12911506/why-jscrollpane-does-not-react-to-mouse-wheel-events). – Braj Mar 22 '14 at 23:26
  • It sounds like you're putting a lot of effort into making your application hard to use. Why work so hard to change the scrolling mechanism that they're used to? – BillRobertson42 Mar 23 '14 at 16:42
  • @bill haha:) yess, It is to make it easier for myself, I basically have 3 scrollpanes that need to be scrolled in sync, I'm doing that automatically, but now i decided to use a simple synchronizer class that transfers the value from 1 scrollbar to the other. get it? probably not... – rhbvkleef Apr 01 '14 at 07:40

1 Answers1

2

Basically when I scroll while the cursor is above the scrollPane, it disables the autoscrolling, which is handled by a JTextArea Caret.

Not sure, but maybe you can use Smart Scrolling.

It disables automatic scrolling when the scrollbar is not at the bottom of the scroll pane.

camickr
  • 321,443
  • 19
  • 166
  • 288