[英]show vertical scrollbar of jscrollpane at the top
I have a JScrollPane containing a JPanel.JPanel consist of one JCombobox,one JTextfield,4 JTextarea whose values are depend on selected item in combobox. 我有一个包含JPanel.JPanel的JScrollPane,它由一个JCombobox,一个JTextfield,4 JTextarea组成,其值取决于组合框中的选定项。 Problem is vertical scrollbar of scrollpane always start at the bottom. 问题是滚动窗格的垂直滚动条始终从底部开始。
I tried with 我尝试过
scrollPane.getVerticalScrollBar().setValue(0);
and also tried with 并尝试了
scrollPane.getViewport().setViewPosition(new Point(0,0));
but nothing seems work.Any help would be appreciated. 但似乎无济于事。任何帮助将不胜感激。
Wrap the call scrollPane.getVerticalScrollBar().setValue(0);
包装呼叫scrollPane.getVerticalScrollBar().setValue(0);
in SwingUtilities.invokeLater() to let content layout be done first. 在SwingUtilities.invokeLater()中,先进行内容布局。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.