简体   繁体   中英

How to make 2 JPanels scroll at the same time?

I am displaying a table in a scrollable JPanel, and I also have a JPanel with the column titles that are also buttons to sort by the columns. I do this so the titles stay fixed while you scroll down the table. I want the buttons panel to extend to the width of the table panel, and to scroll alongside the table panel. How would I go about doing this?

If I understood you right, you have 2 JPanels in JScrollPanes that you want to scroll horizontally at the same time

the only solution I could think of is make one of the JScrollPanes use the other JScrollPanes' horizontal model

JScrollPane sp1 = new JScrollPane(panel1);
JScrollPane sp2 = new JScrollPane(panel2);
sp2.getHorizontalScrollBar().setModel(sp1.getHorizontalScrollBar().getModel());

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