Java Code Examples for javafx.stage.Stage#requestFocus()

The following examples show how to use javafx.stage.Stage#requestFocus() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RenameMenuItem.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
	StackPane root = new StackPane();
	primaryStage.setScene(new Scene(root, 300, 250));
	primaryStage.requestFocus();
	primaryStage.show();

	// Get the toolkit
	MenuToolkit tk = MenuToolkit.toolkit();

	// Create the default Application menu
	Menu defaultApplicationMenu = tk.createDefaultApplicationMenu("mars-sim");

	// Update the existing Application menu
	tk.setApplicationMenu(defaultApplicationMenu);

	// Since we now have a reference to the menu, we can rename items
	defaultApplicationMenu.getItems().get(1).setText("Hide all the otters");
}
 
Example 2
Source File: RenameMenuItem.java    From NSMenuFX with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
	StackPane root = new StackPane();
	primaryStage.setScene(new Scene(root, 300, 250));
	primaryStage.requestFocus();
	primaryStage.show();

	// Get the toolkit
	MenuToolkit tk = MenuToolkit.toolkit();

	// Create the default Application menu
	Menu defaultApplicationMenu = tk.createDefaultApplicationMenu("test");

	// Update the existing Application menu
	tk.setApplicationMenu(defaultApplicationMenu);

	// Since we now have a reference to the menu, we can rename items
	defaultApplicationMenu.getItems().get(1).setText("Hide all the otters");
}
 
Example 3
Source File: TestMemoryLeaks.java    From cssfx with Apache License 2.0 6 votes vote down vote up
public static void cleanupFocusedStage() {
    // This is a workaround for https://bugs.openjdk.java.net/browse/JDK-8241840
    Stage stage = new Stage();
    stage.setScene(new Scene(new StackPane()));
    stage.show();
    stage.close();
    stage.requestFocus();
}
 
Example 4
Source File: SampleMenuBar.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
	StackPane root = new StackPane();
	primaryStage.setScene(new Scene(root, 300, 250));
	primaryStage.requestFocus();
	primaryStage.show();

	MenuToolkit tk = MenuToolkit.toolkit();

	MenuBar bar = new MenuBar();

	MenuItem item1 = new MenuItem("Item1");
	MenuItem item2 = new MenuItem("Item2");
	MenuItem item3 = new MenuItem("Mute");
	item3.setOnAction(new EventHandler<ActionEvent>() {
		@Override
		public void handle(ActionEvent event) {
			System.out.println("Muted");
		}
	});

	MenuItem quit = tk.createQuitMenuItem("mars-sim");

	Menu menu2 = new Menu("Menu2");
	menu2.getItems().add(item2);
	
	Menu menu1 = new Menu("Menu1");
	menu1.getItems().addAll(item1, menu2, quit);

	Menu file = new Menu("File");
	file.getItems().addAll(item3);

	bar.getMenus().addAll(menu1, file);

	tk.setMenuBar(primaryStage, bar);

}
 
Example 5
Source File: WaitIndicator.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public WaitIndicator(Stage stage) {	
  	this.stage = stage;
  	//stage = new Stage();
  	indicator = new CircularProgressIndicator();
      StackPane pane = new StackPane(indicator);
      
//stackPane.setScaleX(1.2);
//stackPane.setScaleY(1.2);

      pane.setBackground(Background.EMPTY);
      pane.setStyle(
   		   //"-fx-border-style: none; "
   		   //"-fx-background-color: #231d12; "
      			"-fx-background-color: transparent; "
      			+ 
      			"-fx-background-radius: 1px;"
   		   );
      
      Scene scene = new Scene(pane, 128, 128, true);

scene.setFill(Color.TRANSPARENT);

stage.requestFocus();
      stage.initStyle(StageStyle.TRANSPARENT);
      stage.setTitle("Circular Progress Indicator");
      stage.setScene(scene);
      stage.toFront();
      stage.show();
      
      indicator.setProgress(ProgressIndicator.INDETERMINATE_PROGRESS);
  }
 
