Switch to another file page in JavaFX - javafx

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

Related

Add red asterisk to the beginning of text to a javafx label

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:

create javafx reusable components

When I was creating some app using javafx, I found similar constructs appear multiple times in my fxml files:
<HBox alignment="CENTER_LEFT" spacing="5">
<padding>
<Insets bottom="5.4" left="6.5" right="6.5" top="5.4" />
</padding>
<children>
......
</children>
</HBox>
The only differences are the children. I want to have some way to avoid specifying the common attributes everywhere. Is there a easy way to do that?
I know we can have custom components in javafx but that requires implementing a custom Controller class, which is over kill for my purpose.
Create a separate fxml for commonly used components and then add them in another fxml using fx:include tag..

FXML Button activate on enter

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.

Element does not define a default property

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

How to resolve TableView with css in Titanium Android Emulator

xsml file as below its display good in web browser but not showing in Android Emulator.
<Alloy >
<Window id="readWin" class="bg">
<TableView id="tableView">
<TableViewRow class="titlebar"></TableViewRow>
<TableViewRow></TableViewRow>
<TableViewRow>
<TextField class="serachbar"></TextField>
</TableViewRow>
<TableViewRow></TableViewRow>
<TableViewRow center="center" width="190" height="63">
<Button class="sbtn" id="subbtn"></Button>
</TableViewRow>
</TableView>
</Window>
</Alloy>
my index.tss code is like
'#tableView':{
separatorColor:'none'
}
"View":{
layout:'vertical',
},
".bg":{
backgroundImage:'images/bg.png',
},
".titlebar":{
backgroundImage:'images/logo.png',
width:'339dp',
height:'71dp',
top:'140dp'
},
'.serachbar':{
backgroundImage:'images/searchbar.png',
width:'400dp',
height:'50dp',
borderStyle:'none',
},
'.sbtn':{
backgroundImage:'images/btn.png',
width:'187dp',
height:'60dp',
borderStyle:'none',
}
my index.js file code is
$.readWin.open();
bg css is applying at window successfully but tableview data is not showing in Andriod Emulator event its good display in Web Browser. what can be the problem please help
Kind of an old post, but I thought I'd add my 2 cents. First, there's no way we can test this code because we don't have the referenced images. Second, remove all the dp references in your code by adding this line to your tiapp.xml <property name="ti.ui.defaultunit" type="string">dp</property>. Finally, explain what you've tried, and what you're trying to accomplish. Your post lacks a great deal of information that would allow others to help you.

Resources