When I do an fx:include in my fxml file, I got this error:
Caused by: java.lang.NullPointerException
at javafx.fxml.FXMLLoader.equals(FXMLLoader.java:1856)
at javafx.fxml.FXMLLoader.isCyclic(FXMLLoader.java:1868)
at javafx.fxml.FXMLLoader.access$2100(FXMLLoader.java:71)
at javafx.fxml.FXMLLoader$IncludeElement.constructValue(FXMLLoader.java:941)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:570)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2356)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2172)
Here is my root file:
<fx:root type="javafx.scene.layout.AnchorPane" fx:id="scrollPane" id="scrollStocksList"
xmlns:fx="http://javafx.com/fxml"
fx:controller="net.StocksListRunningController">
<fx:include fx:id="tableListStock"
source="/fxml/stocksList.fxml" />
</fx:root>
And my include file:
<fx:root type="javafx.scene.layout.VBox" xmlns:fx="http://javafx.com/fxml"
fx:controller="net.StockListTableController">
<TableView fx:id="stocksList" onMouseClicked="#openDetail">
<columns>
<TableColumn text="Titre" prefWidth="125">
<cellValueFactory>
<PropertyValueFactory property="title" />
</cellValueFactory>
</TableColumn>
</columns>
</TableView>
</fx:root>
If I remove my fx:include in my root file, all work fine.
I use the lastest version of java fx provided by jdk 7.0.51.
What is wrong in my include file (or other) ?
Thanks.
Here is the solution.
Add this line for the loader:
loader.setLocation(JfxUtils.class.getResource(fxml));
Very bad bug.
Related
I am developing a dialog box inside the scenebuilder and I can see there the size is 625x616 (I am using gridpane), however when I run the tool it looks much bigger (around 900x900).
This is the code I use to load the fxml file
private void DisplayDialog(String title, String fxmlPath) throws IOException {
final Stage dialog = new Stage();
dialog.initModality(Modality.APPLICATION_MODAL);
dialog.initOwner(primaryStage);
dialog.setResizable(false);
dialog.setTitle(title);
dialog.getIcons().add(primaryStage.getIcons().get(0));
Parent root = FXMLLoader.load(getClass().getResource(fxmlPath));
Scene dialogScene = new Scene(root);
dialog.setScene(dialogScene);
dialog.show();
logger.exit();
}
and here it is my fxml file:
<GridPane hgap="5.0" vgap="10.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ca.mali.dialogs.chapter6.UpdateAttributeValuesServiceController">
<columnConstraints>
<ColumnConstraints hgrow="NEVER" maxWidth="300.0" minWidth="200.0" prefWidth="200.0" />
<ColumnConstraints hgrow="NEVER" prefWidth="400.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="-Infinity" vgrow="SOMETIMES" />
<RowConstraints vgrow="SOMETIMES" />
<RowConstraints maxHeight="-Infinity" vgrow="SOMETIMES" />
<RowConstraints maxHeight="-Infinity" vgrow="SOMETIMES" />
<RowConstraints maxHeight="-Infinity" vgrow="SOMETIMES" />
</rowConstraints>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<HBox alignment="CENTER_RIGHT" GridPane.columnIndex="1" GridPane.rowIndex="4">
<Button cancelButton="true" mnemonicParsing="false" onAction="#Cancel_click" text="Cancel">
<HBox.margin>
<Insets right="20.0" />
</HBox.margin>
</Button>
<Button fx:id="OkButton" defaultButton="true" disable="true" mnemonicParsing="false" onAction="#OK_click" text="OK" />
</HBox>
<Label text="Instance Name: " GridPane.halignment="RIGHT" />
<ComboBox fx:id="InstanceName" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" />
<TableView fx:id="AttributeValueTableView" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" GridPane.columnSpan="2" GridPane.rowIndex="1">
<columns>
<TableColumn fx:id="AttributeTableColumn" editable="false" maxWidth="1.7976931348623157E308" minWidth="50.0" prefWidth="200.0" text="Attribute" />
<TableColumn fx:id="ValueTableColumn" maxWidth="1.7976931348623157E308" minWidth="50.0" prefWidth="400.0" text="Value" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
<Label text="User-supplied tag*:" GridPane.halignment="RIGHT" GridPane.rowIndex="2" />
<TextField fx:id="UserSuppliedTag" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label text="Logical Time:" GridPane.halignment="RIGHT" GridPane.rowIndex="3" />
<Spinner fx:id="LogicalTimeSpin" editable="true" GridPane.columnIndex="1" GridPane.rowIndex="3" />
</GridPane>
I also tried to replace Gridpane with VBox but I got the same results.
I embedded a png in as3, it's all fine on windows, either use FB4.6 or Ant. But while build with Ant under linux(debian), I got this Error. Image path is /var/lib/jenkins/workspace/q5/dev_Flash/code/Copper/src/assets/c001_up.png. Project name is /var/lib/jenkins/workspace/q5/dev_Flash/code/Copper.
[mxmlc] /var/lib/jenkins/workspace/q5/dev_Flash/code/Copper/src/com/copper/ui/skin/DefaultAssets.as(10): col: 3: Error: unable to resolve 'assets/c001_up.png' for transcoding
[mxmlc]
[mxmlc] [Embed(source = "assets/c001_up.png")]
[mxmlc] ^
[mxmlc]
[mxmlc] /var/lib/jenkins/workspace/q5/dev_Flash/code/Copper/src/com/copper/ui/skin/DefaultAssets.as(10): col: 3: Error: Unable to transcode assets/c001_up.png.
as3 file like this
package com.copper.ui.skin {
/**
*
* #author marzwu
*
*/
public class DefaultAssets extends Assets {
[Embed(source = "assets/c001_up.png")]
private var Button_Up:Class;
My ant file is:
<?xml version="1.0" encoding="UTF-8"?>
Q5客户端构建
<!-- 配置属性 -->
<property file="build.properties" />
<property environment="env" />
<property name="FLEX_HOME" value="${env.FLEX_HOME}" />
<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
<target name="compile">
<echo message="${basedir}/../src" />
<compc output="../bin/copper.swc" debug="false" incremental="true">
<!-- 指定Comman项目的源码目录 -->
<source-path path-element="${basedir}/../src" />
<!-- 指定编译的文件列表 -->
<include-sources dir="${basedir}/../src">
<include name="**/*.as" />
</include-sources>
<!-- 将Flex SDK 作为外部库进行引用 -->
<compiler.external-library-path dir="${FLEX_HOME}/frameworks">
<include name="**/*.swc" />
</compiler.external-library-path>
<!-- 添加项目中的SWC包,请注意这里是外部 -->
<compiler.external-library-path dir="../libs">
<include name="**/*.swc" />
</compiler.external-library-path>
<define name="CONFIG::Debug" value="true" />
<define name="CONFIG::Release" value="false" />
<jvmarg value="-Xmx2048m"/>
<jvmarg value="-Xms512m"/>
<jvmarg value="-XX:MaxPermSize=512m"/>
</compc>
<!-- 删除缓存文件 -->
<delete>
<fileset dir="../bin" includes="*.cache" />
</delete>
<echo message="complier Flex Library Project finished!" />
</target>
<target name="deploy">
<antcall target="compile" />
<!--antcall target="copy_to_bin" /-->
<echo>前往查看结果:http://10.0.1.69/q5d/</echo>
<echo message="执行发布" />
</target>
I use jenkins to build my as3 project. It's bother me for many day. Appreciate for your helping.
Oops, compiler can't resolve the path, because I did not notice the "u" between "c001_up.png" is an upper case letter. Windows are not sensitive of letter case, but linux are. My fault, thank you for your time.
In the JavaFX Scene Builder, is it somehow possible to view the FXML code for the current layout without saving to a file and view the saved file?
right click on the root node in scene builder and then choose copy . and paste it in any text editor.
out put :
<Group id="sb-clipboard" xmlns:fx="http://javafx.com/fxml">
<fx:define>
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0">
<children>
<Button id="button1" layoutX="140.0" layoutY="104.0" mnemonicParsing="false" text="Button" />
<RadioButton id="radioButton1" layoutX="283.0" layoutY="172.0" mnemonicParsing="false" text="RadioButton" />
<ToggleButton id="toggleButton1" layoutX="94.0" layoutY="234.0" mnemonicParsing="false" text="ToggleButton" />
</children>
</AnchorPane>
</fx:define>
</Group>
I'm new in JavaFX and have a little troubles:
I have an TabPane with several Tabs and I wanna make Tab titles invisible. So, user should not change Tabs by clicking on titles, but it will be changed in different way from menu..
How to make this Tab titles invisible/hidden? That's the question. I don't wanna hide whole Tabs or disable or anything like that, just titles.
Or maybe you have another, completely different idea, how to solve this in JavaFX. Maybe with another controls???
Thanks for any clue.
If you are not using Tabs then you don't need TabPane.
You can just introduce a list of content panes and switch them according to menu commands.
You can find a code example in next question: How can I implement the functionality of awt.CardLayout in my javaFX 2.0 application?
Conclusion of my research: This is not possible to do this in JavaFX. TabPane captions can be located on the top, left, right and bottom of the control, but cannot be hidden.
You can make this by wrapping TabPane in AnchorPane (root container) and setting up TabPane's topAnchor to negative number as much as needed.
Java code:
...
AnchorPane.setTopAnchor(myTabPane, -29.0);
AnchorPane.setBottomAnchor(myTabPane, 0);
AnchorPane.setLeftAnchor(myTabPane, 0);
AnchorPane.setRightAnchor(myTabPane, 0);
...
Also in FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.*?>
<?import javafx.scene.layout.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<TabPane fx:id="myTabPane" prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="-29.0">
<tabs>
<Tab fx:id="tab1" text="Tab 1">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<Label text="Tab 1" />
<Button layoutX="35.0" layoutY="2.0" mnemonicParsing="false" text="Go to Tab 2 (non-functional currently)" />
</children>
</AnchorPane>
</content>
</Tab>
<Tab fx:id="tab2" text="Tab 2">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<Label text="Tab 2" />
<Button layoutX="35.0" layoutY="2.0" mnemonicParsing="false" text="Go to Tab 1 (non-functional currently)" />
</children>
</AnchorPane>
</content>
</Tab>
</tabs>
</TabPane>
</children>
</AnchorPane>
I am building a application in JavaFx 2.0 and would like to, when the application is deployed, to have it show up on the center of the window of a browser. I have looked for this topic in google and yahoo and found nothing. Any help is greatly appreciated.
Look at the source code for the JavaFX Ensemble example. The Ensemble application is configured to run to fill a browser window, no matter the size of the window. The way it is done is by configuration in the JavaScript which launches the app as well as via css styling of the div the application is embedded in.
Here is an extract of the relevant parts of the html.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaFX 2.0 - Ensemble</title>
<SCRIPT src="http://java.com/js/dtjava.js"></SCRIPT>
<script>
function javafxEmbed_ensemble() {
dtjava.embed(
{
id : 'ensemble',
url : 'Ensemble.jnlp',
placeholder : 'javafx-app-placeholder',
width : '100%',
height : '100%',
jnlp_content : '...'
},
{
javafx : '2.0+'
},
{}
);
}
dtjava.addOnloadCallback(javafxEmbed_ensemble);
</script>
<style>
html, body, #javafx-app-placeholder, #ensemble-app {
margin: 0;
overflow: hidden;
padding: 0;
width: 100%;
height: 100%;
}
</style>
</head>
<body><div id='javafx-app-placeholder'></div></body>
</html>
If you need something other than 100% coverage, you can the 100% tags to, say 75%, and adjust the css styling to get centering in the page with the margins you want.
The current Java packaging tools (e.g. the javafxpackager utility), do not allow specification of percentange widths. I've created a feature request for this in the javafx jira - you can create an account there to view the request. If you use those tools to generate your deployment html, then you might have to modify the deployment html by hand or by a post-processing ant script, as can be seen in the build.xml for the Ensemble sample application.
You can use combination of HBox and VBox panels in your FXML. Hier is my tested code:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane fx:id="panel1" xmlns:fx="http://javafx.com/fxml" fx:controller="app.MainController">
<HBox alignment="CENTER" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<VBox alignment="CENTER">
<Pane fx:id="panel2"></Pane> <!-- YOUR CENTERED CONTENT HERE! -->
</VBox>
</HBox>
</AnchorPane>
The 'panel1' will stretch in the browser area. So the HBox and VBox will also. Because they have 'center' attributes for their childeren, the 'panel2' will be centered.
Use this FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml">
<children>
<HBox id="HBox" alignment="CENTER" spacing="5.0" AnchorPane.bottomAnchor="213.0" AnchorPane.leftAnchor="168.0" AnchorPane.rightAnchor="168.0" AnchorPane.topAnchor="214.0">
<children>
<GridPane id="gridPane1" alignment="CENTER" hgap="2.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" vgap="2.0">
<children>
<Label id="label1" alignment="CENTER_RIGHT" contentDisplay="RIGHT" text="Username" GridPane.columnIndex="0" GridPane.rowIndex="0" />
<Label id="label2" alignment="CENTER_RIGHT" text="Password" GridPane.columnIndex="0" GridPane.rowIndex="1" />
<TextField id="textField1" fx:id="userid" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="0" />
<PasswordField id="passwordField1" fx:id="password" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Button id="button1" alignment="CENTER_RIGHT" text="Signin" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="2" />
</children>
<columnConstraints>
<ColumnConstraints halignment="CENTER" hgrow="NEVER" maxWidth="-Infinity" minWidth="-Infinity" percentWidth="0.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
</columnConstraints>
<padding>
<Insets bottom="2.0" left="4.0" right="4.0" top="2.0" />
</padding>
<rowConstraints>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
</children>
</HBox>
</children>
</AnchorPane>
Might solve your problem
Try to use a StackPane as container. It will center all nodes it includes.
Torsten