Disable TitledPane Expand - javafx

How I can disable TitledPane expand?
TitledPane pane = new TitledPane("Connections", content);
I can't find any information about this on Google.

You dont need to google, you can simply check javadoc or Ctrl+space will show you all methods for that class. To answer your question its
titledPane.setCollapsible(false);

Related

How to disable dragndrop for tabpane in Javafx/Tornadofx?

My Scene already haves a dragndrop feature but now that I have made the root a TabPane, the TabPane creates a new tab if I drag files into my Program (my dragndrop feature still works). How can I disable this behaivior of the TabPane? I tried to consume the events in the setOnDragDropped and setOnDragOver of the scene but it seems like the events reaches the TabPane before it reaches my Scene.
Update:
I think its not possible for me to close the question (correct me if Im wrong), but I misinterpreted what was going on or what was the mistake, the whole Question was wrong. I solved the real problem with a workaround (by putting tabpane into vbox, so now vbox is the root).
The real problem is this: accesing nodes adds them into other nodes.
fun justManipulateNodes(){
someNode.add(...) //This line doesnt only manipulate someNode but it Adds someNode itself to where ever justManipulateNodes() is called. To be concrete, someNode is another vbox in my example and Im adding labels into it
}
override fun onBeforeShow() {
super.onBeforeShow()
this.currentStage?.scene?.setOnDragDropped {
//do other stuff
justManipulateNodes() //this call ads someNode into the Tabpane as a new Tab if it is the root
it.consume()
}

How to use a new window to let the user input data about an item in a list?

In my main window there is a list of items which the user can add to. I want to have a dialog window open each time they add an item where they can add information about that item such as the name of it etc., and then it will be added into the list on the main window with all provided data. I would also like them to be able to click on the item later and open the same dialog in which they can edit the data.
I am having trouble figuring out how to implement this, mainly in how to carry the information from the dialog back to the main window, and in the case of editing the item carrying the initial information already in the list to the dialog for it to be edited. What would be a good way to do this?
I am sure there is a common method for it since this is a very common feature in many software applications, I've just been unable to find guidance on how to do it.
In a previous application I sent the index of the item in the list to the dialog as well as a struct or enum of some kind containing the information between the windows so it could insert the item into the list at the correct index with the correct data, but this became very messy and clunky.
#FXML
private ListView<String> taskListView;
public void addTask() {
taskListView.getItems().add("New");
}
public void editTask() throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("EditWindowView.fxml"));
Stage stage = new Stage();
Scene scene = new Scene(root);
stage.initStyle(StageStyle.UNDECORATED);
stage.setTitle("Edit Task");
stage.setScene(scene);
stage.show();
}
I open the dialog with the editTask method so this is where I would put in information that needs to be carried back and forth, I'm just really unsure of how to do that.
I know this is quite a broad question so please bear with me. Even if anyone could provide a link to a tutorial which teaches something like this that would be greatly appreciated. If you need any more information from me please let me know. Thank you.

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.

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.

Make a javafx stage the owner of a JDialog?

Display a swings JDialog containing a JRViewer for Jasper Report, from within a javafx application menu item click. BUT the JDialog is not MODAL even after setModal(true) as it is not owned by javafx stage. How to make a javafx stage the owner of a JDialog? Alternatively how to display a Jasper report inside a javafx stage, scene?
Don't use a JDialog. In JavaFX you use Stages. Put your Jasper report inside a Scene, put the Scene in a Stage. I think you can't put Swing components inside JavaFX components, so you must check this link: Integrating JavaFX into Swing Applications
Code to make a JavaFX dialog:
Stage stage = new Stage();
stage.setTitle("Title");
stage.setResizable(false);
stage.initModality(Modality.APPLICATION_MODAL);
stage.initOwner(primaryStage);
stage.initStyle(StageStyle.UTILITY);
(...)
Scene scene = new Scene(...);
stage.setScene(scene);
In the code above the Stage will behave exactly like a dialog.
Also check this:
How to create a JavaFX dialog?
Hello World, JavaFX Style
Back to the first (base) question: It's not possible to make a Stage the owner of a JDialog. But, after setting the content of the SwingNode
swingNode.setContent(xxx);
you can get the parent of xxx (may be the parent of the parent of xxx too...) until you find a (AWT-) Frame or (AWT-) Dialog. In the case of SwingNode it's a JLightweightFrame. This object you can use as the owner to create your JDialog.
But, I think there is a bug in the JavaFX SwingNode mechanism. The JDialog appears functionally modal, if you set it modal (setModal(true)), but it may appear behind the main (JavaFX) window. It's still possible to move the main window, to bring it in front and so on, what should not be possible if there is a modal dialog. But this is another topic.
To view a Jasper Report in javafx ( jdk 1.8> ) stage
JasperPrint jp = JasperFillManager.fillReport(reportsource, params,getCon());
SwingNode swingNode = new SwingNode();
swingNode.setContent(new JRViewer(jp));
AnchorPane anchorPane = new AnchorPane();
AnchorPane.setTopAnchor(swingNode,0.0);
AnchorPane.setBottomAnchor(swingNode,0.0);
AnchorPane.setLeftAnchor(swingNode,0.0);
AnchorPane.setRightAnchor(swingNode,0.0);
anchorPane.getChildren().add(swingNode);
Scene scene = new Scene(anchorPane);
Stage stage = new Stage();
stage.setHeight(550);
stage.setWidth(600);
stage.setAlwaysOnTop(true);
stage.setScene(scene);
stage.showAndWait();
Alternatively how to display a Jasper report inside a javafx stage, scene?
Output HTML from your Jasper report and load the report in a JavaFX WebView.
Make a javafx stage the owner of a JDialog?
I don't think this is possible. What should work instead is to make your application a Swing application and host your JavaFX content inside a JFXPanel inside a Swing JFrame. Then you have no Stage and the owner of the JDialog can be the JFrame hosting the JFXPanel.
now it's possible to do that
what you need now is install jdk 8
because swing content in javafx is introduced in jdk8
#FXML
private SwingNode swingNode;
...
JasperPrint jasperPrint = JasperFillManager.fillReport(FileName, hash, connect);
swingNode.setContent(new JRViewer(jasperPrint));
oracle just add tutorial for this too
for the next you can follow this link
oracle tutorial embed swing in javaFX
I have written a JasperReports print preview stage class in JavaFX 8. It is a pure JavaFX code and there is no need for use of SwingNode class.
In comparison to the JRViewer it does not support links and parts, but print preview window does not need it anyway. On the other side, code is much, much shorter and therefore it is easy to understand and to adopt further to everyone's needs.
Source code for this class is freely available at GitHub repository.

Resources