Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. #### fxml
  2. <?xml version="1.0" encoding="UTF-8"?>
  3.  
  4. <?import java.lang.String?>
  5. <?import javafx.collections.FXCollections?>
  6. <?import javafx.scene.control.Button?>
  7. <?import javafx.scene.control.ComboBox?>
  8. <?import javafx.scene.control.ScrollPane?>
  9. <?import javafx.scene.control.TextField?>
  10. <?import javafx.scene.layout.AnchorPane?>
  11. <?import javafx.scene.layout.VBox?>
  12.  
  13. <VBox prefHeight="400.0" prefWidth="235.0" styleClass="main" stylesheets="@standards.css" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.lampa.testing.javafxcontroller">
  14. <AnchorPane prefHeight="111.0" prefWidth="235.0" styleClass="anchor">
  15. <ComboBox fx:id="combo" layoutX="14.0" layoutY="47.0" onAction="#comboAction" prefWidth="150.0">
  16. <items>
  17. <FXCollections fx:factory="observableArrayList">
  18. <String fx:value="Apple" />
  19. <String fx:value="Orange" />
  20. <String fx:value="Pear" />
  21. </FXCollections>
  22. </items>
  23. </ComboBox>
  24. </AnchorPane>
  25.  
  26. <ScrollPane prefHeight="141.0" prefWidth="235.0" styleClass="scroll">
  27. <VBox>
  28. <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="177.0" styleClass="anch">
  29. <TextField layoutX="7.0" layoutY="62.0" prefHeight="31.0" prefWidth="133.0" />
  30. </AnchorPane>
  31.  
  32. <Button layoutX="41.0" layoutY="75.0" mnemonicParsing="false" text="Button" />
  33. </VBox>
  34. </ScrollPane>
  35.  
  36. </VBox>
  37.  
  38. ### controller
  39. package com.lampa.testing;
  40.  
  41. import javafx.collections.ObservableList;
  42. import javafx.event.ActionEvent;
  43. import javafx.event.EventHandler;
  44. import javafx.fxml.FXML;
  45. import javafx.geometry.Bounds;
  46. import javafx.scene.Node;
  47. import javafx.scene.Parent;
  48. import javafx.scene.control.ComboBox;
  49. import javafx.scene.control.ScrollPane;
  50. import javafx.scene.input.MouseEvent;
  51. import javafx.scene.layout.VBox;
  52.  
  53.  
  54. public class javafxcontroller {
  55. @FXML
  56. private ComboBox combo;
  57.  
  58. @FXML
  59. private void initialize() { }
  60.  
  61. @FXML
  62. private void comboAction(ActionEvent event) {
  63. System.out.println(combo.getValue());
  64. view(combo);
  65. }
  66.  
  67. private void view(Node combobox) {
  68. Parent parent = combobox.getParent().getParent(); //vbox
  69. ScrollPane scrollPane = (ScrollPane) parent.getChildrenUnmodifiable().get(1); // get scrollpane
  70. VBox vboxInScrollPane = (VBox) scrollPane.getContent(); // anchor
  71. ObservableList<Node> elements = vboxInScrollPane.getChildren(); // get elements in vbox
  72.  
  73. for(Node node : elements) {
  74. Bounds bounds = node.getLayoutBounds();
  75.  
  76. System.out.println(node + " - " + bounds.getWidth() + " - " + bounds.getHeight());
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement