首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Java:冻结JFrame上的组件

Java:冻结JFrame上的组件
EN

Stack Overflow用户
提问于 2013-02-19 18:09:52
回答 1查看 1.2K关注 0票数 0

很长时间的潜伏者,第二次海报(它有那么绝望)

我有一个框架,它需要一个接一个地显示12个组件(就好像每个组件都是它自己的列)。第一个组件是属性名称列表,第二个组件显示默认属性,接下来的十个组件都是从数据库中提取的。我想让我的滚动条有效地“冻结”前两个组件(即它总是显示前两个组件),滚动条允许您查看其余条目。这类似于我们冻结列的Excel,类似于here

我已经研究过使用表格,但问题是我的组件不仅仅是文本。他们也有图像之类的东西。

下面是我使用的一些代码

代码语言:javascript
运行
复制
    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

EN

Stack Overflow用户

回答已采纳

发布于 2013-02-19 19:07:03

将冻结的部分放入滚动窗格的行标题中。有关更多信息和示例,请查看how to use scroll panes

票数 2
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14954853

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档