Java:JTabbedPane 选项卡标题中的 JProgressBar(或等效项) [英] Java: JProgressBar (or equivalent) in a JTabbedPane tab title

查看:26
本文介绍了Java:JTabbedPane 选项卡标题中的 JProgressBar(或等效项)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我真的想做这样的事情,我可以在 JTabbedPane 选项卡中放置一个 JProgressBar(或等效的)吗?(我的意思是,不是在选项卡本身中,

If I really wanted to do something like that, can I put a JProgressBar (or it's equivalent) in a JTabbedPane tab? (I mean, not in the tab itself,

我该怎么做这样的事情?

How would I do something like that?

编辑我真的很想将进度条放在选项卡的标题中,而不是选项卡本身.

EDIT I really do want to put the progressbar in the title of the tab, not the tab itself.

这是一些 ascii 艺术:

Here's some ascii art:

----------------------------------------------------
|  Tab 1  || Tab   2||Tab-with-progress-bar||Tab  4|
-----------         --------------------------------
'                                                  '
'                                                  '
'                                                  '
'                                                  '
'                                                  '
'                                                  '
'                                                  '
'                                                  '
----------------------------------------------------

所以它实际上是当前可见的选项卡 2",但我希望进度条(或等效项)在第三个选项卡的标题中可见.

So it's really "tab 2" that is currently visible, but I want the progress bar (or equivalent) to be visible in the third tab's title.

编辑 2

这必须适用于 Java 1.5:这必须适用于无数永远不会配备 Java 6 的 MacOS 10.4 和 MacOS 10.5 Apple 计算机(有些会,有些不会:而且很多永远不会,它不是我的电话)

This has to work on Java 1.5: this has to work on the countless MacOS 10.4 and MacOS 10.5 Apple computers that will never be equipped with Java 6 (some do, some don't: and quite a lot never will, it is not my call)

推荐答案

将 JProgressbar 包含在 JPanel 中,并将该 JPanel 添加到 JTabbedPane.

Enclose the JProgressbar in a JPanel and add that JPanel to the JTabbedPane.

来自 JTabbedPane JavaDoc:

//本例中的自定义组件负责渲染选项卡的标题.

// In this case the custom component is responsible for rendering the title of the tab.

tabbedPane.addTab(null, myComponent); 
tabbedPane.setTabComponentAt(0, new JLabel("Tab"));

因此,您基本上可以简单地将 new JLabel("Tab") 替换为对 JProgressbar 的引用(尽管此 JProgressbar 不得添加到 Tab 本身).但是,我认为 Java 1.6 之前不存在这种方法.

So you could basically simply replace new JLabel("Tab") by a reference to your JProgressbar (though this JProgressbar must not be added to the Tab itself). However, I think this method doesn't exist prior to Java 1.6.

这篇关于Java:JTabbedPane 选项卡标题中的 JProgressBar(或等效项)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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