How to create a dialog using JFXDialog of JFoenix in JavaFX - javafx

i search for an example for jfoenix jfxdialog anybody has working demo of this
JFXDialog dialog = new JFXDialog();

JFXDialog has three different constructors:
JFXDialog(),
JFXDialog(StackPane dialogContainer, Region content, DialogTransition transitionType) and
JFXDialog(StackPane dialogContainer, Region content, DialogTransition transitionType, boolean overlayClose)
The first one just sets the animationType to Center.
The second one sets the Parent(dialogContainer), the content(content) and the animationType(transitionType).
The third one sets the same as the second one + if the dialog should close if you click on the overlay(overlayClose).
For the parent of the Dialog you need a StackPane.
For the content you can use anything which is a child, grandchild, ... of Region. I would suggest you to use a JFXDialogLayout as it extends StackPane and makes it easier to style you dialog.
For the transitionType you have five different ones:
DialogTransition.TOP
DialogTransition.RIGHT
DialogTransition.BOTTOM
DialogTransition.LEFT
DialogTransition.CENTER
If you want to close it by clicking on the overlay set overlayClose to true, else set it to false
Some usefull methods which JFXDialog has:
setDialogContainer(StackPane dialogContainer) sets the Parent.
setContent(Region content) sets the Content of your Dialog.
setOverlayClose(final boolean overlayClose) you set wheter you want to close the Dialog by clicking on the overlay or not.
show(StackPane dialogContainer) shows the JFXDialog in the given StackPane
show() shows the JFXDialog in its parent
close() closes the JFXDialog
setTransitionType(DialogTransition transition) sets the DialogTransition to one of those mentioned before
setOnDialogClosed(EventHandler<? super JFXDialogEvent> handler) Defines a function to be called when the dialog is closed. It will be triggered after the close animation is finished.
setOnDialogOpened(EventHandler<? super JFXDialogEvent> handler) Defines a function to be called when the dialog is opened. It will be triggered after the show animation is finished.
JFXDialogLayout has just an empty constructor but contains out of a heading, body and actions.
The JFXDialogLayout class provides a setter for all those parts. Those are:
setHeading(Node... titleContent
setBody(Node... body)
setActions(Node... actions)
If you don't know, because of the three dots after Node you can add unlimited Nodes to all three parts. This is a feature called Varargs
For further information take a look at the demo on github at the Java controller JFoenix/Dialog Container and at the FXML file JFoenix/JFXDialog.fxml
Also here is the source code of the controls containing JFXDialog and JFXDialogLayout JFoenix/controls
I would suggest you to write your JavaFX applications seperated in Java, FXML and CSS files. Why Use FXML

Related

javafx deleting contents of an accordion pane

I have an accordion pane which contains three titled panes. I wish to delete these in the java program, however the Accordion object doesn't seem to have a clear or remove method to do this.
I have tried some ways to get around this such as the following:
if (!measureAccordion.getChildrenUnmodifiable().isEmpty()) {
ObservableList<javafx.scene.Node> accordionContent = measureAccordion.getChildrenUnmodifiable();
accordionContent.clear();
}
But this raised an UnsupportedOperationException.
If you check here accordion in javaFX , you will see that the accordion object has a method, getPanes(), which returns an ObservableList of TitledPane. The ObservableList has a lot of methods that you could use such as removeAll. You can see here the documentation for ObservableList.
Accordion is a control that can contain only TitledPane components. So if you want to modify content of Accordion then use Accordion#getPanes method.

Make ControlFx NotificationPane accept Node

ControlsFX has an awesome control called NotificationPane, which can easily be use like so
NotificationPane np = new NotificationPane();
np.setText("What to be displayed here");
What I am wondering, is it possible to extends it in such a way that, instead of it displaying text to display a Node.
You don't need to extends it. Just use the constructor that accepts a node.
http://controlsfx.bitbucket.org/org/controlsfx/control/NotificationPane.html#NotificationPane-javafx.scene.Node-
The Node that NotificationPane accepts in the constructor is actually the content pane OVER which the notification appears, not the content of the notification itself.
There is however a way to achieve what you asked. From the JavaDocs:
The graphic property represents the Node to show within the popup
notification bar that appears on top of the content that is within the
NotificationPane. Despite the term 'graphic', this can be an
arbitrarily complex scenegraph in its own right.
This means that you can indeed put complex Nodes (even whole trees) inside the notification. As long as the Text/Action properties are null, it will occupy all available space (or up to the preferred/max sizes of the node itself), leaving space for the closing button.

How to create an inner popup in JavaFX styled with FXML

I have an FXML file that I'm using to allow user input when requested. Right now I just put it in a new stage and do Stage.show(). I would like to not have it appear in a new window and behave more like a ContextMenu.
Looking at ContextMenu class it doesn't appear that I can set the content based off an FXML file. Is there a way to do this either with ContextMenu or Popup or some other class I am unaware of?
Although that library is quite nice, I wanted something simple that didn't require 3rd party downloads. I came up with this:
Popup popup = new Popup();
CustomController controller = new CustomController();
FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlfile));
loader.setController(controller);
popup.getContent().add((Parent)loader.load());
The problem was I didn't realize that a Parent could be considered a Node for the method Popup#getContent#add
ControlsFX has a PopOver control you might like. That PopOver can use any Node for its content, so you can simply create a popover, load a node from FXML and set the content of the popover to that node.

JavaFX, adding images in StackPane

I stuck at this stage, how add that 3 towers in to the StackPane and how to move the bricks inside that pane (from 1-2-3 for example) using only JavaFX code without Scene Builder? I would be grateful for any answers!
Image:
My suggestion:
You create a class "Tower" which extends the class Pane and contains a list of disks. The class has a method "accept" which returns boolean depending on whether you can put a disk there or not.
Create 3 instances of the class Tower.
Then you create a class "Disk" which extends the class Rectangle. Create 8 instances with varying width and add them to the first tower, ie the list of the class Tower.
Each Disk will use a mouselistener as described in Drag nodes like in a patience/Klondike card game. The mechanism is very similar to what you need.
In the mousepressed handler of the mouse listener you check whether the disk is on top of the tower or not and hence whether you can drag it or not.
In the mousereleased handler of the mouse listener you simply check whether a disk intersects (see boundsInParent and intersects) with a given tower. If it does and the accept method returns true, you drop it there. If the accept method returns false, you let it fly back to where it came from.
You're finished when a Tower has all of the disks.
That's basically it.
Oh, and don't use a StackPane, use a Pane instead. And you don't need images. The picture you show can be created solely of rectangles.

Context Menu of TableView in Child Widget

I am programming in C++ in QT and trying to make a UI with dynamic tabs having tables inside each of them. For doing the same, I had my TabWidget in the main window, and another widget with just the tableView. As the tabs are dynamically being added to the main window by a button click, I make a new object of my widget and put it in that.
I also have another version of the application in which there are no tabs, just a tableView in the main window.
I am unable to open the context menu in the former case, while it works perfectly for the latter.
I am using the signal "customContextMenuRequested" in both the cases. Don't understand what I need to add for it to work when the tableView is in a child widget.
Some help please?
Thanks already!
Did you check that nothing is involving QAbstractScrollArea, it's possible that in this case it would signal/slot as expected.
This signal is emitted when the widget's contextMenuPolicy is Qt::CustomContextMenu, and the user has requested a context menu on the widget. The position pos is the position of the context menu event that the widget receives. Normally this is in widget coordinates. The exception to this rule is QAbstractScrollArea and its subclasses that map the context menu event to coordinates of the viewport() .

Resources