Menu item to exit a JavaFX application

Hello. I am very new to JavaFX so please forgive what may be an obvious question.

Can anyone provide a code example to create a menu entry for example, file-> exit to quit a JavaFX application?

I can create the menus, but I don't know how to perform the actual output.

Use the setOnAction method? What is the code performs the actual closing of the app?

Thank you.

Tony

Hello. Here is an example:

import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import javafx.scene.control.*;

public class MenuIt extends Application {

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void start(Stage primaryStage) {

        MenuItem menuItem = new MenuItem("Exit");

        final Menu menu = new Menu("File");
        menu.getItems().add(menuItem);

        MenuBar menuBar = new MenuBar();
        menuBar.getMenus().add(menu);

        menuItem.setOnAction(new EventHandler() {

            @Override
            public void handle(ActionEvent e) {
                Platform.exit();
            }
        });

        primaryStage.setTitle("Menu sample");
        Group root = new Group();

        Scene scene = new Scene(root, 300, 250);

        root.getChildren().add(menuBar);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

Tags: Java

Similar Questions

  • Disable the menu item in the third party application (such as Photoshop)

    Please suggest me to disable the menu item in the third party application (such as Photoshop).

    Hello

    I suggest you to send your query to the following link:

    Photoshop Help Center: http://www.adobe.com/support/photoshop/

    Hope this information is useful.

  • Air desktop application: how to make a "BOLD" menu item?

    Hi, I use Flash CS6 to develop a desktop AIR for OSX application. I created my NativeMenu and other Help menu, but I can't find a way to make the first "BOLD" menu item, like a real OSX application. So far, the little I found about it always called Flex, Flash not. Any tips?

    Thank you.

    You can't control how the operating system chooses to display, of NativeMenuItem.

  • 'Settings' menu item disabled - why?

    I have a flash application that makes an audio recording via our fms server on influxis.com. then I do the usual stuff like trying to open a microphone etc. when the charges first app, it tries to find a microphone, but the library says microphone the microphone is muted. also, when I right click on the application, the menu item "Settings"... "is disabled. Why? normally, the user can select a microphone to use through this dialog box. the only way to make it work, it is to open another application that performs video recording, right-click, select 'Settings' (not disabled for this app!) and then set the microphone settings.

    My big question is why the "settings" menu item is disabled for my application?

    any help greatly appreciated

    BHU

    Hi bhu,.

    I was also curious about it so I asked around.  It seems that there is a minimum requirement of width and height for the parameters dialog box to activate.  Try to set the width of your swf > = 215px and height > = 138px.

    Thank you

    Chris

  • How to disable contextual right click menu items.

    Hello

    I am disable some menu items when opening my pdf application.  However, the same menu items are enabled in right click menu popup pop up anywhere in the document.  Can someone let me know how to disable the specific menu items in the right click menu? Also, is there is it possible to disable the whole right click menu shit back in my Pdf?

    Yes, if you know the names of the menus AND they are beyond the real "arise", then you can indeed use them the same way.

  • How to use the script "click menu item" command on a menu item for an application that runs under another user?

    Hey everyone, quick question...

    I am trying to run this script:

    say application "System events".

    say process of "iTunes."

    click on menu item "Start Station" from the menu 'Song' to menu bar item 'Song' in the menu bar 1

    end say

    end say



    The idea behind this is to start a song selected currently playing station. I know, it's not hard to do it manually, but I want to be able to do it without having to call the iTunes app to the front. Now, this script works for my own iTunes app, but I have a second instance of iTunes connecting the second user on my computer at home (User2), with its own separate library and account and all. script I have works fine for an instance of iTunes under my user account, but I can't figure out how to specify which instance of iTunes, I'd like the script to work on.




    I want to emphasize as an FYI that i use.


    the shell script "connection f User2 /Applications/iTunes.app/Contents/MacOS/iTunes > & - 2 > & - &" with administrator privileges

    -to open my second instance of iTunes as User2



    is there a way to change the "process"iTunes"to say" something like 'process 'unix ID' say' and have the ID for each respective instance of iTunes unix?


    Let me know if I do not make sense... Thanks in advance to anyone who can help






    You can target a process of application using various properties of system events, for example:

    tell application "System Events"
      tell first item of (get application processes whose unix id is 15174) -- or whatever id
        activate --> needed when using GUI scripting
        get properties
      end tell
    end tell
    
  • 4.7 deleting application Switch menu item

    Hi all.

    Recently, I tested my app on the simulator of the storm and was surprised to see a new menu item 'native' "Switch application" on my menus.
    Of course, there was the "Show keyboard" I love
    The thing is, I already replace makeMenu to remove native menu items as "Change the input language" but I can't seem to remove the application 'Switch '.
    Still more, if I put a breakpoint in makeMenu, the 'application Switch' and 'See the keyboard' are not present, so I can't delete them

    Manipulation of menu has changed since 4.5 or 4.6?
    How can I remove the 'Switch' application while leaving the "Show keyboard"?

    I'll answer myself:

    The 4.7 introduces another mask of menu option:

    Screen.NO_SYSTEM_MENU_ITEMS
    

    I am yet to discover all the consequences of its use, but id did remove the keyboard and the elements of the application menu.

  • Close application when the application switch menu item to invoke

    Hello, I made application for blackberry (os 5,6,7), but it has a strange behavior.

    When I press the switch application menu item, my request is close, so I can't get back to my application once I switched to another application.

    I have replace my onClose to be like this

    public boolean onClose()
    {
    This.Close ();
    Returns true;
    UiApplication.getUiApplication () .requestBackground ();
    getApplication () .requestBackground ();
    Returns true;
    }

    but the problem remains.

    Please help me solve this problem

    When you change your application, the close method is not pushed directly so I think that you look elsewhere this

    Try to use the Application Switch with an application example - say the sample HelloWorld application.  I think he won't, which suggests that the problem is in your application.

    There are three places to look:

    (a) the Application disable method is pressed when the request is sent to the background.  Maybe you have coded it and it closes the application

    (b) you have a certain type of background processing controls (isForeground()) and reacts according to what it finds.

    (c) in the method onObscured() to one of theFields/screen on the display at once.  .

    Other than that, I think you're looking for a general bug in your application.  The starting point is to look at the debugging log when you do this - look for anything from your application you consider odd.

  • can I add a menu item to the messaging application during execution (after the reading of the object and decide whether to add this menu item or not)?

    Hi all...

    can I add a mail application menu item when running...

    I want to open a mail, depending on its content, I want to decide whether to add an element or not or at least change the name of my customized according to the context of the email...?

    Please help anyone

    still no

  • Delete or remove application menu item switch

    Hello

    I use blackberry api 4.3 for my application and I tested this application in my simulators(9500/9530) api 4.7.

    I don't want to remove all of the default menus (like showkeyboard or hide keyboard, see the symbols, close, switch application).

    I want to delete or remove only switchapplication of the menu item. So is it possible then you can you please give some more

    information about this problem.

    Thank you

    MINDUS

    Sorry, my mistake. You're right, you do not see the menu system default items in makeMenu. Instead, you override getMenu, call super.getMenu () and then search & delete. The ordinal is 268501000 (it's a hack, because this number may change).

