如何使JTabbedPane自动调整大小以适应页面尺寸? [英] How to make JTabbedPane autoresize to fit page dimensions?

查看:228
本文介绍了如何使JTabbedPane自动调整大小以适应页面尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JFrame中只有JTabbedPane。 JTabbedPane将其尺寸设置为最大页面宽度/高度。
由于页面大小不同,是否可以在选择其他页面时强制JTabbedPane更改其尺寸?

I have only JTabbedPane inside JFrame. JTabbedPane sets its dimensions to biggest page width/height. As pages has different size is it possible to force JTabbedPane to change its dimensions when selecting other page?

http://grab.by/3hIg

排名第一的是它现在的行为方式,最下面一个是我希望它如何表现(我手工调整框架)

Top one is how it behave now and bottom one is how i want it to behave (i resized frame by hand)

推荐答案

我认为另一个选择是动态更改每个面板选项卡选项卡时的选项卡:

I think another option is to dynamically change the panels of each tab when the tab is selected:


  1. JTabbedPane 选择中安装一个监听器

  2. 在每个选项卡上安装一个空面板,但默认情况下选中的选项卡(包含该选项卡的实际面板)
  3. 选择监听器中的



    • 从先前选择的标签中删除面板(即,将其替换为空面板)

    • 更改空白面板新选择的选项卡中的真实面板

    • 在窗口/对话框中调用 pack() g JTabbedPane

  1. install a listener on JTabbedPane selection
  2. install an empty panel on every tab but the selected tab by default (that contains the real panel for that tab)
  3. in the selection listener:
    • remove the panel from the previously selected tab (ie, replace it with an empty panel)
    • change the empty panel by the real panel in the newly selected tab
    • call pack() on the window/dialog containing the JTabbedPane

免责声明:我没有测试过这种方法,但我相信它应该按照你想要的方式工作。

Disclaimer: I haven't tested this approach but I believe it should work according to what you want.

请注意动态改变从纯GUI角度来看,基于所选选项卡的对话框大小不是非常用户友好。

Please also note that dynamically changing the size of the dialog based on the selected tab is not very user-friendly from a pure GUI viewpoint.

这篇关于如何使JTabbedPane自动调整大小以适应页面尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