Guest User

Untitled

a guest
May 24th, 2018
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1. .combo-box .arrow, .combo-box .arrow-button{
  2. -fx-background-color: transparent;
  3. }
  4.  
  5. public class ComboboxSample extends Application {
  6. public static void main(String[] args) {
  7. launch(args);
  8. }
  9.  
  10. final Button button = new Button("Send");
  11. final Label notification = new Label();
  12. final TextField subject = new TextField("");
  13. final TextArea text = new TextArea("");
  14.  
  15. String address = " ";
  16.  
  17. @Override
  18. public void start(Stage stage) {
  19. stage.setTitle("ComboBoxSample");
  20. Scene scene = new Scene(new Group(), 450, 250);
  21. // Load the css as below to the scene
  22. scene.getStylesheets()
  23. .add(ComboboxSample.class.getResource("styles.css").toExternalForm());
  24.  
  25. final ComboBox emailComboBox = new ComboBox();
  26. emailComboBox.setEditable(true);
  27. emailComboBox.getItems().addAll("jacob.smith@example.com",
  28. "isabella.johnson@example.com", "ethan.williams@example.com",
  29. "emma.jones@example.com", "michael.brown@example.com");
  30.  
  31. final ComboBox priorityComboBox = new ComboBox();
  32. priorityComboBox.getItems().addAll("Highest", "High", "Normal", "Low",
  33. "Lowest");
  34.  
  35. priorityComboBox.setValue("Normal");
  36.  
  37. GridPane grid = new GridPane();
  38. grid.setVgap(4);
  39. grid.setHgap(10);
  40. grid.setPadding(new Insets(5, 5, 5, 5));
  41. grid.add(new Label("To: "), 0, 0);
  42. grid.add(emailComboBox, 1, 0);
  43. grid.add(new Label("Priority: "), 2, 0);
  44. grid.add(priorityComboBox, 3, 0);
  45. grid.add(new Label("Subject: "), 0, 1);
  46. grid.add(subject, 1, 1, 3, 1);
  47. grid.add(text, 0, 2, 4, 1);
  48. grid.add(button, 0, 3);
  49. grid.add(notification, 1, 3, 3, 1);
  50.  
  51. Group root = (Group) scene.getRoot();
  52. root.getChildren().add(grid);
  53. stage.setScene(scene);
  54. stage.show();
  55. }
  56. }
  57.  
  58. .combo-box1 .arrow-button {
  59. -fx-opacity: 0.0;
  60. -fx-cursor: text;
  61. }
  62.  
  63. combobox.getStyleClass().add("combo-box1");
  64.  
  65. .combo-box1 .arrow-button
  66. {
  67. -fx-background-color: null;
  68. -fx-background-insets: 0;
  69. -fx-background-radius: 0;
  70. -fx-padding: 0.0em 0em 0.0em 0.0em; /* 0 3 0 0 */
  71. }
  72.  
  73. .combo-box1 .arrow-button .arrow
  74. {
  75. -fx-background-color: -fx-mark-highlight-color, -fx-mark-color;
  76. -fx-background-insets: 0 0 0 0, 0;
  77. -fx-padding: 0em 0em 0em 0em; /* 3 3.75 3 3.75 */
  78. /*
  79. -fx-shape: "M 0 0 h 7 l -3.5 4 z";
  80. */
  81. -fx-shape: null;
  82. }
  83.  
  84. public enum URLBarArrowConstants {
  85. //URLBarArrow Constants
  86. BYCSS_AND_SHAPE,
  87. BYCSS_AND_NO_SHAPE,
  88. NOCSS_AND_SHAPE,
  89. NOCSS_AND_NO_SHAPE;
  90. }
  91.  
  92. /*ComboBox's Arrow is a Region.*/
  93. .combo-box .arrow-button .arrow {
  94. -fx-shape: "...";
  95. -fx-scale-shape: true;
  96. -fx-position-shape: true;
  97. }
  98.  
  99. /*ComboBox's Arrow is a Region.*/
  100. .combo-box .arrow-button .arrow {
  101. /*Setting either of these two will do.*/
  102. -fx-background-color: transparent;
  103. -fx-opacity: 0.0;
  104. }
  105.  
  106. /*ComboBox's Arrow Button is a Stack Pane.*/
  107. .combo-box .arrow-button{
  108. -fx-background-position: center;
  109. -fx-background-repeat: no-repeat;
  110. -fx-background-image: url("..<file>.png");
  111. }
  112.  
  113. def setCustomURLBarArrow(self, url_bar, scene, URLBarArrowConstant):
  114. from javafx.scene.paint import Paint
  115. from javafx.scene.shape import Shape, SVGPath, FillRule
  116.  
  117. if URLBarArrowConstant == URLBarArrowConstants.NOCSS_AND_SHAPE:
  118.  
  119. #SVG Object
  120. previous_url_bar = SVGPath()
  121.  
  122. #SVG Path
  123. previous_url_bar.setContent("...") # edit this
  124.  
  125. #SVG Fill Rule
  126. previous_url_bar.setFillRule(FillRule.NON_ZERO)
  127.  
  128. #Set Fill --
  129. previous_url_bar.setFill(Paint.valueOf(Color.web("...").toString())) //edit here
  130.  
  131. #Apply CSS Sheet
  132. url_bar.applyCss()
  133.  
  134. #Set Region's Shape
  135. arrow_region = url_bar.lookup(".arrow").setShape(previous_url_bar)
  136.  
  137. elif URLBarArrowConstant == URLBarArrowConstants.BYCSS_AND_SHAPE:
  138. #Apply Stylesheet for URL Bar
  139. scene.getStylesheets().add(File("..<file>.css").toURI().toString()) //edit here
  140.  
  141. elif URLBarArrowConstant == URLBarArrowConstants.BYCSS_AND_NO_SHAPE:
  142. #Apply Stylesheet for URL Bar
  143. scene.getStylesheets().add(File("..<file>.css").toURI().toString()) //edit here
  144.  
  145. elif URLBarArrowConstant == URLBarArrowConstants.NOCSS_AND_NO_SHAPE:
  146.  
  147. from javafx.scene.paint import Paint
  148. from javafx.scene.layout import CornerRadii
  149. from javafx.scene.layout import Background, BackgroundSize, BackgroundImage, BackgroundPosition, BackgroundRepeat, BackgroundFill
  150.  
  151. #Apply CSS Sheet
  152. url_bar.applyCss()
  153.  
  154. #Grab Arrow(Region), ArrowButton(StackPane) ComboBox properties
  155. arrow_region = url_bar.lookup(".arrow")
  156. arrow_button = url_bar.lookup(".arrow-button")
  157.  
  158. #Either Set Opacity to 0 or set background color to transparent.
  159. arrow_region.setOpacity(0.0)
  160. arrow_region.setBackground( Background( array(BackgroundFill, [BackgroundFill( Paint.valueOf(Color.TRANSPARENT.toString()), CornerRadii.EMPTY, Insets.EMPTY)]) ) )
  161.  
  162. #Set a Background Image for the .arrow-button StackPane.
  163. arrow_button.setBackground(Background( array(BackgroundImage, [BackgroundImage( Image( String(File('..<file>.png').toURI().toString()), True) , BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, BackgroundSize.DEFAULT)] ) ) ) //if you want, edit this
Add Comment
Please, Sign In to add comment