Need Java Swing equivalent to "scrollIntoView" from DOM browser

I have a JPanel with several levels of child components, also with JScrollPane. I place a focus listener on some child components to add some kind of behavior to these components, but I would also like this component to scroll to the JPanel view when the focus is received.

My question is, does anyone have a general purpose function for this, similar to the browser scroll Do function "scrollIntoView"? I tried to confuse this with various inputs in JComponent.scrollRectToVisible, but I think I did not understand the magic word.

Thanks in advance.

+3
source share
1 answer

scrollRectToVisible on - JScrollPane, , , . scrollRectToVisible , . :

java.awt.Component focusedComponent = evt.getComponent();
panel.scrollRectToVisible(focusedComponent.getBounds(null));
repaint();
+4

Source: https://habr.com/ru/post/1749839/


All Articles