Example 6
Source File: WaitIndicatorDemo.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public void start(Stage stage) {
 // public WaitIndicatorDemo(Stage stage) {	
  	this.stage = stage;
  	//stage = new Stage();
  	indicator = new CircularProgressIndicator();
      StackPane pane = new StackPane(indicator);
      
//stackPane.setScaleX(1.2);
//stackPane.setScaleY(1.2);

      pane.setBackground(Background.EMPTY);
      pane.setStyle(
   		   //"-fx-border-style: none; "
   		   //"-fx-background-color: #231d12; "
      			"-fx-background-color: transparent; "
      			+ 
      			"-fx-background-radius: 1px;"
   		   );
      
      Scene scene = new Scene(pane, 128, 128, true);

scene.setFill(Color.TRANSPARENT);

stage.requestFocus();
      stage.initStyle(StageStyle.TRANSPARENT);
      stage.setTitle("Circular Progress Indicator");
      stage.setScene(scene);
      stage.toFront();
      stage.show();
      
      indicator.setProgress(ProgressIndicator.INDETERMINATE_PROGRESS);
  }
 
Example 7
Source File: WaitIndicator.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public WaitIndicator(Stage stage) {	
  	this.stage = stage;
  	//stage = new Stage();
  	indicator = new CircularProgressIndicator();
      StackPane pane = new StackPane(indicator);
      
//stackPane.setScaleX(1.2);
//stackPane.setScaleY(1.2);

      pane.setBackground(Background.EMPTY);
      pane.setStyle(
   		   //"-fx-border-style: none; "
   		   //"-fx-background-color: #231d12; "
      			"-fx-background-color: transparent; "
      			+ 
      			"-fx-background-radius: 1px;"
   		   );
      
      Scene scene = new Scene(pane, 128, 128, true);

scene.setFill(Color.TRANSPARENT);

stage.requestFocus();
      stage.initStyle(StageStyle.TRANSPARENT);
      stage.setTitle("Circular Progress Indicator");
      stage.setScene(scene);
      stage.toFront();
      stage.show();
      
      indicator.setProgress(ProgressIndicator.INDETERMINATE_PROGRESS);
  }
 
Example 8
Source File: SampleMenuBar.java    From NSMenuFX with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
	StackPane root = new StackPane();
	primaryStage.setScene(new Scene(root, 300, 250));
	primaryStage.requestFocus();
	primaryStage.show();

	MenuToolkit tk = MenuToolkit.toolkit();

	MenuBar bar = new MenuBar();

	MenuItem item1 = new MenuItem("Item1");
	MenuItem item2 = new MenuItem("Item2");
	MenuItem item3 = new MenuItem("Item3");
	item3.setOnAction(new EventHandler<ActionEvent>() {
		@Override
		public void handle(ActionEvent event) {
			System.out.println("Item3 clicked");
		}
	});

	MenuItem item4 = tk.createQuitMenuItem("my app");

	Menu menu2 = new Menu("Menu2");
	menu2.getItems().add(item2);
	Menu menu1 = new Menu("Menu1");
	menu1.getItems().addAll(item1, menu2, item4);

	Menu menu3 = new Menu("Menu3");
	menu3.getItems().addAll(item3);

	bar.getMenus().addAll(menu1, menu3);

	tk.setMenuBar(primaryStage, bar);

}
 
Example 9
Source File: TemplateBox.java    From DeskChan with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void requestFocus(){
	Stage win = (Stage) getDialogPane().getScene().getWindow();
	win.toFront();
	win.requestFocus();
}
 