    I think you should resolve your question a little differently. I suggest that you add your own Application Switch menu only if the OS does not provide its own, as the point provided operating system will work better.

  • Problem with default system menu item "Switch Application"

    I used the system menu item in my app screen. If I select 'Application Switch', I noticed that my app icon becomes empty. The problem doesn't stop here. If I go back to the home screen and in all cases, my icon of gets too empty.

    The system has lost somehow, the application icon.

    Anyone see this problem and suggestions on how to fix?

    Version of Blackberry 6, 9800 Simulator.

    Thank you

    Sherry

    So you see your application autostart - unless it is enforcement, not UiApplication. Also focus on the method of Application.acceptsForeground - you might want to tinker with it.

    Check all the icons in the 'Application Switch' strip - it will be your main application with an icon as well.

  • How can I replace the opened in the Mail application Menu item?

    Hi all -

    I want to provide my users through the queue of mail message. I receive a message formatted and I know I can add a customized via menu item

    repository.addMenuItem (MENUITEM_MESSAGE_LIST, MyCustomMenuItem);

    but it still requires the user select MyCustomMenuItem.

    I can identify which messages are specific to my application, so I want to replace the menu item open for e-mail messages to call my manager rather than the method of 'open email message"default conditionally.

    Can anyone provide assistance in how to achieve this? Or if this is not considered a best practices approach, what are the alternatives?

