Java Code Examples for javafx.scene.control.Button#setText()

The following examples show how to use javafx.scene.control.Button#setText() . 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: ModalDialogDemo.java    From oim-fx with MIT License 6 votes vote down vote up
@Override
public void start(final Stage primaryStage) {
    primaryStage.setTitle("Hello World");
    ModalDialog md = new ModalDialog(primaryStage);
    
    Group root = new Group();
    Scene scene = new Scene(root, 500, 450, Color.LIGHTBLUE);
    Button btn = new Button();
    btn.setLayoutX(250);
    btn.setLayoutY(240);
    btn.setText("Show modal dialog");
    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
        	md.show();
        }
    });
    root.getChildren().add(btn);
    primaryStage.setScene(scene);
    primaryStage.show();
}
 
Example 2
Source File: HelloWorld.java    From JavaExercises with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Hello World!");
    Button btn = new Button();
    btn.setText("Say 'Hello World'");
    btn.setOnAction(new EventHandler<ActionEvent>() {
         @Override
        public void handle(ActionEvent event) {
            System.out.println("Hello World!");
        }
    });
    StackPane root = new StackPane();
    root.getChildren().add(btn);
    primaryStage.setScene(new Scene(root, 300, 250));
    primaryStage.show();
}
 
Example 3
Source File: Main.java    From NativeJDK9AppTemplate with Apache License 2.0 6 votes vote down vote up
@Override
public void start(Stage primaryStage) {
    
    // create a button 
    Button btn = new Button();
    btn.setText("Say 'Hello World'");
    
    // define action (btn clicked)
    btn.setOnAction((ActionEvent event) -> {
        primaryStage.setTitle("Button Pressed at " + new Date());
    });
    
    // container element for the button
    StackPane root = new StackPane();
    root.getChildren().add(btn);
    
    // main scene
    Scene scene = new Scene(root, 450, 250);
    
    // configure & display stage
    primaryStage.setTitle("Hello World!");
    primaryStage.setScene(scene);
    primaryStage.show();
}
 
Example 4
Source File: testScheduledExecutorService.java    From JavaFX with MIT License 6 votes vote down vote up
@Override
public void start(Stage primaryStage) {
	Button btn = new Button();
	btn.setText("Start ScheduledExecutorService");
	btn.setOnAction(new EventHandler<ActionEvent>() {
		@Override
		public void handle(ActionEvent event) {
			startScheduledExecutorService();
		}
	});

	textCounter = new Text();

	VBox vBox = new VBox();
	vBox.getChildren().addAll(btn, textCounter);

	StackPane root = new StackPane();
	root.getChildren().add(vBox);

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

	primaryStage.setTitle("java-buddy.blogspot.com");
	primaryStage.setScene(scene);
	primaryStage.show();
}
 
Example 5
Source File: FileFrame.java    From oim-fx with MIT License 6 votes vote down vote up
private void init() {
	this.setCenter(rootPane);
	this.setTitle("登录");
	this.setWidth(380);
	this.setHeight(600);
	this.setRadius(10);

	Button button1 = new Button();

	button1.setText("点击");
	button1.setOnAction(new EventHandler<ActionEvent>() {

		@Override
		public void handle(ActionEvent event) {
			fileChooser.setInitialFileName("cc.text");
			File file=fileChooser.showSaveDialog(FileFrame.this);
			if(file!=null){
				System.out.println("getName:"+file.getName());
				System.out.println("isFile:"+file.isFile());
				System.out.println("isDirectory:"+file.isDirectory());
				System.out.println("getAbsolutePath:"+file.getAbsolutePath());
			}
		}
	});
	rootPane.setCenter(button1);
}
 
Example 6
Source File: TooltipFrame.java    From oim-fx with MIT License 5 votes vote down vote up
private void init() {

		this.setCenter(rootVBox);
		this.setTitle("登录");
		this.setWidth(380);
		this.setHeight(600);
		this.setRadius(10);

		rootVBox.getChildren().add(hBox1);
		rootVBox.getChildren().add(hBox2);
		rootVBox.getChildren().add(hBox3);
		rootVBox.getChildren().add(hBox4);

		Tooltip tooltip1 = new Tooltip();
		tooltip1.setText("账号");
		tooltip1.setHideOnEscape(true);

		TextField textField1 = new TextField();
		
		textField1.setTooltip(tooltip1);
		
		Button button1 = new Button();

		button1.setText("点击");
		button1.setOnAction(new EventHandler<ActionEvent>() {

			@Override
			public void handle(ActionEvent event) {
				tooltip1.show(TooltipFrame.this);
			}
		});
		hBox1.getChildren().add(textField1);
		hBox1.getChildren().add(button1);

	}
 
Example 7
Source File: TestFrame.java    From oim-fx with MIT License 5 votes vote down vote up
public void start(Stage primaryStage) {
    Button btn = new Button();
    btn.setText("Say 'Hello World'");
    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            System.out.println("Hello World!");
        }
    });

}
 
Example 8
Source File: LinkConfigurationWidget.java    From BowlerStudio with GNU General Public License v3.0 5 votes vote down vote up
private void setShaftType(Button editShaft, Button newShaft, final ComboBox<String> shaftSize,
		String selectedItem) {
	shaftSize.getItems().clear();
	if (selectedItem == null)
		return;
	for (String s : Vitamins.listVitaminSizes(selectedItem)) {
		shaftSize.getItems().add(s);
	}
	newShaft.setText("New " + selectedItem);
	// editShaft.setText("Edit "+ conf.getShaftSize());
}
 
Example 9
Source File: StringTable.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private Button createToolbarButton(final String id, final String tool_tip, final EventHandler<ActionEvent> handler)
{
    final Button button = new Button();
    try
    {
        // Icons are not centered inside the button until the
        // button is once pressed, or at least focused via "tab"
        button.setGraphic(ImageCache.getImageView(ImageCache.class, "/icons/" + id + ".png"));

        // Using the image as a background like this centers the image,
        // but replaces the complete characteristic button outline with just the icon.
        // button.setBackground(new Background(new BackgroundImage(new Image(Activator.getIcon(id)),
        //                      BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT,
        //                      BackgroundPosition.CENTER,
        //                      new BackgroundSize(16, 16, false, false, false, false))));
        button.setTooltip(new Tooltip(tool_tip));
    }
    catch (Exception ex)
    {
        logger.log(Level.WARNING, "Cannot load icon for " + id, ex);
        button.setText(tool_tip);
    }
    // Without defining the button size, the buttons may start out zero-sized
    // until they're first pressed/tabbed
    button.setMinSize(35, 25);
    button.setOnAction(handler);

    // Forcing a layout of the button on later UI ticks
    // tends to center the image
    Platform.runLater(() -> Platform.runLater(button::requestLayout));

    return button;
}
 
Example 10
Source File: BigButtonDemo.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void start(Stage primaryStage) {
    Button btn = new Button();
    btn.setText("Alpha Base" + System.lineSeparator() + "Population : 8");
    btn.setGraphic(new Rectangle(30,30, Color.RED));
    btn.setMinHeight(200);
    btn.setMinWidth(250);
    //btn.setStyle("-fx-alignment: LEFT;");
    btn.setAlignment(Pos.BASELINE_LEFT);

    StackPane root = new StackPane();
    root.getChildren().add(btn);
    primaryStage.setScene(new Scene(root, 300, 250));
    primaryStage.show();
}
 
Example 11
Source File: LinkConfigurationWidget.java    From BowlerStudio with GNU General Public License v3.0 5 votes vote down vote up
private void setShaftSize(Button editShaft, Button newShaft, String selectedItem) {
	if (selectedItem == null) {
		newShaft.setText("");
		editShaft.setText("");
		return;
	}
	editShaft.setText("Edit " + selectedItem);
}
 
Example 12
Source File: StaticMethods.java    From SmartCity-ParkingManagement with Apache License 2.0 5 votes vote down vote up
public static Button cloneButton(final Button firstButton) {
	final Button $ = new Button();
	$.setText(firstButton.getText());
	// System.out.println("firstButton.getOnAction(): " +
	// firstButton.getOnAction());
	// System.out.println(firstButton.getStyleClass().toString());
	$.getStyleClass().addAll(firstButton.getStyleClass());
	$.setOnAction(λ -> StaticMethods.dealWithMute(AbstractWindow.mediaPlayer, AbstractWindow.muteButtonsAL));
	return $;
}
 
Example 13
Source File: SettingsWindowController.java    From SmartModInserter with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void updateButton(Button button, Path path) {
    if (path != null) {
        button.setText(".../" + path.getFileName().toString());
    } else {
        button.setText("...");
    }
    closeButton.setDisable(Datastore.getInstance().getDataDir() == null || Datastore.getInstance().getFactorioApplication() == null);
}
 
