@Override public void start(Stage primaryStage) { primaryStage.setTitle("CoAP Explorer"); Group root = new Group(); Scene scene = new Scene(root, 800, 600); TextArea hexArea = new TextArea(); TextArea binArea = new TextArea(); CoapPacket packet = new CoapPacket(); packet.setPayload("PAYLOAD"); packetProp.setValue(packet); binArea.textProperty().bindBidirectional(packetProp, new AsciiConverter()); hexArea.textProperty().bindBidirectional(packetProp, new HexConverter()); hexArea.setEditable(false); hexArea.setFont(javafx.scene.text.Font.font(Font.MONOSPACED)); VBox vbox = new VBox(); vbox.setPadding(new Insets(10)); vbox.setSpacing(8); VBox.setMargin(hexArea, new Insets(0, 0, 0, 8)); vbox.getChildren().add(hexArea); VBox.setMargin(binArea, new Insets(0, 0, 0, 8)); vbox.getChildren().add(binArea); root.getChildren().add(vbox); primaryStage.setScene(scene); primaryStage.show(); }
public void start(Stage stage) { stage.setTitle("ListView demo"); FlowPane rootNode = new FlowPane(10, 10); rootNode.setAlignment(Pos.CENTER); Scene scene = new Scene(rootNode, 200, 120); stage.setScene(scene); responseLabel = new Label("Select Transport Type"); ObservableList<String> transportTypes = FXCollections.observableArrayList("Train", "Car", "Airplane"); ListView<String> transportListView = new ListView(transportTypes); transportListView.setPrefSize(80, 80); MultipleSelectionModel<String> listViewSelectionModel = transportListView.getSelectionModel(); listViewSelectionModel .selectedItemProperty() .addListener( new ChangeListener<String>() { public void changed( ObservableValue<? extends String> changed, String oldValue, String newValue) { responseLabel.setText("Transport selected is " + newValue); } }); rootNode.getChildren().addAll(transportListView, responseLabel); stage.show(); }
@Override public void start(Stage primaryStage) throws Exception { GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setVgap(10); grid.setHgap(10); grid.setPadding(new Insets(25, 25, 25, 25)); Scene sc = new Scene(grid, 500, 500); String css = Main.class.getResource("Login.css").toExternalForm(); // System.out.println(css); sc.getStylesheets().add(css); Text scenetitle = new Text("Welcome"); // scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20)); grid.add(scenetitle, 0, 0, 1, 1); Label userName = new Label("User Name:"); grid.add(userName, 0, 1); TextField userTextField = new TextField("Мудак"); grid.add(userTextField, 1, 1); Label pw = new Label("Password:"******"Sign in"); HBox hbBtn = new HBox(10); hbBtn.setAlignment(Pos.BOTTOM_RIGHT); hbBtn.getChildren().add(btn); grid.add(hbBtn, 1, 4); final Text actiontarget = new Text(); grid.add(actiontarget, 1, 6); btn.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { // actiontarget.setFill(Color.FIREBRICK); actiontarget.setText("Pressed"); } }); // grid.setGridLinesVisible(true); scenetitle.setId("welc"); actiontarget.setId("act"); primaryStage.setScene(sc); primaryStage.setTitle("Hello World"); primaryStage.show(); }
public void start(Stage primaryStage) { d3 = new Draw3D(); Scene scene = d3.buildScene(); preambleCommands(); drawingCommands(); d3.setStart(); primaryStage.setScene(scene); primaryStage.setTitle(title); primaryStage.show(); }
@Override public void start(Stage stage) throws Exception { stage.setTitle("Tetris"); Group root = new Group(); Scene scene = new Scene(root, 800, 400); stage.setScene(scene); stage.show(); SceneManager scmanager = new SceneManager(stage, scene, root); stage.setOnCloseRequest(scmanager.getOnCloseWindow()); scmanager.launch(); }
@Override public void start(Stage primaryStage) { try { TabPane page = (TabPane) FXMLLoader.load(Main.class.getResource("simple.fxml")); Scene scene = new Scene(page); primaryStage.setScene(scene); primaryStage.setTitle("Hotels"); primaryStage.show(); textf = (TextField) scene.lookup("#HotelNameTextb"); Button create = (Button) scene.lookup("#CreateButton"); create.setOnAction(this::handleButtonAction); } catch (Exception ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } }
/** Starts the Gui applicaiton. */ public void start(Stage myStage) { System.out.println("Inside the start() method."); table = new TableView<PersonBean>(); table.setEditable(true); // Give the stage a title. myStage.setTitle("Person Spam App"); filteredData = new FilteredList<>(personData, p -> true); sortedData = new SortedList<>(filteredData); sortedData.comparatorProperty().bind(table.comparatorProperty()); table.setItems(sortedData); table.setPrefWidth(500); table.getStylesheets().add("resource/style.css"); table.setColumnResizePolicy(TableView.UNCONSTRAINED_RESIZE_POLICY); // My edition: TableColumn<PersonBean, String> wholeNameCol = new TableColumn<PersonBean, String>("Full name"); wholeNameCol.setCellValueFactory(new PropertyValueFactory("firstAndLastName")); wholeNameCol.setCellFactory(TextFieldTableCell.<PersonBean>forTableColumn()); wholeNameCol.setOnEditCommit( (CellEditEvent<PersonBean, String> t) -> { // Start on line below ((PersonBean) t.getTableView().getItems().get(t.getTablePosition().getRow())) .setFirstAndLastName(t.getNewValue()); }); // TableColumn<PersonBean, String> firstNameCol = new TableColumn<PersonBean, String>("First // Name"); // firstNameCol.setCellValueFactory(new PropertyValueFactory("firstName")); // firstNameCol.setCellFactory(TextFieldTableCell.<PersonBean> forTableColumn()); // firstNameCol.setOnEditCommit((CellEditEvent<PersonBean, String> t) -> { // // ((PersonBean)t.getTableView().getItems().get(t.getTablePosition().getRow())).setFirstName(t.getNewValue()); // }); // // TableColumn<PersonBean, String> lastNameCol = new TableColumn<PersonBean, String>("Last // Name"); // lastNameCol.setCellValueFactory(new PropertyValueFactory("lastName")); // lastNameCol.setCellFactory(TextFieldTableCell.<PersonBean> forTableColumn()); // lastNameCol.setOnEditCommit((CellEditEvent<PersonBean, String> t) -> { // ((PersonBean) // t.getTableView().getItems().get(t.getTablePosition().getRow())).setLastName(t.getNewValue()); // }); TableColumn<PersonBean, String> emailCol = new TableColumn<PersonBean, String>("Email"); emailCol.setCellValueFactory(new PropertyValueFactory("email")); emailCol.setCellFactory(TextFieldTableCell.<PersonBean>forTableColumn()); emailCol.setOnEditCommit( (CellEditEvent<PersonBean, String> t) -> { ((PersonBean) t.getTableView().getItems().get(t.getTablePosition().getRow())) .setEmail(t.getNewValue()); }); TableColumn<PersonBean, String> genderCol = new TableColumn<PersonBean, String>("Gender"); genderCol.setCellValueFactory(new PropertyValueFactory("gender")); genderCol.setCellFactory(TextFieldTableCell.<PersonBean>forTableColumn()); genderCol.setOnEditCommit( (CellEditEvent<PersonBean, String> t) -> { ((PersonBean) t.getTableView().getItems().get(t.getTablePosition().getRow())) .setGender(t.getNewValue()); }); TableColumn<PersonBean, Integer> ageCol = new TableColumn<PersonBean, Integer>("Age"); ageCol.setCellValueFactory(new PropertyValueFactory("age")); ageCol.setCellFactory( TextFieldTableCell.<PersonBean, Integer>forTableColumn(new IntegerStringConverter())); ageCol.setOnEditCommit( (CellEditEvent<PersonBean, Integer> t) -> { ((PersonBean) t.getTableView().getItems().get(t.getTablePosition().getRow())) .setAge(t.getNewValue()); }); table.getColumns().setAll(wholeNameCol, emailCol, genderCol, ageCol); ageCol.setId("white"); Button allButton = new Button("All"); allButton.setMinSize(100, 10); allButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Show all!"); filteredData.setPredicate(showAll()); } }); Button maleButton = new Button("Male"); maleButton.setMinSize(100, 10); maleButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Show male"); // printIt(); filteredData.setPredicate(isMale()); } }); Button femaleButton = new Button("Female"); femaleButton.setMinSize(100, 10); femaleButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Show female"); filteredData.setPredicate(isFemale()); } }); Button over18Button = new Button("Over 18"); over18Button.setMinSize(100, 10); over18Button.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Above 18"); // filteredData.setPredicate(over18()); filteredData.setPredicate( new Predicate<PersonBean>() { public boolean test(PersonBean p) { return p.getAge() > 17; } }); } }); Button addButton = new Button("Add row"); addButton.setMinSize(100, 10); addButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Add me!"); filteredData.setPredicate(showAll()); addRow(); } }); Button removeButton = new Button("Delete row"); removeButton.setMinSize(100, 10); removeButton.setOnAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("delete me!"); List items = new ArrayList(table.getSelectionModel().getSelectedItems()); personData.removeAll(items); table.getSelectionModel().clearSelection(); } }); // Create a root node. In this case, a flow layout // is used, but several alternatives exist. FlowPane rootNode = new FlowPane(); rootNode.getStylesheets().add("resource/style.css"); rootNode .getChildren() .addAll(table, allButton, maleButton, femaleButton, over18Button, addButton, removeButton); // Create a scene. Scene myScene = new Scene(rootNode, 800, 800); // Set the scene on the stage. myStage.setScene(myScene); // Show the stage and its scene. myStage.show(); }
@Override public void start(final Stage primaryStage) { // initialize the stage primaryStage.setTitle("Modal Confirm Example"); final WebView webView = new WebView(); webView.getEngine().load("http://docs.oracle.com/javafx/"); primaryStage.setScene(new Scene(webView)); primaryStage.show(); // initialize the confirmation dialog final Stage util = new Stage(StageStyle.TRANSPARENT); util.initModality(Modality.APPLICATION_MODAL); util.setScene( new Scene( StackPaneBuilder.create() .children( PaneBuilder.create().styleClass("modal-dialog-glass").build(), HBoxBuilder.create() .styleClass("modal-dialog-content") .children( LabelBuilder.create().text("Will you like this page?").build(), ButtonBuilder.create() .text("Yes") .defaultButton(true) .onAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { // take action and close the dialog. System.out.println( "Liked: " + webView.getEngine().getTitle()); primaryStage.getScene().getRoot().setEffect(null); util.close(); } }) .build(), ButtonBuilder.create() .text("No") .cancelButton(true) .onAction( new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { // abort action and close the dialog. System.out.println( "Disliked: " + webView.getEngine().getTitle()); primaryStage.getScene().getRoot().setEffect(null); util.close(); } }) .build()) .build()) .build(), Color.TRANSPARENT)); util.getScene() .getStylesheets() .add(getClass().getResource("/assets/fxml/modal-dialog.css").toExternalForm()); // show the confirmation dialog each time a new page is loaded. webView .getEngine() .getLoadWorker() .stateProperty() .addListener( new ChangeListener<Worker.State>() { @Override public void changed( ObservableValue<? extends Worker.State> observableValue, Worker.State state, Worker.State newState) { if (newState.equals(Worker.State.SUCCEEDED)) { primaryStage.getScene().getRoot().setEffect(new BoxBlur()); util.show(); util.toFront(); } } }); }
@Override public void start(Stage stage) { stage.setScene(new MainScene(stage)); stage.setTitle("Мой бюджет"); stage.show(); }
/** * Here is our whole stage with layout, </Br > ( Grid, TextField and Buttons) * * @author PatrikWebb */ public void NameDisplay() { Stage nameWindow = new Stage(); // Block events to other windows nameWindow.initModality(Modality.APPLICATION_MODAL); nameWindow.setTitle("Enter your name"); nameWindow.setMinWidth(250); // GridPane Form GridPane grid = new GridPane(); grid.setPadding(new Insets(10, 10, 10, 10)); grid.setVgap(8); grid.setHgap(10); // Name Label Label nameLabel = new Label("Player Name:"); GridPane.setConstraints(nameLabel, 0, 0); // Name Input nameInput = new TextField(); nameInput.setPromptText("Name"); nameInput.setFocusTraversable(false); GridPane.setConstraints(nameInput, 1, 0); // Betting Label Label bettingLabel = new Label("Betting amount: "); GridPane.setConstraints(bettingLabel, 0, 1); // Bett Input playerCashInput = new TextField(); playerCashInput.setFocusTraversable(false); playerCashInput.setPromptText("Betting amount"); GridPane.setConstraints(playerCashInput, 1, 1); // Enter button Button enterButton = new Button("Enter"); enterButton.setFocusTraversable(false); // setPercentWidth(50); GridPane.setConstraints(enterButton, 1, 2); // Cancel button Button cancelButton = new Button("Demo Player"); cancelButton.setFocusTraversable(false); GridPane.setConstraints(cancelButton, 2, 2); // enterButton.setOnAction( e -> { Platform.runLater( () -> { // Get the input from the nameInput TextField name = nameInput.getText(); // Get the betting input from the bettsInput TextField playerCash = Integer.parseInt(playerCashInput.getText()); // Add name and playerCash input to a new player Bank.getInstance().addPlayerToBank(name, playerCash); // Add the player to the table Bank.getInstance().addPlayersToTheTable(); // Close the stage nameWindow.close(); System.out.println("\nPlayer Name: " + name); System.out.println("Betting Amount: " + playerCash + "\n"); }); }); cancelButton.setOnAction( e -> { // TODO Platform.runLater( () -> { /* * * * * * * * * * * * * * If you press cancel you still want a player to join * the table so I add a test player insted of * getting the error, Exception JavaFX Application THREAD ;) * * * * * * * * * * * * */ Bank.getInstance().addPlayerToBank("Demo Player", 500); // Add the player to the table Bank.getInstance().addPlayersToTheTable(); nameWindow.close(); }); }); // Add everything to grid grid.getChildren() .addAll(nameLabel, nameInput, bettingLabel, playerCashInput, enterButton, cancelButton); // Display window and wait for it to be closed before returning Scene scene = new Scene(grid, 450, 150); nameWindow.setScene(scene); nameWindow.showAndWait(); }