    Thanks in advance.

    Dave

    I understand your point.  I think I'd in memory when I responded to your original post,

    Go back and looking at some code:

    You can get a reference to the message using MessageEvent.getMessage ().

    You can then re-evaluate the flags:

    Boolean isOpened = ((mssgFlags & Message.Flag.OPENED) == Message.Flag.OPENED);

    Then you can say 'if the update and isOpened"to determine if the message was opened.

    It seems to work for us.

    I hope this helps.

  • How - add a menu item custom application BlackBerry

    I'm working on an application that creates a custom in various standard Blackberry applications menu item.
    On the platform of v4.2.1.72 8800 2.3.0.54 everything works fine all the Blackberry PIM application that the spectacle of my menu item mail application custom.

    When I load on platform 8330 v4.3.0.124 3.1.0.71 none of the custom menu to the top and on the OS of the Pearl Flip is v4.6.0.48 4.1.0.13 only e-mail and todo/tasks application view my custom menu others do not show my menu item.

    I tried to compile my app in the various versions of the JDE, but always the same question.

    Am I missing something for the new OS?  I followed the knowledge base article "how - to add a custom BlackBerry application menu item.

    I tested it on 8800 v4.5.0.52 platform 2.7.0.66 and Mail and Memo shows no custom menu item in Contacts, calendar and ToDo my custom menu appears.

    Thank you...

    BTW do you know if I can add menu browser and retrieve the content of the web page?

    No, this is not supported.

  • How to remove menu items by default in a Mac Air application

    Hello world

    I have an Air application built in Flash Builder, which runs on Windows, as well as in Mac.

    My application has its own menu bar. In windows, it's OK.

    But in Mac above the menu bar of the application, there is a menu bar by default Mac app with four elements (application, file, Edition, Windows name), which is completely useless.

    I want to remove the menu bar of the Mac by default app.

    Help, please.

    Thanks in advance,

    Jameel

    You can remove them by using the NativeApplication.nativeApplication.menu property to access the native menu.

    import flash.desktop.NativeApplication;

    If {(NativeApplication.nativeApplication.supportsMenu)

    NativeApplication.nativeApplication.menu.removeAllItems ();

    }

    The ASDocs said this removes all menu items, but I imagine that he will allow the "App name" menu on Mac OS computers item so that the user knows which app is currently active and so it can be closed or hidden.

    NativeMenu - Adobe ActionScript® 3 (AS3) QAnywhere

    NativeApplication - Adobe ActionScript® 3 (AS3) QAnywhere

  • Custom menu item at the request of Message: two questions

    I try to add a custom menu to the Blackberry message request and get two questions:

    1. When you click the custom menu, the "Application.getApplication () .requestForeground (); method call does not call the main() method of my application "DemoMI".
    2. If I changed the method of

