pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oliver Oyston" <Oliver.Oys...@actian.com>
Subject RE: Dialog opened from menu loses focus
Date Fri, 15 Feb 2013 16:52:52 GMT
I worked around the problem using a custom skin - perhaps not the most
elegant solution but it works...

The custom skin is registered at an appropriate place (application
startup / constructor / etc).

// Use a customized skin for menu items
theme.set(Menu.Item.class, CustomMenuItemSkin.class);

Our main class exposes the mainWindow like this:

 * The main application window (top-level Pivot object).
@BXML public static Window mainWindow;

I renamed our main class to "MainClass" in the snippet below - you will
need to implement this as appropriate for your application or alter the
skin to make it more generic

package your.package.name.here;

import org.apache.pivot.util.Vote;
import org.apache.pivot.wtk.Component;
import org.apache.pivot.wtk.Container;
import org.apache.pivot.wtk.Menu;
import org.apache.pivot.wtk.MenuPopup;
import org.apache.pivot.wtk.MenuPopupStateListener;
import org.apache.pivot.wtk.Mouse;
import org.apache.pivot.wtk.skin.terra.TerraMenuItemSkin;

 * Custom skin to ensure that the transition effects of the context menu
does not cause the stealing of focus from dialogs.
public class CustomMenuItemSkin extends TerraMenuItemSkin {

    public boolean mouseUp(Component component, Mouse.Button button, int
x, int y) {
        boolean consumed = super.mouseDown(component, button, x, y);

        Menu.Item menuItem = (Menu.Item)getComponent();

        if (menuItem.isActive()) {

            MenuPopup popup;

            // Find the first MenuPopup container for the component.
            Container container = component.getParent();

            do {
                if (container.getClass() == MenuPopup.class){

                    // We found a menu popup
                    popup = (MenuPopup)container;

                    // Disable the main window.

MenuPopupStateListener() {
                        public Vote previewMenuPopupClose(MenuPopup
components, boolean b) {
                            return Vote.APPROVE;

                        public void menuPopupCloseVetoed(MenuPopup
components, Vote vote) {


                        public void menuPopupClosed(MenuPopup
components) {
                            // Enable the main window.

                            // Remove listener.

                    // Break out of the loop.
            while ((container = container.getParent()) != null);

            // Execute the menu press

        return consumed;

Hope this helps.


-----Original Message-----
From: Jumbo [mailto:p_kowshik@yahoo.com] 
Sent: Friday, February 15, 2013 2:35 AM
To: user@pivot.apache.org
Subject: RE: Dialog opened from menu loses focus

Hi Roger,

Is it possible for you to share how you have resolved this issue by
sub-classing the menu and disabling the transition animations?


View this message in context:
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

View raw message