Java:JTabbedPane选项卡标题中的JProgressBar(或等效项) [英] Java: JProgressBar (or equivalent) in a JTabbedPane tab title
问题描述
如果我真的想做类似的事情,我可以在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,
我该怎么做?
编辑我确实想把进度条放在标签的标题中,而不是标签本身。
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|
----------- --------------------------------
' '
' '
' '
' '
' '
' '
' '
' '
----------------------------------------------------
所以它真的是tab 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"));
所以你基本上可以简单地替换新的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屋!