Example 10
Source File: StandardMacApp.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
	StackPane root = new StackPane();
	Button button = new Button();
	button.setText("Create new Stage");
	button.setOnAction(action -> createNewStage());
	root.getChildren().add(button);

	primaryStage.setScene(new Scene(root, 300, 200));
	primaryStage.requestFocus();
	primaryStage.setTitle(mainWindowTitle);
	primaryStage.show();

	MenuToolkit tk = MenuToolkit.toolkit();

	MenuBar bar = new MenuBar();

	// Application Menu
	// TBD: services menu
	Menu appMenu = new Menu(appName); // Name for appMenu can't be set at
										// Runtime
	MenuItem aboutItem = tk.createAboutMenuItem(appName);
	MenuItem prefsItem = new MenuItem("Preferences...");
	appMenu.getItems().addAll(aboutItem, new SeparatorMenuItem(), prefsItem, new SeparatorMenuItem(),
			tk.createHideMenuItem(appName), tk.createHideOthersMenuItem(), tk.createUnhideAllMenuItem(),
			new SeparatorMenuItem(), tk.createQuitMenuItem(appName));

	// File Menu (items TBD)
	Menu fileMenu = new Menu("File");
	MenuItem newItem = new MenuItem("New...");
	fileMenu.getItems().addAll(newItem, new SeparatorMenuItem(), tk.createCloseWindowMenuItem(),
			new SeparatorMenuItem(), new MenuItem("TBD"));

	// Edit (items TBD)
	Menu editMenu = new Menu("Edit");
	editMenu.getItems().addAll(new MenuItem("TBD"));

	// Format (items TBD)
	Menu formatMenu = new Menu("Format");
	formatMenu.getItems().addAll(new MenuItem("TBD"));

	// View Menu (items TBD)
	Menu viewMenu = new Menu("View");
	viewMenu.getItems().addAll(new MenuItem("TBD"));

	// Window Menu
	// TBD standard window menu items
	Menu windowMenu = new Menu("Window");
	windowMenu.getItems().addAll(tk.createMinimizeMenuItem(), tk.createZoomMenuItem(), tk.createCycleWindowsItem(),
			new SeparatorMenuItem(), tk.createBringAllToFrontItem());

	// Help Menu (items TBD)
	Menu helpMenu = new Menu("Help");
	helpMenu.getItems().addAll(new MenuItem("TBD"));

	bar.getMenus().addAll(appMenu, fileMenu, editMenu, formatMenu, viewMenu, windowMenu, helpMenu);

	tk.autoAddWindowMenuItems(windowMenu);
	tk.setGlobalMenuBar(bar);
}
 
Example 11
Source File: MessagePopup.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public void popAMessage(String title, String str, String name, Stage stage, Pos location, Image IMAGE) {
    	//System.out.println("calling popAMessage()");
/*
    	//notifier = Notification.Notifier.INSTANCE;
		//msg = "\"" + wrap(msg, CHARS_PER_LINE-1) + "\"";
		str = wrap(str, CHARS_PER_LINE-1);

		int strSize = str.length();
		int numLines = (int)Math.ceil((double)strSize/CHARS_PER_LINE);

		int nameSize = 0;

		if (name != null)
			nameSize = name.length() + 3;
		else
			nameSize = 0;

		//int remaining = CHARS_PER_LINE * numLines - strSize;
		int index = str.lastIndexOf(System.lineSeparator());//"\n");
		String s = str.substring(index+1, strSize);
		int lastLineLength = s.length();
		int remaining = CHARS_PER_LINE - lastLineLength;

		int numWhiteSpace = 0;
		int new_height = 0;
		int new_width = WIDTH;

		if (strSize < CHARS_PER_LINE) {
			// case 1: the quote is a short one-liner, type the author name on the second line.
			numWhiteSpace = (int)(strSize - nameSize);

			new_width = (int)(strSize * 8) + SIZE_ICON + 15;

			new_height = BASE_HEIGHT + HEIGHT_PER_LINE;

			str += System.lineSeparator();//"\n";

			//System.out.println("Case 1 : quote can fit one line ");
			//System.out.println("# of whitespaces inserted b4 author's name : " + numWhiteSpace);

		}
		else if (remaining > nameSize) {
			// case 2: the author name can be fit to the last line with the quote.
			numWhiteSpace = (int)(remaining - nameSize);

			//new_width = (int)((numWhiteSpace + nameSize) * 7.818);
			//WIDTH = 40 + new_width;

			new_height = BASE_HEIGHT + HEIGHT_PER_LINE * numLines;

			//System.out.println("Case 2 : last line can fit author's name");
			//System.out.println("# of whitespaces inserted b4 author's name : " + numWhiteSpace);
		}
		else {
			// case 3: author name must be on its own line
			numWhiteSpace = (int)(CHARS_PER_LINE - nameSize - 3);

			//new_width = (int)((numWhiteSpace + nameSize) * 7.818);
			//WIDTH = 40 + new_width;

			new_height = BASE_HEIGHT + HEIGHT_PER_LINE * (numLines + 1);

			str += System.lineSeparator();//"\n";
			//System.out.println("Case 3 : last line cannot fit author's name");
			//System.out.println("# of whitespaces inserted b4 author's name : " + numWhiteSpace);
		}


		StringBuffer nameLine = new StringBuffer ("");
		for (int i = 0; i < numWhiteSpace; i++)
			nameLine.append(" ");

		if (name != null)
			nameLine.append("- ").append(name);

		str = System.lineSeparator() + str + nameLine;
*/
        //Duration duration = new Duration(POPUP_IN_MILLISECONDS);
		//notifier.setPopupLifetime(duration);

        notifier.setPopupLifetime(Duration.ZERO);//INDEFINITE);//duration);
        PNotification.Notifier.setNotificationOwner(stage);
        notifier.setPopupLocation(stage, location);
        //PNotification.Notifier.setHeight(new_height);
        PNotification.Notifier.setWidth(100);
        //System.out.println("wait time : " + notifier.getPopupLifetime().toSeconds() + " secs");
        notifier.notify(title, str, IMAGE); //INFO_ICON);
	        //notifier.setNotificationOwner(stage);

		stage.requestFocus();

    }
 
