0

I have created scroll pane - everything is working fine, but noticed, that if I add JTextArea as view panel, and if I selecting text with mouse by dragging it outside visible view - my scroll pane do not change it's view position to make cursor/selected text visible. I think JTextArea uses some method to notify scroll pane to change view position in such case. How can I notify my custom scroll pane to change position?

Ernestas Gruodis
  • 8,567
  • 14
  • 55
  • 117
  • 1
    [This question](http://stackoverflow.com/questions/8245328/how-do-i-make-jscrollpane-scroll-to-follow-input-focus) should definitely help you out on this. – Obicere Mar 28 '15 at 19:08
  • Yes, it could be, indeed. My scroll pane does not have the method `scrollRectToVisible` yet. I will try to implement it and will see. – Ernestas Gruodis Mar 28 '15 at 19:11
  • Every `JComponent` has that method available to it. [Documentation](http://docs.oracle.com/javase/7/docs/api/javax/swing/JComponent.html#scrollRectToVisible(java.awt.Rectangle)) – Obicere Mar 28 '15 at 19:12
  • Yes, now I'm overriding it. I made inside it `System.out.println(rectangle);` - and now I see how `JTextArea` calling this method with coordinates. Super, this is an answer, thanks :) I could accept it as an answer if you post it. – Ernestas Gruodis Mar 28 '15 at 19:19
  • Where is your SSCCE that demonstrates the problem??? It could be a mistake just like your last question: http://stackoverflow.com/questions/29237804/setting-jtextfield-selection-foreground-color. Automatic scrolling works fine for me with no special code. – camickr Mar 28 '15 at 19:21
  • No no, I have made scroll pane extending only `JComponent`, so every method here is created by myself here. I'm talking about `JTextArea` (if view is larger than scroll pane vertically), not `JTextField` (which works). – Ernestas Gruodis Mar 28 '15 at 19:26
  • Why are you creating a custom scroll pane? Why are you reinventing the wheel? – camickr Mar 28 '15 at 19:31
  • Looks better, arrows placed as I want, fading, etc, etc.. Freedom at least here :) – Ernestas Gruodis Mar 28 '15 at 19:36

0 Answers0