【问题标题】:Tab content that is scrollable可滚动的标签内容
【发布时间】:2011-03-30 21:33:33
【问题描述】:

我是 Java GUI 的新手,我正在尝试创建一些选项卡,其中包含图像面板。我想修复选项卡的大小并使其可滚动,以便用户可以看到选项卡中的所有内容。有没有办法使选项卡内的内容可滚动?

一个简短的例子会有很大帮助。

非常感谢。

【问题讨论】:

    标签: java user-interface tabs scroll


    【解决方案1】:

    您制作了一个 JTabbedPane,并添加了一个包含 JScrollPane 的面板,其中包含您的图像面板。这可能听起来令人困惑,但它只是一个层次结构:

    JFrame | JTabbedPane | 面板 | 滚动窗格 | 面板 | 图片

    您可以按如下方式初始化您的 JScrollPanel:

    JScrollPane imageScroller = new JScrollPane(myImagePanel); //the panel containing the images
    JPanel scrollPanel = new JPanel(); //make the panel containing the scroller
    scrollPanel.add(imageScroller); //add the scroller to the panel
    myTabbedPane.add(scrollPanel); //make a tab out of it
    

    【讨论】:

    • 谢谢。我已经尝试过了,并添加了一些其他的东西,它奏效了。我想我的错误是我没有让我的内容可滚动。
    【解决方案2】:

    有没有办法让标签内的内容可滚动?

    使用 JScrollPane。有关详细信息,请参阅 Java 教程中的How to Use Scroll Panes

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-19
      • 2020-04-10
      • 2015-02-26
      • 2016-06-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多