很长时间的潜伏者,第二次海报(它有那么绝望)
我有一个框架,它需要一个接一个地显示12个组件(就好像每个组件都是它自己的列)。第一个组件是属性名称列表,第二个组件显示默认属性,接下来的十个组件都是从数据库中提取的。我想让我的滚动条有效地“冻结”前两个组件(即它总是显示前两个组件),滚动条允许您查看其余条目。这类似于我们冻结列的Excel,类似于here。
我已经研究过使用表格,但问题是我的组件不仅仅是文本。他们也有图像之类的东西。
下面是我使用的一些代码
JPanel info = new JPanel(); // this is the main component (holds the other 12)
info.setLayout(new GridBagLayout()); // GridBag Layoout
info.add(attNames); // add in the attribute names component
info.add(currentCase); // add in the default values
JPanel rets = new JPanel(); // add in the ten retrieved cases
rets.setLayout(new GridLayout(1,10));
for (int i=0;i<maxCases;i++)
{
rets.add(retCase[i]);
}
info.add(rets); // add the return cases to the info component
JScrollPane scrollBar2=new JScrollPane(rets,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); // surround the return cases with a scroll bar
info.add(scrollBar2); // add the scrollbar
//add the info comp to the content pane along with other necessary components
this.getContentPane().add(casesPanel, BorderLayout.NORTH);
this.getContentPane().add(info, BorderLayout.CENTER);
this.getContentPane().add(buttons, BorderLayout.SOUTH);
//finally, add the overall scrollbars and set the size
this.pack();
JScrollPane scrollBar=new JScrollPane(info,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
this.setSize(this.getWidth(), 750);
this.setResizable(true);
this.add(scrollBar);问题是返回的案例的滚动条不认为它是必要的,我必须使用大滚动条,这意味着我可以离开前两个组件。
任何帮助都将不胜感激!
问题就在这里

干杯,K
发布于 2013-02-19 19:07:03
将冻结的部分放入滚动窗格的行标题中。有关更多信息和示例,请查看how to use scroll panes
https://stackoverflow.com/questions/14954853
复制相似问题