Example 14
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 15
Source File: PluginManagerController.java    From ShootOFF with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void updateItem(String item, boolean empty) {
	if (!empty) {
		final int currentIndex = indexProperty().getValue() < 0 ? 0 : indexProperty().getValue();
		final PluginMetadata metadata = actionColumn.getTableView().getItems().get(currentIndex);
		final Button actionButton = new Button();

		actionButton.setOnAction((e) -> {
			if (downloadTask.isPresent()) {
				downloadTask.get().cancel();
				downloadTask = Optional.empty();
			} else {
				final Optional<Plugin> installedPlugin = metadata.findInstalledPlugin(pluginEngine.getPlugins());

				if (installedPlugin.isPresent()) {
					if (uninstallPlugin(installedPlugin.get())) actionButton.setText("Install");
				} else {
					final ProgressIndicator progress = new ProgressIndicator();
					progress.setPrefHeight(actionButton.getHeight() - 2);
					progress.setPrefWidth(actionButton.getHeight() - 2);
					progress.setOnMouseClicked((event) -> actionButton.fire());

					actionButton.setGraphic(progress);

					downloadTask = installPlugin(metadata, () -> actionButton.setText("Uninstall"),
							() -> actionButton.setGraphic(null));
				}
			}
		});

		if (metadata.findInstalledPlugin(pluginEngine.getPlugins()).isPresent()) {
			actionButton.setText("Uninstall");
		} else {
			actionButton.setText("Install");
		}

		setGraphic(actionButton);
	} else {
		setGraphic(null);
	}
}
 
Example 16
Source File: PCGenToolBar.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
public ToolBar buildMenu()
{
	ToolBar toolBar = new ToolBar();

	Button newButton = new Button();
	newButton.setOnAction(this::onNew);
	newButton.setGraphic(new ImageView(Icons.New16.asJavaFX()));
	newButton.setText(LanguageBundle.getString("in_mnuFileNew"));
	newButton.setDisable(true);
	ReferenceFacade<DataSetFacade> loadedDataSetRef = rootFrame.getLoadedDataSetRef();
	loadedDataSetRef.addReferenceListener(new EnabledOnlyWithSources(newButton, rootFrame));
	toolBar.getItems().add(newButton);

	Button openButton = new Button();
	openButton.setOnAction(this::onOpen);
	openButton.setGraphic(new ImageView(Icons.Open16.asJavaFX()));
	openButton.setText(LanguageBundle.getString("in_mnuFileOpen"));
	toolBar.getItems().add(openButton);

	Button closeButton = new Button();
	closeButton.setOnAction(this::onClose);
	closeButton.setGraphic(new ImageView(Icons.Close16.asJavaFX()));
	closeButton.setText (LanguageBundle.getString("in_mnuFileClose"));
	toolBar.getItems().add(closeButton);
	ReferenceFacade<CharacterFacade> ref = rootFrame.getSelectedCharacterRef();
	ref.addReferenceListener(new EnabledOnlyWithCharacter(closeButton, rootFrame));

	Button saveButton = new Button();
	saveButton.setOnAction(this::onSave);
	saveButton.setGraphic(new ImageView(Icons.Save16.asJavaFX()));
	saveButton.setText(LanguageBundle.getString("in_mnuFileSave"));
	toolBar.getItems().add(saveButton);
	ref.addReferenceListener(new EnabledOnlyWithCharacter(saveButton, rootFrame));

	Button printButton = new Button();
	printButton.setOnAction(this::onPrint);
	printButton.setGraphic(new ImageView(Icons.Print16.asJavaFX()));
	printButton.setText(LanguageBundle.getString("in_mnuFilePrint"));
	toolBar.getItems().add(printButton);
	ref.addReferenceListener(new EnabledOnlyWithCharacter(printButton, rootFrame));

	Button exportButton = new Button();
	exportButton.setOnAction(this::onExport);
	exportButton.setGraphic(new ImageView(Icons.Export16.asJavaFX()));
	exportButton.setText(LanguageBundle.getString("in_mnuFileExport"));
	toolBar.getItems().add(exportButton);
	ref.addReferenceListener(new EnabledOnlyWithCharacter(exportButton, rootFrame));

	Button preferencesButton = new Button();
	preferencesButton.setOnAction(this::onPreferences);
	preferencesButton.setGraphic(new ImageView(Icons.Preferences16.asJavaFX()));
	preferencesButton.setText(LanguageBundle.getString("in_mnuToolsPreferences"));
	toolBar.getItems().add(preferencesButton);

	return toolBar;
}
 
Example 17
Source File: CurrentPatchSetTab.java    From EWItool with GNU General Public License v3.0 4 votes vote down vote up
public void reset() {
  for (Button b : patchButtons) b.setText( "<Not Loaded>" );
  patchEditorTab.setDisable( true );
  setDisable( true );
}
 
