Class PopupView

  • All Implemented Interfaces:
    Styleable, EventTarget
    Direct Known Subclasses:
    MenuPopupView

    public class PopupView
    extends Layer

    The PopupView class is used to show a list of Nodes within the user interface - it will appear relative to the given owner node. PopupView will stick to either left or right side of the owner node depending on the value of the {sideProperty().

    Example

    The following example shows a PopupView when the user presses the button with the label "Click".

     public class MyApp extends MobileApplication{
       private Button button;
       private PopupView popupView;
    
      @Override
       public void init() {
         addViewFactory(HOME_VIEW, () -> {
           button = new Button("Click");
           button.setOnAction(event -> popupView.show());
           popupView = new PopupView(button);
           VBox vBox = new VBox();
           vBox.getChildren().addAll(new Label("Choice 1"), new Label("Choice 2"), new Label("Choice 3"));
           vBox.setSpacing(5);
           popupView.setContent(vBox);
           return new View(button) {
            @Override
             protected void updateAppBar(AppBar appBar) {
               appBar.setTitleText("PopupView");
             }
           };
         });
       }
     }
     
    Since:
    2.2.0
    • Property Detail

      • popupPadding

        public final StyleableObjectProperty<Insets> popupPaddingProperty
        Space between the root node of the popup and each side of the scene. Does not affect computed width and height calculations.
        • The top padding is the difference between the top edge of the scene and popup. It will used when either the popup is laid out on top of the owner node or the sum of verticalOffset and layoutY of the root node is less than the top padding.
        • The right padding is the difference between the right edge of the scene and popup. Please note that when sideProperty() is set to PopupView.PopupSide.RIGHT, the popup is automatically laid out from the right edge of the owner node and not the right edge of the scene. Under such circumstances, if the distance between the right edge of the owner node and the scene is more than the right padding this value will be ignored.
        • The bottom padding is the difference between the bottom edge of the scene and the popup. It will only be used when the popup is laid out below the owner node.
        • The left padding is the difference between the left edge of the scene and popup. Please note that when sideProperty() is set to PopupView.PopupSide.LEFT, the popup is automatically laid out its from the left edge of the owner node and not the left edge of the scene. Under such circumstances, if the distance between the left edge of the owner node and the scene is more than the left padding this value will be ignored.

        Setting the value to null should be avoided.

        Style Guide:

        This property can be applied in css using "-fx-popup-padding" which accepts a double value.
        Default value:
        Insets.EMPTY
        Since:
        5.0.0
        See Also:
        getPopupPadding(), setPopupPadding(Insets)
    • Constructor Detail

      • PopupView

        protected PopupView​(Node ownerNode,
                            PopupRenderer renderer)
        Creates a PopupView using the owner node and renderer.
        Parameters:
        ownerNode - The node on which this popup is to be shown.
        renderer - The renderer to provide the root node for the popup.
        Throws:
        NullPointerException - when the ownerNode parameter is null
      • PopupView

        public PopupView​(Node ownerNode)
        Creates a new PopupView instance that will be displayed relative to the given ownerNode.
        Parameters:
        ownerNode - The node that the popup should be shown relative to.
      • PopupView

        public PopupView​(Node ownerNode,
                         Node content)
        Creates a new PopupView instance that will be displayed relative to the given ownerNode with the given content as its content.
        Parameters:
        ownerNode - The node that the popup should be shown relative to.
        content - The content of the popup.
    • Method Detail

      • setContent

        public final void setContent​(Node content)
        Sets the value of the property content.
        Property description:
        The content of the PopupView.
      • getContent

        public final Node getContent()
        Gets the value of the property content.
        Property description:
        The content of the PopupView.
      • setVerticalOffset

        public final void setVerticalOffset​(double offset)
        Sets the value of the property verticalOffset.
        Property description:
        By default the original position of the popup is over the owner node. This is the vertical offset from the original position from which to show the popup.
      • getVerticalOffset

        public double getVerticalOffset()
        Gets the value of the property verticalOffset.
        Property description:
        By default the original position of the popup is over the owner node. This is the vertical offset from the original position from which to show the popup.
      • popupPaddingProperty

        public final StyleableObjectProperty<Insets> popupPaddingProperty()
        Space between the root node of the popup and each side of the scene. Does not affect computed width and height calculations.
        • The top padding is the difference between the top edge of the scene and popup. It will used when either the popup is laid out on top of the owner node or the sum of verticalOffset and layoutY of the root node is less than the top padding.
        • The right padding is the difference between the right edge of the scene and popup. Please note that when sideProperty() is set to PopupView.PopupSide.RIGHT, the popup is automatically laid out from the right edge of the owner node and not the right edge of the scene. Under such circumstances, if the distance between the right edge of the owner node and the scene is more than the right padding this value will be ignored.
        • The bottom padding is the difference between the bottom edge of the scene and the popup. It will only be used when the popup is laid out below the owner node.
        • The left padding is the difference between the left edge of the scene and popup. Please note that when sideProperty() is set to PopupView.PopupSide.LEFT, the popup is automatically laid out its from the left edge of the owner node and not the left edge of the scene. Under such circumstances, if the distance between the left edge of the owner node and the scene is more than the left padding this value will be ignored.

        Setting the value to null should be avoided.

        Style Guide:

        This property can be applied in css using "-fx-popup-padding" which accepts a double value.
        Default value:
        Insets.EMPTY
        Since:
        5.0.0
        See Also:
        getPopupPadding(), setPopupPadding(Insets)
      • getPopupPadding

        public final Insets getPopupPadding()
        Gets the value of the property popupPadding.
        Property description:
        Space between the root node of the popup and each side of the scene. Does not affect computed width and height calculations.
        • The top padding is the difference between the top edge of the scene and popup. It will used when either the popup is laid out on top of the owner node or the sum of verticalOffset and layoutY of the root node is less than the top padding.
        • The right padding is the difference between the right edge of the scene and popup. Please note that when sideProperty() is set to PopupView.PopupSide.RIGHT, the popup is automatically laid out from the right edge of the owner node and not the right edge of the scene. Under such circumstances, if the distance between the right edge of the owner node and the scene is more than the right padding this value will be ignored.
        • The bottom padding is the difference between the bottom edge of the scene and the popup. It will only be used when the popup is laid out below the owner node.
        • The left padding is the difference between the left edge of the scene and popup. Please note that when sideProperty() is set to PopupView.PopupSide.LEFT, the popup is automatically laid out its from the left edge of the owner node and not the left edge of the scene. Under such circumstances, if the distance between the left edge of the owner node and the scene is more than the left padding this value will be ignored.

        Setting the value to null should be avoided.

        Style Guide:

        This property can be applied in css using "-fx-popup-padding" which accepts a double value.
        Default value:
        Insets.EMPTY
        Since:
        5.0.0
      • setPopupPadding

        public final void setPopupPadding​(Insets value)
        Sets the value of the property popupPadding.
        Property description:
        Space between the root node of the popup and each side of the scene. Does not affect computed width and height calculations.
        • The top padding is the difference between the top edge of the scene and popup. It will used when either the popup is laid out on top of the owner node or the sum of verticalOffset and layoutY of the root node is less than the top padding.
        • The right padding is the difference between the right edge of the scene and popup. Please note that when sideProperty() is set to PopupView.PopupSide.RIGHT, the popup is automatically laid out from the right edge of the owner node and not the right edge of the scene. Under such circumstances, if the distance between the right edge of the owner node and the scene is more than the right padding this value will be ignored.
        • The bottom padding is the difference between the bottom edge of the scene and the popup. It will only be used when the popup is laid out below the owner node.
        • The left padding is the difference between the left edge of the scene and popup. Please note that when sideProperty() is set to PopupView.PopupSide.LEFT, the popup is automatically laid out its from the left edge of the owner node and not the left edge of the scene. Under such circumstances, if the distance between the left edge of the owner node and the scene is more than the left padding this value will be ignored.

        Setting the value to null should be avoided.

        Style Guide:

        This property can be applied in css using "-fx-popup-padding" which accepts a double value.
        Default value:
        Insets.EMPTY
        Since:
        5.0.0
      • getSide

        public final PopupView.PopupSide getSide()
        Gets the value of the property side.
        Property description:
        The side of the owner node to which this Popup should stick to.
      • setSide

        public final void setSide​(PopupView.PopupSide value)
        Sets the value of the property side.
        Property description:
        The side of the owner node to which this Popup should stick to.
      • layoutChildren

        public void layoutChildren()
        Override this method to add the layout logic for your layer. Care should be taken to call this method in overriden methods for proper functioning of the Layer.
        Overrides:
        layoutChildren in class Layer
      • useContentSize

        protected boolean useContentSize()
        By default, PopupView uses the contentProperty()'s pref size to layout the content. If available bounds is less than the size of the content, the latter is resized to fit the same. When set to false, it uses the Region.getPrefWidth() and Region.getPrefHeight() of the PopupView to layout the content.

        In case, this is set to false, care should be taken to set the height and width of the view.

        Returns:
        true, if content size is to be used. Else, returns false.
      • getClassCssMetaData

        public static List<CssMetaData<? extends Styleable,​?>> getClassCssMetaData()
        Returns:
        The CssMetaData associated with this class, which may include the CssMetaData of its super classes.
        Since:
        JavaFX 8.0