Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #### fxml
- <?xml version="1.0" encoding="UTF-8"?>
- <?import java.lang.String?>
- <?import javafx.collections.FXCollections?>
- <?import javafx.scene.control.Button?>
- <?import javafx.scene.control.ComboBox?>
- <?import javafx.scene.control.ScrollPane?>
- <?import javafx.scene.control.TextField?>
- <?import javafx.scene.layout.AnchorPane?>
- <?import javafx.scene.layout.VBox?>
- <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">
- <AnchorPane prefHeight="111.0" prefWidth="235.0" styleClass="anchor">
- <ComboBox fx:id="combo" layoutX="14.0" layoutY="47.0" onAction="#comboAction" prefWidth="150.0">
- <items>
- <FXCollections fx:factory="observableArrayList">
- <String fx:value="Apple" />
- <String fx:value="Orange" />
- <String fx:value="Pear" />
- </FXCollections>
- </items>
- </ComboBox>
- </AnchorPane>
- <ScrollPane prefHeight="141.0" prefWidth="235.0" styleClass="scroll">
- <VBox>
- <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="177.0" styleClass="anch">
- <TextField layoutX="7.0" layoutY="62.0" prefHeight="31.0" prefWidth="133.0" />
- </AnchorPane>
- <Button layoutX="41.0" layoutY="75.0" mnemonicParsing="false" text="Button" />
- </VBox>
- </ScrollPane>
- </VBox>
- ### controller
- package com.lampa.testing;
- import javafx.collections.ObservableList;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.fxml.FXML;
- import javafx.geometry.Bounds;
- import javafx.scene.Node;
- import javafx.scene.Parent;
- import javafx.scene.control.ComboBox;
- import javafx.scene.control.ScrollPane;
- import javafx.scene.input.MouseEvent;
- import javafx.scene.layout.VBox;
- public class javafxcontroller {
- @FXML
- private ComboBox combo;
- @FXML
- private void initialize() { }
- @FXML
- private void comboAction(ActionEvent event) {
- System.out.println(combo.getValue());
- view(combo);
- }
- private void view(Node combobox) {
- Parent parent = combobox.getParent().getParent(); //vbox
- ScrollPane scrollPane = (ScrollPane) parent.getChildrenUnmodifiable().get(1); // get scrollpane
- VBox vboxInScrollPane = (VBox) scrollPane.getContent(); // anchor
- ObservableList<Node> elements = vboxInScrollPane.getChildren(); // get elements in vbox
- for(Node node : elements) {
- Bounds bounds = node.getLayoutBounds();
- System.out.println(node + " - " + bounds.getWidth() + " - " + bounds.getHeight());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement