简体   繁体   中英

Make a particular component visible in a Scrollable JPanel

I have a scrollable JPanel in which are added many Editor Panes (having their respective Scroll Pane) in Box layout (Vertical Axis). My problem is that on clicking a particular button I want a particular Editor Pane to gain focus and also be visible on the screen.

I am unable to make that Editor pane visible.

I tried

scrollRectToVisible(jScrollPane5.getVisibleRect()); //It did nothing !

I also tried

scroller.setViewportView(jScrollPane5); // It made the particular editor pane occupy the entire panel !

Kindly suggest what to do ?

Thanks.

Invoke scrollRectToVisible() on the "Editor Pane" that you want to be visible in the scroll pane.

Also, after clicking on the button it will have focus so you need to use requestFocusInWindow() on the edtitor pane that you want to have focus.

You can also check out Scrolling a Form which will do this for you whenever any component in the scroll pane gets focus.

scrollRectToVisible(theWantedEditorPane.getBounds())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM