pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Brown <gk_br...@verizon.net>
Subject Re: How to make middle mousebutton close a closable tab in a TabPane?
Date Fri, 13 May 2011 12:18:02 GMT
You want to do something like this:

Component descendant = tabPane.getDescendantAt(x, y);

if (descendant instanceof TerraTabPaneSkin.TabButton) {
    int tabIndex = descendant.getParent().indexOf(descendant);

On May 13, 2011, at 8:09 AM, Edvin Syse wrote:

> .. or maybe you meant:
> tabs.getTabs().indexOf(descendant.getParent()).. but that returns -1. The parent of descendant
isn't the argument to tabPane.remove(), as far as I understand, the descendant has a child
(in the field member tab) that is the actual component I can remove.
> Den 13.05.2011 14:06, skrev Edvin Syse:
>> Can't get my head around that one... The button is descendant in my example, right?
You want me to call descendant.getParent().indexOf(), but what is the argument to indexOf()?
>> Den 13.05.2011 13:56, skrev Greg Brown:
>>> Again, this is a hack, but since you have the tab button, you can call indexOf()
on the button's parent to get the tab index. That way you don't need to use reflection.
>>> On May 13, 2011, at 7:52 AM, Edvin Syse wrote:
>>>> Got it, thanks :) I had to use reflection to get the correct argument for
tabPane.remove(), does it look right to you?
>>>>        tabPane.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener.Adapter()
>>>>            public boolean mouseClick(Component component, Mouse.Button button,
int x, int y, int count) {
>>>>                Component descendant = tabPane.getDescendantAt(x, y);
>>>>                if (descendant instanceof TerraTabPaneSkin.TabButton&&
 button == Mouse.Button.MIDDLE) {
>>>>                    try {
>>>>                        Field tabField = TerraTabPaneSkin.TabButton.class.getDeclaredField("tab");
>>>>                        tabField.setAccessible(true);
>>>>                        tabPane.getTabs().remove((Component) tabField.get(descendant));
>>>>                    } catch (Exception ignored) {
>>>>                    }
>>>>                }
>>>>                return false;
>>>>            }
>>>>        });
>>>> Den 13.05.2011 13:34, skrev Greg Brown:
>>>>> Since the buttons are effectively private to the tab pane's skin, the
"right" way to do this would probably be to create a custom subclass of TerraTabPaneSkin that
knows about the buttons and can attach a listener to them. However, you could probably hack
support for this by registering a mouse listener on the TabPane itself, then calling tabPane.getComponentAt(x,
y). If the component is an instance of TerraTabPaneSkin.TabButton, then the user has clicked
on the tab button.
>>>>> On May 13, 2011, at 2:53 AM, Edvin Syse wrote:
>>>>>> I would like a middle mousebutton click to close the active tab in
a TabPane, using the same action that happens when one click the X in the tab. Where should
I attach a listener to make this happen?
>>>>>> -- Edvin

View raw message