JTabbedPanes中的JToolBars;(JToolBars in JTabbedPanes; incorrect tab name when docked and undocked)

编程入门 行业动态 更新时间:2024-10-22 11:33:47
JTabbedPanes中的JToolBars;(JToolBars in JTabbedPanes; incorrect tab name when docked and undocked)

我对事件监听和GUI很新,所以我很难搞清楚这一点。

我有一个JTabbedPane,我添加了3个组件。 这些组件是JToolBars,它允许我将它们从JTabbedPane拖到浮动窗口中。 这将从选项卡式窗格中删除选项卡。 当我将JToolBar拖回窗格时,将重新创建选项卡。 但是,它现在的名称不正确。 该名称对应于ToolBar停靠的TabbedPane的哪一侧; 北,南,东或西。

任何人都可以推荐一种正确的方法来检测JToolBar是否已被重新锁定,然后更新标签标题? 到目前为止,我已经在tabbedPane上实现了一个更改侦听器,但无法计算出合适的事件。

干杯。

已解决:解决方案是使用ContainerListener来检测通过实现的componentAdded方法添加的组件。 当一个组件被添加到JTabbedPane时,我调用了一个方法,用组件名称更新选项卡名称,通过.setName()设置。

public void componentAdded(ContainerEvent added) { updateTabs(); } public void updateTabs() { for (int i = 0; i < tabbedPane.getComponents().length; i++) { tabbedPane.setTitleAt(i, tabbedPane.getComponents()[i].getName()); } }

I'm quite new to event listening and GUI's, so am having trouble figuring this out.

I have a JTabbedPane to which I have added 3 components. These components are JToolBars, which allows me to drag them out of the JTabbedPane into a floating window. This removes the tab from the tabbed pane. When I drag the JToolBar back into the pane, the tab is recreated. However, it now has an incorrect name. The name corresponds to which side of the TabbedPane the ToolBar was docked to; North, South, East or West.

Can anyone recommend a decent way of detecting that a JToolBar has been redocked and then updating the tab title? Thus far I've implemented a change listener on the tabbedPane, but cannot work out a suitable event.

Cheers.

SOLVED: The solution was to use a ContainerListener to detect a component added through the implemented componentAdded method. When a component was added to the JTabbedPane, I called a method to update the tab names with the components name, set via .setName().

public void componentAdded(ContainerEvent added) { updateTabs(); } public void updateTabs() { for (int i = 0; i < tabbedPane.getComponents().length; i++) { tabbedPane.setTitleAt(i, tabbedPane.getComponents()[i].getName()); } }

最满意答案

解决方案是使用ContainerListener来检测通过实现的componentAdded方法添加的组件。 当一个组件被添加到JTabbedPane时,我调用了一个方法,用组件名称更新选项卡名称,通过.setName()设置。

public void componentAdded(ContainerEvent added) { updateTabs(); } public void updateTabs() { for (int i = 0; i < tabbedPane.getComponents().length; i++) { tabbedPane.setTitleAt(i, tabbedPane.getComponents()[i].getName()); } }

The solution was to use a ContainerListener to detect a component added through the implemented componentAdded method. When a component was added to the JTabbedPane, I called a method to update the tab names with the components name, set via .setName().

public void componentAdded(ContainerEvent added) { updateTabs(); } public void updateTabs() { for (int i = 0; i < tabbedPane.getComponents().length; i++) { tabbedPane.setTitleAt(i, tabbedPane.getComponents()[i].getName()); } }

更多推荐

本文发布于:2023-08-04 23:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1423329.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:incorrect   JToolBars   JTabbedPanes   undocked   docked

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!