    Application.getApplication () .requestForeground)

    TO

    ApplicationManager.getApplicationManager () .runApplication (app); Where app is the "DemoMI" application descriptor

    Will be called the main() method. However, how can I make the subject of the Message around in the method "run" for the application "com.demo.DemoApp"?  I tried to use a static variable 'mi ContactsDemoMenuItem', but I've always had "null" value when the "main()" is called.

    My environment:

    • JDE: 4.2.0
    • Feature: Pearl 8100 with OS 4.2.0
    import net.rim.device.api.system.*;
    import net.rim.device.api.ui.component.Dialog.*;
    import net.rim.blackberry.api.menuitem.*;
    import net.rim.blackberry.api.pdap.*;
    import javax.microedition.pim.*;
    import net.rim.blackberry.api.mail.Message;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.component.*;
    import net.rim.device.api.ui.container.*;
    
    public final class DemoMI extends Application
    {
        private static final String ARG_LAUNCH_CONTACT_DEMO = "1";
        private static  ContactsDemoMenuItem mi;
        public static void main(String[] args)
        {
            if(args == null || args.length == 0)
            {
                DemoMI app = new DemoMI();
                app.enterEventDispatcher();
            }else
            {
                String appToLaunch = args[0];
                if(ARG_LAUNCH_CONTACT_DEMO.equals(appToLaunch))
                {
                   new com.demo.DemoApp(mi.getMessage()).enterEventDispatcher();
                }
            }
        }
    
        DemoMI()
        {
            long locationToAddMenuItem = ApplicationMenuItemRepository.MENUITEM_EMAIL_VIEW ;
            ApplicationMenuItemRepository amir = ApplicationMenuItemRepository.getInstance();
            ApplicationDescriptor app = ApplicationDescriptor.currentApplicationDescriptor();
    
            app = new ApplicationDescriptor(app, new String[]{ARG_LAUNCH_CONTACT_DEMO});
            mi = new ContactsDemoMenuItem(app);
            amir.addMenuItem(locationToAddMenuItem, mi);
            System.exit(0);
        }
    
        private static class ContactsDemoMenuItem extends ApplicationMenuItem
        {
            ApplicationDescriptor app;
            Message msg;
            ContactsDemoMenuItem(ApplicationDescriptor app)
            {
                super(20);
                this.app = app;
            }
    
            public String toString()
            {
                return "My Menu Item";
            }
    
            public Message getMessage()
            {
                return msg;
            }      
    
            public Object run(Object context)
            {
                if ( context instanceof Message )
                {
                    msg = (Message)context;
                    try
                    {
    
                        Application.getApplication.requestForeground();
                        //ApplicationManager.getApplicationManager().runApplication(app);
                    }catch(Exception e)
                    {
                        e.printStackTrace();
                    }
    
                 } else
                 {
                    throw new IllegalStateException( "Context is null, expected a Contact instance");
                 }
                 return null;
            }
        }
    }
    

    What you see is the expected behavior.  The ApplicationMenuItem runs in a different process where your application was run.  You have two options.

    You can store the subject of the Message in the RuntimeStore when the ApplicationMenuItem is called.  Your application you are undertaking could then read the subject of the Message of the RuntimeStore.

    Or you can create an application based on the drawing below:

    How to allow - a listener in the background to detect and update a GUI application
    Article number: DB-00406

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800783/How_To _...

Maybe you are looking for

  • WiFi starts to turn on and off

    Every 15 minutes, my wireless starts to turn on and off repeatedly at a fast rate. I mean, it turns off and then over time offshore on a second and repeat this until I put the computer to sleep, then wake it back up. It of really annoying and makes t

  • Really quick question on Rockbox...

    Should this firmware Rockbox install?  I finally found my rocket and the warranty expired so finally I decided to Rockbox it.  He wants a different firmware from 01.02.31.  Which should I use?

  • Organization of the CSA

    I'm looking for some tips on how to better organize the policies, the Modules of the rule and the rules. Specifically, is it better to create more policy, rule or rules Modules.

  • Pale Moon browser keeps closing

    I use pale Moon because firefox is not 64-bit based but it keeps crashing any advice welcome

  • How do you uninstall creative cloud of my laptop to put it on another laptop?

    My creative cloud is on my laptop but I I just got a mac book pro and I would so move the program on my new mac, how do I have remove from my old laptop?