Example 12
Source File: StandardMacApp.java    From NSMenuFX with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
	StackPane root = new StackPane();
	Button button = new Button();
	button.setText("Create new Stage");
	button.setOnAction(action -> createNewStage());
	root.getChildren().add(button);

	primaryStage.setScene(new Scene(root, 300, 200));
	primaryStage.requestFocus();
	primaryStage.setTitle(mainWindowTitle);
	primaryStage.show();

	MenuToolkit tk = MenuToolkit.toolkit();

	MenuBar bar = new MenuBar();

	// Application Menu
	// TBD: services menu
	Menu appMenu = new Menu(appName); // Name for appMenu can't be set at
										// Runtime
	MenuItem aboutItem = tk.createAboutMenuItem(appName);
	MenuItem prefsItem = new MenuItem("Preferences...");
	appMenu.getItems().addAll(aboutItem, new SeparatorMenuItem(), prefsItem, new SeparatorMenuItem(),
			tk.createHideMenuItem(appName), tk.createHideOthersMenuItem(), tk.createUnhideAllMenuItem(),
			new SeparatorMenuItem(), tk.createQuitMenuItem(appName));

	// File Menu (items TBD)
	Menu fileMenu = new Menu("File");
	MenuItem newItem = new MenuItem("New...");
	fileMenu.getItems().addAll(newItem, new SeparatorMenuItem(), tk.createCloseWindowMenuItem(),
			new SeparatorMenuItem(), new MenuItem("TBD"));

	// Edit (items TBD)
	Menu editMenu = new Menu("Edit");
	editMenu.getItems().addAll(new MenuItem("TBD"));

	// Format (items TBD)
	Menu formatMenu = new Menu("Format");
	formatMenu.getItems().addAll(new MenuItem("TBD"));

	// View Menu (items TBD)
	Menu viewMenu = new Menu("View");
	viewMenu.getItems().addAll(new MenuItem("TBD"));

	// Window Menu
	// TBD standard window menu items
	Menu windowMenu = new Menu("Window");
	windowMenu.getItems().addAll(tk.createMinimizeMenuItem(), tk.createZoomMenuItem(), tk.createCycleWindowsItem(),
			new SeparatorMenuItem(), tk.createBringAllToFrontItem());

	// Help Menu (items TBD)
	Menu helpMenu = new Menu("Help");
	helpMenu.getItems().addAll(new MenuItem("TBD"));

	bar.getMenus().addAll(appMenu, fileMenu, editMenu, formatMenu, viewMenu, windowMenu, helpMenu);

	tk.autoAddWindowMenuItems(windowMenu);
	tk.setGlobalMenuBar(bar);
}
 
Example 13
Source File: TopsoilWindow.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
public void loadTopsoilWindow(double x, double y) {

        Pane topsoilPlotUI = topsoilPlot.initializePlotPane();

        Scene topsoilPlotScene = new Scene(topsoilPlotUI, 900, 600);
                
        setScene(topsoilPlotScene);
        
        topsoilPlotWindow = new Stage(StageStyle.DECORATED);

        topsoilPlotWindow.setX(x);
        topsoilPlotWindow.setY(y);
        topsoilPlotWindow.setResizable(true);
        topsoilPlotWindow.setScene(topsoilPlotScene);
        topsoilPlotWindow.setTitle("Topsoil Plot");

        topsoilPlotWindow.requestFocus();
        topsoilPlotWindow.initOwner(null);
        topsoilPlotWindow.initModality(Modality.NONE);

        topsoilPlotWindow.show();

    }