[英]Java: Freezing components on a JFrame
长时间潜伏,第二次海报(它是绝望的)
我有一个框架需要彼此相邻显示十二个组件(就好像每个组件都是它自己的列)。 第一个组件是属性名称列表,第二个组件显示默认属性,接下来的十个组件都是从数据库中提取的。 我希望我的Scroll Bar能够有效地“冻结”前两个组件(即它始终显示前两个组件),滚动条允许您查看其余条目。 这类似于我们冻结列的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
将冻结部分放入滚动窗格行标题中。 检查如何使用滚动窗格获取更多信息和示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.