I need to us a .fxml file to build my GUI. I need actually need to make it work without a mouse, just keyboard action....
So, here is the button in fxml:
<HBox spacing="10" alignment="bottom_right"
GridPane.columnIndex="1" GridPane.rowIndex="4">
<Button text="Login"
onAction="#handleSubmitButtonAction"/>
</HBox>
First of all, I just need this button to do the "handleSubmitButtonAction" event, when the enter key is pressed. (If you have any tips on the secondary objective: getting the arrow keys to navigate through buttons, than by all means fire away ;) )
button.setDefaultButton(true)
Or if you are using FXML:
<Button text="Login"
defaultButton="true"
onAction="#handleSubmitButtonAction"/>
From the javadoc:
A default Button is the button that receives a keyboard VK_ENTER press, if no other node in the scene consumes it.
Related
I have a scene (created in SceneBuilder) with a number of labels some of which I want to show as required fields by adding a red asterisk at the beginning of the label text. I cannot see how to do this in SceneBuilder. Is there a way of doing this using CSS.
Below is the label snippet form the FXML file:
<Label fx:id="lblFirstName" alignment="CENTER_RIGHT" prefHeight="17.0" prefWidth="295.0" text="First Name:" GridPane.columnIndex="1" GridPane.rowIndex="2">
<padding>
<Insets right="10.0" />
</padding>
</Label>
Everything I have found so far relates to HTML files.
Slaw suggestion is good, but I would suggest another way using validation.
Note that this method requires ControlsFX library and some code in your controller (can't be done in css as you mentioned).
In your controller class create a validator:
ValidationSupport validationSupport = new ValidationSupport();
Add validation (as a required field) to your node (TextField in this example) inside initialize method:
validationSupport.registerValidator(myTextField, Validator.createEmptyValidator("Field is required"));
Now when you run your application the required TextField will look like this:
If the focus is lost from TextField and it doesn't have any text in it, it will show a red X like this:
I have a very simple Xamarin Forms application that navigates between two pages.
On the second page (the page being navigated to) the following XAML content exists:
<StackLayout>
<Button Text="TEST" />
</StackLayout>
When the page has this content, the page appears to render correctly. However, if I change the XAML to this:
<StackLayout HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand">
<Button Text="TEST" />
</StackLayout>
The button background appears to be transparent until I hover over the button. It appears that any combination of values for the HorizontalOptions and VerticalOptions properties causes this effect.
Interestingly, if I set the second page as the root page, the button background is not transparent even when the properties are set.
I am using the Prism framework if that makes any difference.
What am I missing? Is this behavior correct?
Should anyone stumble upon this question, I submitted an issue on GitHub (here). It has been confirmed as a bug.
In my FXML i have a simple empty VBox inside an AnchorPane:
<VBox fx:id="clients" spacing="10" AnchorPane.rightAnchor="50.0" AnchorPane.topAnchor="150.0">
<children>
</children>
</VBox>
Then I want to add a node to the VBox in java class:
clients.getChildren().add(0, customObject.getGridPane());
But the node doesn't show up, VBox keeps empty.
If I simply add any node to the FXML then later adding a node in java works but not if it starts empty.
This works:
<VBox fx:id="clients" spacing="10" AnchorPane.rightAnchor="50.0" AnchorPane.topAnchor="150.0">
<children>
<Label />
</children>
</VBox>
It must be an easy thing I'm missing but couldn't find the answer anywhere.
I tried it and it's working fine the problem is in this code customObject.getGridPane() make sure that it get a node I added a Button and it's working fine
Note: label didn't show because of text color try a button
use addAll method instead of add
clients.getChildren().addAll(0, customObject.getGridPane());
I'm making a simple application for school, but one thing just wont work. I'm trying to make a button, that when you press it, you go to another page, aka, loads a new fxml file.
here's my code for the buttons so far.
<Button prefWidth="240.0" styleClass="first, active" text="HOME">
<VBox.margin>
<Insets top="40.0" />
</VBox.margin>
</Button>
<Button prefWidth="240.0" styleClass="first, active" text="Dashboard">
<VBox.margin>
<Insets top="40.0" />
</VBox.margin>
</Button>
and I cant seem to make the button for Dashboard work so that it loads the Dashboard Page
i'm not sure if I totally understood your question but here's a possible solution : Follow the tutorial in this : managing multiple screens in javafx
it's clear, easy and well organised and you can dowload the full implementation with three testing screens
I'm working with JavaFX and trying to use FXML, however I've never had any sort of formal training in it, so I'm kind of stumbling about.
I keep running into this here error:
Caused by: javafx.fxml.LoadException: Element does not define a default property.
My aim is to try to initialize a Custom Controller class that runs its own FXML file. The code example given by Oracle therefore looks like this:
<fx:root type="javafx.scene.layout.VBox" xmlns:fx="http://javafx.com/fxml">
<TextField fx:id="textField"/>
<Button text="Click Me" onAction="#doSomething"/>
</fx:root>
where the controller and root is set in the Controller method.
I'm trying to adapt this code to my own needs, and I was wondering if someone could explain to me why this error comes up if the fx:root type="javafx.scene.layout.VBox" is ever changed to something like fx:root type="javafx.scene.Parent" if you want me to, I can post some actual code samples.
The concept of default-property is introduced to short circuit your FXML in reality you'd have to write:
<fx:root type="javafx.scene.layout.VBox" xmlns:fx="http://javafx.com/fxml">
<children>
<TextField fx:id="textField"/>
<Button text="Click Me" onAction="#doSomething"/>
</children>
</fx:root>
if you now change the container type to Parent and you browse the parent class you'll notice that it does not define a children-property which you implicitly assume - children is introduced by Pane.
You should probably read http://docs.oracle.com/javafx/2/api/javafx/fxml/doc-files/introduction_to_fxml.html