Example 18
Source File: TreeViewApp.java    From oim-fx with MIT License 4 votes vote down vote up
public Parent createContent() {

		final TreeItem<String> treeRoot = new TreeItem<String>("Root node");

		treeRoot.getChildren().addAll(Arrays.asList(
				new TreeItem<String>("Child Node 1"),
				new TreeItem<String>("Child Node 2"),
				new TreeItem<String>("Child Node 3")));

		treeRoot.getChildren().get(2).getChildren().addAll(Arrays.asList(

				new TreeItem<String>("Child Node 4"),
				new TreeItem<String>("Child Node 5"),
				new TreeItem<String>("Child Node 6"),
				new TreeItem<String>("Child Node 7"),
				new TreeItem<String>("Child Node 8")));

		Button button = new Button();
		button.setText("root");
		
		button.setOnMouseEntered(e->{
			System.out.println(3333);
		});

		TreeItem<Button> root = new TreeItem<Button>(button);
		
		Button nodeButton = new Button();
		nodeButton.setText("node");
		
		TreeItem<Button> node = new TreeItem<Button>(nodeButton);
		root.getChildren().add(node);
		
		TreeView<Button> treeView = new TreeView<Button>();
		treeView.setShowRoot(true);
		treeView.setRoot(root);
		// treeRoot.setExpanded(true);
		treeView.setOnMouseEntered(e->{
			System.out.println(1111);
		});
		return treeView;
	}
 
Example 19
Source File: PCGenToolBar.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
public ToolBar buildMenu()
{
	ToolBar toolBar = new ToolBar();

	Button newButton = new Button();
	newButton.setOnAction(this::onNew);
	newButton.setGraphic(new ImageView(Icons.New16.asJavaFX()));
	newButton.setText(LanguageBundle.getString("in_mnuFileNew"));
	newButton.setDisable(true);
	ReferenceFacade<DataSetFacade> loadedDataSetRef = rootFrame.getLoadedDataSetRef();
	loadedDataSetRef.addReferenceListener(new EnabledOnlyWithSources(newButton, rootFrame));
	toolBar.getItems().add(newButton);

	Button openButton = new Button();
	openButton.setOnAction(this::onOpen);
	openButton.setGraphic(new ImageView(Icons.Open16.asJavaFX()));
	openButton.setText(LanguageBundle.getString("in_mnuFileOpen"));
	toolBar.getItems().add(openButton);

	Button closeButton = new Button();
	closeButton.setOnAction(this::onClose);
	closeButton.setGraphic(new ImageView(Icons.Close16.asJavaFX()));
	closeButton.setText (LanguageBundle.getString("in_mnuFileClose"));
	toolBar.getItems().add(closeButton);
	ReferenceFacade<CharacterFacade> ref = rootFrame.getSelectedCharacterRef();
	ref.addReferenceListener(new EnabledOnlyWithCharacter(closeButton, rootFrame));

	Button saveButton = new Button();
	saveButton.setOnAction(this::onSave);
	saveButton.setGraphic(new ImageView(Icons.Save16.asJavaFX()));
	saveButton.setText(LanguageBundle.getString("in_mnuFileSave"));
	toolBar.getItems().add(saveButton);
	ref.addReferenceListener(new EnabledOnlyWithCharacter(saveButton, rootFrame));

	Button printButton = new Button();
	printButton.setOnAction(this::onPrint);
	printButton.setGraphic(new ImageView(Icons.Print16.asJavaFX()));
	printButton.setText(LanguageBundle.getString("in_mnuFilePrint"));
	toolBar.getItems().add(printButton);
	ref.addReferenceListener(new EnabledOnlyWithCharacter(printButton, rootFrame));

	Button exportButton = new Button();
	exportButton.setOnAction(this::onExport);
	exportButton.setGraphic(new ImageView(Icons.Export16.asJavaFX()));
	exportButton.setText(LanguageBundle.getString("in_mnuFileExport"));
	toolBar.getItems().add(exportButton);
	ref.addReferenceListener(new EnabledOnlyWithCharacter(exportButton, rootFrame));

	Button preferencesButton = new Button();
	preferencesButton.setOnAction(this::onPreferences);
	preferencesButton.setGraphic(new ImageView(Icons.Preferences16.asJavaFX()));
	preferencesButton.setText(LanguageBundle.getString("in_mnuToolsPreferences"));
	toolBar.getItems().add(preferencesButton);

	return toolBar;
}
 
Example 20
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);
}