JScrollBar什么都不做 [英] JScrollBar Doesn't Do Anything
问题描述
我试图在JPanel顶部放置一个垂直的JScrollBar.我可以很容易地添加scoll栏,但是当我运行该程序时,滚动条没有任何作用.我可以上下拖动它,但是JPanel的内容不会移动.我已经阅读了有关如何执行此操作的所有信息,这看起来非常简单,但是显然我缺少一些东西.
I'm trying to put a vertical JScrollBar on top of a JPanel. I can add the scoll bar easily enough, but when I run the program, my scroll bar doesn't have any effect. I can drag it up and down, but the contents of the JPanel don't move. I've read all what I can find about how to do this, and it seems very straightforward, but I'm obviously missing something.
请注意,我的JPanel布局设置为NULL.这是相关的代码.谢谢!
Please note that my JPanel layout is set to NULL. Here is the relevant code. Thanks!
public JDlgResults(ArrayList<AnsweredProblem> probList) {
initComponents();
pnlResults.setLayout(null); //allows free form placing of JLabels
/* Iterate over the ArrayList and add each problem to the results table */
Iterator iter = probList.iterator();
int row = 1;
while(iter.hasNext()) {
addRow(row, iter.next());
row++;
}
JScrollBar jScrollResults = new javax.swing.JScrollBar();
pnlResults.add(jScrollResults);
jScrollResults.setBounds(590, 0, 17, 196);
}
推荐答案
我假设您的initComponents()
方法设置了一堆组件并将其添加到contentPane并建立对话框(无论是对话框还是框架) .
I assume that your initComponents()
method sets up a bunch of components and adds them to your contentPane and establishes your dialog (whether it be dialog or a frame).
仅将您的JScrollPane
添加到该面板将无法解决问题.
Simply adding your JScrollPane
to that panel wont do the trick.
相反,将您的pnlResults
添加到JScrollPane
实例中,并将那个设置为您的contentPane.
Instead, add your pnlResults
to the JScrollPane
instance and make that your contentPane.
这篇关于JScrollBar什么都不做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!