Skip to content

Instantly share code, notes, and snippets.

@oddbjornkvalsund
Created November 10, 2014 11:25
Show Gist options
  • Save oddbjornkvalsund/2c3cf8360973ec70885a to your computer and use it in GitHub Desktop.
Save oddbjornkvalsund/2c3cf8360973ec70885a to your computer and use it in GitHub Desktop.
package focusbug;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBoxBuilder;
import javafx.scene.layout.VBoxBuilder;
import javafx.stage.Stage;
public class FocusBug extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage mainStage ) {
mainStage.setScene(new Scene(getRootNode()));
mainStage.show();
}
public Parent getRootNode() {
final TextField textField = new TextField();
textField.setId("mainTextField");
final Button clickMeButton = new Button("Click me to show popup");
clickMeButton.setId("clickMeButton");
clickMeButton.setOnAction(showPopupWindow());
return VBoxBuilder.create().children(textField, clickMeButton).build();
}
private EventHandler<ActionEvent> showPopupWindow() {
return new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
final Label label = new Label("Enter text:");
label.setId("popupLabel");
final TextField textField = new TextField();
textField.setId("popupTextField");
final Stage stage = new Stage();
stage.setTitle("Popup");
stage.setScene(new Scene(HBoxBuilder.create().children(label, textField).build()));
stage.show();
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment