使用 JTabbedPane 重叠选项卡
使用 JTabbedPane,我们想要实现一个要求选项卡重叠的设计(如图所示,可以在此处找到:http:// imm.io/YAZ)。
不完全是火箭科学,但我似乎找不到解决方案(即使在广泛的谷歌搜索之后也找不到)。
使用 JTabbedPane(也许通过 PLAF)可以实现这一点吗?还是我们需要编写自定义组件?
谢谢
托马斯
Using JTabbedPane we want to implement a design that requires tabs to be overlapping (illustrated in image that can be found here: http://imm.io/YAZ).
Not exactly rocket science, but I can't seem to find a solution (not even after extensive googling).
Is this possible using JTabbedPane (via PLAF maybe) or do we need to write a custom component?
Thanks
Tomas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,它需要一个自定义组件。我认为这可以通过扩展 JTabbedPane 并插入新类型的选项卡来完成。
使其重叠的方法是最后调用所选选项卡上的paintComponent方法,即它将最接近视图的前面。
至于重叠选项卡类,您可以在代码中使用几乎任何 JComponent 子类。您甚至可以使用透明 PNG 作为背景来设置主题,并在选项卡本身上调用 public void setOpaque(boolean isOpaque)。
As far as I know it requires a custom component. I think it can be done by extending the JTabbedPane and inserting a new type of tab.
The way you make it overlap is by calling the paintComponent method on the selected tab last i.e. it will be closest to the front of the view.
As for the overlapping tab class you can make use of almost any JComponent subclass for your code. You can even theme it with transparent PNG's as background and calling public void setOpaque(boolean isOpaque) on the tab itself.
通过在自定义 UI 实现中覆盖 PaintTab 并将前一个选项卡的一部分绘制到下一个选项卡上来解决此问题。这是可能的,因为 PaintTab 允许您在整个选项卡区域上绘制,而不仅仅是在当前正在绘制的选项卡的边界内。例如,如果我们有选项卡 A、B 和 C:
选项卡 A 绘制其左边框和中心填充。
选项卡 B 绘制其左边框、中心填充,然后绘制选项卡 A 的右边框。
选项卡 C 绘制其左边框、中心填充、选项卡 B 的右边框,然后绘制其自己的右边框(因为这是窗格中的最后一个选项卡)。
然后以稍微不同的方式处理选定的选项卡。
上述解决方案实施起来并不难,而且效果很好。
Solved this by overriding paintTab in a custom UI implementation and painting part of the previous tab over the next. This was possible since paintTab allows you to paint over the entire tab area, not solely in the bounds of the tab it was currently painting. Example, if we have tabs A, B and C:
Tab A paints its left border and center fill.
Tab B paints its left border, center fill and then tab A's right border.
Tab C paints its left border, center fill, Tab B's right border and then it's own right border (since this is the last tab in the pane).
Then handle selected tabs slightly differently.
The above solution was not hard to implement and works very well.