开发者

How do I save my JScrollPane position after I do a JFrame.pack()?

开发者 https://www.devze.com 2023-03-12 09:38 出处:网络
I have the following code: JFrame frame = new JFrame(); JScrollPane scrollPane = new JScrollPane(new panel(with stuff in it));

I have the following code:

JFrame frame = new JFrame();
JScrollPane scrollPane = new JScrollPane(new panel(with stuff in it));
frame.getContentPane().add(scrollPane);

So the user scrolls a bit and then clicks a link on my panel and then I do a pack(), so I try the following code:

int val = scrollPane.getVerticalScrollBar().getValue();
frame.pack();
scrollPane.getVer开发者_StackOverflow中文版ticalScrollBar().setValue(val);

But this code still returns my scrollBar back to the beginning instead of keeping the position it was originally at before the pack. Any ideas would be appreciated, Thanks!


Try wrapping the setValue() method in a SwingUtilities.invokeLater().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号