长期潜伏者,第二次海报(它有那么绝望)
我有一个框架需要显示十二个组件彼此相邻(好像每个组件都是它自己的列)。第一个组件是属性名称列表,第二个组件显示默认属性,接下来的十个都是从数据库中提取的。我希望我的滚动条能够有效地“冻结”前两个组件(即它始终显示前两个组件),并且滚动条允许您查看其余条目。这与我们冻结列的 Excel 类似,这里是 la 。
我研究过使用表格,但问题是我的组件不仅仅是文本。他们也有图像等。
这是我正在使用的一些代码
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