Is it possible to activate multiple selection for a JavaFX TreeView with FXML?
If you want to set the selection mode programmatically, you would call
treeView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
But how can that be described in FXML? The best I came up with for now was:
<?import javafx.scene.control.TreeView.TreeViewBitSetSelectionModel?>
...
<TreeView>
<selectionModel>
<TreeViewBitSetSelectionModel selectionMode="MULTIPLE"/>
</selectionModel>
</TreeView>
This leads to this exception:
javafx.fxml.LoadException: TreeViewBitSetSelectionModel is not a valid type.
I assume that this is either because is not a public class or because it only has a non default constructor.
I read in the FXML documentation, that there are builders for various types, but I did not see a Builder or a Factory for selection model classes. Did I miss this?
Any hints on how to achieve this are very welcome!
Related
In DataFX & JavaFX there's many annotation do same thing. At least that's what I think. My question is when to use each one of these annotation?
#FXML
#FXMLController
#ViewNode
Let me describe each of these annotations and how they are relevant while using DataFX.
#FXML - This annotation enables an FXMLLoader to inject values defined in an FXML file into references in the controller class. It is a part of JavaFX.
#FXMLController - This annotations is used by the controller class to define its FXML file that contains the layout of the view.
#ViewNode and #ViewController - #ViewNode was introduced in DataFX as a successor to #FXML. With its introduction, #FXMLController was renamed to #ViewController. The entire commit can be found here.
Here is another good source of information.
I've searched several times here for answer but didn't get my solution.
In my case:
I want to take input from user and check validity. If everything is fine I will grab users ID from database and send that ID to another FXML and then run a select query there using that ID and display the results into a tableView.
In 2nd FXML (controller) I am using initialize() method to set data into tableView and a setId() method to receive user ID from previous FXML. But, initialize() method get called before setId() method and doesn't provide my required result as the ID is null.
Used Passing Parameters JavaFX FXML this method form passing data between FXML.
What will be the best solution for this?
FYI: Currently I'm using an extra class with static variable to store ID.
You could use a controller factory that initializes the id before it returns the controller instance:
FXMLLoader loader = new FXMLLoader(url);
loader.setControllerFactory(c -> {
MyController controller = new MyController();
controller.setId(userId);
return controller;
});
...
Node n = loader.load();
This way you could also use classes as controllers, that don't provide a default constructor. A more complex controller factory could be used to connect model and presenter (see MVP).
An alternative would be to modify the scene's contents in the setId method instead of the initialize method, which would be simpler than using a controller factory.
What the best solution is depends on your needs and personal preference. However, using a static member to pass data should be avoided, if possible.
When you use standard t:pagelink component you can pass arbitrary number of custom HTML attributes like class or some data attributes:
<t:pagelink page="somepage" data-somedata="test">link name</t:pagelink>
And they will be included in generated a tag:
link name
This does not work for components created by me. When I have:
<t:misc.custompagelink page="somepage" data-somedata="test">link name</t:misc.custompagelink>
The generated HTML looks like this:
link name
How to mimick the behaviour of standard t:pagelink component?
There are 2 ways to do this, both easy:
1) Read and follow the "Informal Parameters" section at http://tapestry.apache.org/component-parameters.html
2) Have your component class extend Tapestry's "Any" component (http://tapestry.apache.org/5.3/apidocs/org/apache/tapestry5/corelib/components/Any.html)
Is there a way to style the validation message (WrongValueException etc.)
Because it is absolutly not touch friendly.
I searched in the docs of zk but i found nothing.
Currently I use Zk 6.5.2
The validation messages are displayed in an ErrorBox widget.
The z class is z-errbox. Unfortunately, I don't believe ZK gives you a hook to specify a custom z class for any particular ErrorBox. This means the only way to override the style for an ErrorBox is to override the style for all ErrorBoxes. It sounds like that might work for you, if so, you can see the the ZK style class definitions in the source code.
For example, you could override the validation text color with..
.z-errbox-center {
color: blue;
}
As a side note, you'll probably want to hook your custom CSS file into ZK rather than manually loading it on the page. This will ensure it gets loaded as fast as possible and the user won't see the styles change as the page loads.
(in WEB-INF/zk.xml)
<desktop-config>
<theme-uri>/css/style.min.css</theme-uri>
</desktop-config>
You can read more about the theme-uri tag in the documentation.
I placed a ChoiceBox inside an fxml with JavaFX Scene Builder.
The FXML has a controller assigned to it.
My question is: Which event do I need to register if I want to know about changed values?
onInputMethodTextChanged="#languageSelectionModified"
this does not work with the following code
public void languageSelectionModified(Event event) {
ChoiceBox<String> box = (ChoiceBox<String>) event.getSource();
System.out.println(box.getValue());
}
and this only works for the initial click (i.e. opening the list, not when selecting an item):
onMouseClicked="#languageSelectionModified"
Although the Mouse-Events would never be a good choise because of situations where the touch or keyboard is the input-method, it still proves that the System.out can be reached.
I have absolutly no idea where those things are documentated (in the default Java-API they are not)
Add a listener to your #FXML injected choicebox in your controller:
choicebox.getSelectionModel().selectedItemProperty().addListener(choiceboxSelectionChangeListener);
You can also bind to the selected item:
label.textProperty().bind(choicebox.getSelectionModel().selectedItemProperty());
Here is an example of hooking up a listener in a controller for a ComboBox defined in FXML. Logic for a ChoiceBox is pretty much identical.
You can also use FXML onAction attribute:
<ChoiceBox onAction="#languageSelectionModified" />