Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. package javafxExamples;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Optional;
  6.  
  7. import javafx.application.Application;
  8. import javafx.scene.Scene;
  9. import javafx.scene.control.Button;
  10. import javafx.scene.control.ChoiceDialog;
  11. import javafx.scene.control.ComboBox;
  12. import javafx.scene.layout.BorderPane;
  13. import javafx.stage.Stage;
  14.  
  15. public class ComboErrorTest extends Application {
  16.  
  17. String[] list={"Jamie", "Arthur", "Gordon"};
  18.  
  19. private Stage stage;
  20.  
  21. public static void main(String[] args) {
  22. launch(args);
  23. }
  24.  
  25.  
  26. @Override
  27. public void start(Stage stage) throws Exception {
  28. //create box in main stage.
  29. ComboBox<String> comboBox=new ComboBox<String>();
  30. for (int i=0; i<list.length; i++){
  31. comboBox.getItems().add(list[i]);
  32. }
  33. comboBox.getSelectionModel().select(list[0]);
  34.  
  35. BorderPane pane = new BorderPane(comboBox);
  36. pane.setPrefSize(400, 250);
  37.  
  38. //dialog bit
  39. List<String> choices = new ArrayList<>();
  40. choices.add("a");
  41. choices.add("b");
  42. choices.add("c");
  43.  
  44. ChoiceDialog<String> dialog = new ChoiceDialog<>("b", choices);
  45. dialog.setTitle("Choice Dialog");
  46. dialog.setHeaderText("Look, a Choice Dialog");
  47. dialog.setContentText("Choose your letter:");
  48.  
  49.  
  50. Button dialogButton=new Button("Open Dialog...");
  51. dialogButton.setOnAction((action)->{
  52. // Traditional way to get the response value.
  53. Optional<String> result = dialog.showAndWait();
  54. if (result.isPresent()){
  55. System.out.println("Your choice: " + result.get());
  56. }
  57. });
  58.  
  59. pane.setBottom(dialogButton);
  60.  
  61. Scene scene = new Scene(pane);
  62.  
  63. stage.setTitle("ComboError Demo");
  64. stage.setScene(scene);
  65. stage.show();
  66.  
  67. }
  68.  
  69. }
  70.  
  71. java -Dglass.accessible.force=false ...
  72.  
  73. System.setProperty("glass.accessible.force", "false");
  74.  
  75. comboBox.setOnMousePressed(new EventHandler<MouseEvent>(){
  76. @Override
  77. public void handle(MouseEvent event) {
  78. comboBox.requestFocus();
  79. }
  80. });
  81.  
  82. System.setProperty("glass.accessible.force", "false");
  83.  
  84. Pen 'n touch Wacom bamboo create tablet
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement