Frage

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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top