I am trying to center a label spanning two columns of a GridPane. However, it does not seem to work.
Application class:
public class GUIMainFXML extends Application {
#Override
public void start(Stage primaryStage) {
try {
GridPane p = (GridPane) FXMLLoader.load(getClass().getResource(
"FirstGUIexample.fxml"));
Scene scene = new Scene(p);
scene.getStylesheets().add(
getClass().getResource("application.css").toExternalForm());
primaryStage.setTitle("Welcome (FXML CODE)");
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}}
fxml file:
<GridPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
hgap="5" vgap="5">
<padding>
<Insets top="10" right="10" bottom="10" left="10" />
</padding>
<children>
<Text text="Welcome" GridPane.columnSpan="2" GridPane.halignment="CENTER"
GridPane.rowIndex="0" />
<Button text="Press me" GridPane.halignment="CENTER"
GridPane.rowIndex="1" GridPane.columnSpan="2" />
<CheckBox text="Don't touch me" GridPane.rowIndex="2"
GridPane.halignment="CENTER" GridPane.columnSpan="2" />
<Label text="Type me: " GridPane.halignment="CENTER"
GridPane.columnIndex="1" GridPane.rowIndex="3" />
<TextField GridPane.rowIndex="3" GridPane.columnIndex="2"
GridPane.halignment="CENTER" />
</children>
</GridPane>
application.css
Text {
-fx-font-size: 15pt;
-fx-font-family: Tahoma;
-fx-font-weight: bold;
}
I would like to set it either in the css or in the fxml, I am just testing.
You haven't provided the columnIndex for Text and Button, which you want to align in the center.
<Text text="Welcome" GridPane.columnSpan="2" GridPane.halignment="CENTER"
GridPane.columnIndex="1" GridPane.rowIndex="0" id="argh" />
<Button text="Press me" GridPane.halignment="CENTER" GridPane.columnIndex="1"
GridPane.rowIndex="1" GridPane.columnSpan="2" />
Related
I'm Creating a loading screen for my application which has complex Neumorphism Design using InnerShadow, although CPU and RAM usage is less, the application causes lagging effect for animation like Circular Progress Indicator of Gluon charm-glisten.jar as well as PathTransition animation. In this loading screen you can see a red rectangle moving around the design and the progress indicator in blue color in the innermost layer
Java Code:
package application;
import java.net.URL;
import java.util.*;
import com.gluonhq.charm.glisten.control.ProgressIndicator;
import javafx.animation.*;
import javafx.animation.PathTransition.*;
import javafx.application.*;
import javafx.concurrent.*;
import javafx.event.*;
import javafx.fxml.*;
import javafx.stage.*;
import javafx.util.*;
import javafx.scene.*;
import javafx.scene.input.*;
import javafx.scene.layout.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
public class Main extends Application implements Initializable
{
private double xOffset = 0;
private double yOffset = 0;
#FXML
ProgressIndicator pg1;
static AnchorPane root;
private PathTransition pathTransitionCircle;
public void start(Stage primaryStage)
{
try
{
primaryStage.initStyle(StageStyle.TRANSPARENT);
root = FXMLLoader.load(getClass().getResource("Test1.fxml"));
Scene scene = new Scene(root,600,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
scene.setFill(javafx.scene.paint.Color.TRANSPARENT);
primaryStage.setScene(scene);
primaryStage.show();
root.setOnMousePressed(new EventHandler<MouseEvent>()
{
public void handle(MouseEvent e)
{
xOffset = e.getSceneX();
yOffset = e.getSceneY();
}
});
root.setOnMouseDragged(new EventHandler<MouseEvent>()
{
public void handle(MouseEvent e)
{
primaryStage.setX(e.getScreenX() - xOffset);
primaryStage.setY(e.getScreenY() - yOffset);
}
});
Rectangle rect2 = new Rectangle(0, 0, 20, 20);
rect2.setArcHeight(10);
rect2.setArcWidth(10);
rect2.setFill(Color.RED);
root.getChildren().add(rect2);
Path path2 = createEllipsePath(400, 200, 150, 150, 0);
path2.setLayoutX(57);
path2.setLayoutY(10);
root.getChildren().add(path2);
pathTransitionCircle = new PathTransition();
pathTransitionCircle.setDuration(Duration.seconds(6));
pathTransitionCircle.setPath(path2);
pathTransitionCircle.setNode(rect2);
pathTransitionCircle.setOrientation(OrientationType.ORTHOGONAL_TO_TANGENT);
pathTransitionCircle.setCycleCount(PathTransition.INDEFINITE);
pathTransitionCircle.setInterpolator(Interpolator.LINEAR);
pathTransitionCircle.setAutoReverse(false);
pathTransitionCircle.play();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
launch(args);
}
#Override
public void initialize(URL arg0, ResourceBundle arg1)
{
Task<Void> task = new Task<Void>()
{
protected Void call() throws Exception
{
for (int i = 0; i <= 100; i++)
{
updateProgress(i, 100);
Thread.sleep(40);
}
//Platform.runLater(() -> primaryStage.close());
return null;
}
};
pg1.progressProperty().unbind();
pg1.progressProperty().bind(task.progressProperty());
Thread th = new Thread(task);
th.setDaemon(true);
th.start();
task.setOnSucceeded(new EventHandler<WorkerStateEvent>()
{
public void handle(WorkerStateEvent arg0)
{
try
{
/*primaryStage.close();
primaryStage = null;
System.gc();
FXML_Loader f1 = new FXML_Loader();
f1.intermediate();*/
}
catch (Exception e)
{
e.printStackTrace();
}
}
});
}
private Path createEllipsePath(double centerX, double centerY, double radiusX, double radiusY, double rotate)
{
ArcTo arcTo = new ArcTo();
arcTo.setX(centerX - radiusX + 1); // to simulate a full 360 degree celcius circle.
arcTo.setY(centerY - radiusY);
arcTo.setSweepFlag(false);
arcTo.setLargeArcFlag(true);
arcTo.setRadiusX(radiusX);
arcTo.setRadiusY(radiusY);
arcTo.setXAxisRotation(rotate);
Path path = new Path();
path.getElements().addAll(
new MoveTo(centerX - radiusX, centerY - radiusY),
arcTo,
new ClosePath()); // close 1 px gap.
path.setStroke(Color.BLUE);
path.getStrokeDashArray().setAll(5d, 5d);
return path;
}
}
FXML Code:
<?xml version="1.0" encoding="UTF-8"?>
<?import com.gluonhq.charm.glisten.control.ProgressIndicator?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.effect.InnerShadow?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: transparent;" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Main">
<children>
<VBox alignment="CENTER" layoutX="163.5" layoutY="63.5" prefHeight="290.0" prefWidth="290.0" style="-fx-background-color: #3D4956; -fx-background-radius: 150;">
<effect>
<InnerShadow color="#00000070" offsetX="-4.0" offsetY="-4.0">
<input>
<InnerShadow color="#a7a7a7bf" offsetX="4.0" offsetY="4.0" />
</input>
</InnerShadow>
</effect>
<children>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: #3D4956; -fx-background-radius: 150;" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</VBox.margin>
<effect>
<InnerShadow color="#0000008c" offsetX="4.0" offsetY="4.0">
<input>
<InnerShadow color="#a6a6a65c" offsetX="-4.0" offsetY="-4.0" />
</input>
</InnerShadow>
</effect>
<children>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: #3D4956; -fx-background-radius: 150;" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</VBox.margin>
<effect>
<InnerShadow color="#0000008c" offsetX="-4.0" offsetY="-4.0">
<input>
<InnerShadow color="#a6a6a65c" offsetX="4.0" offsetY="4.0" />
</input>
</InnerShadow>
</effect>
<children>
<VBox prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: #3D4956; -fx-background-radius: 150;" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</VBox.margin>
<effect>
<InnerShadow color="#0000008c" offsetX="4.0" offsetY="4.0">
<input>
<InnerShadow color="#a6a6a65c" />
</input>
</InnerShadow>
</effect>
<children>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: #3D4956; -fx-background-radius: 150;" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</VBox.margin>
<effect>
<InnerShadow color="#0000008c" offsetX="-4.0" offsetY="-4.0">
<input>
<InnerShadow color="#a6a6a65c" offsetX="4.0" offsetY="4.0" />
</input>
</InnerShadow>
</effect>
<children>
<AnchorPane prefHeight="58.0" prefWidth="141.0" style="-fx-background-color: #3D4956; -fx-background-radius: 150;" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</VBox.margin>
<effect>
<InnerShadow color="#0000008c" offsetX="4.0" offsetY="4.0">
<input>
<InnerShadow color="#a6a6a65c" offsetX="-4.0" offsetY="-4.0" />
</input>
</InnerShadow>
</effect>
<children>
<ImageView fitHeight="42.0" fitWidth="50.0" layoutX="49.0" layoutY="40.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#logo/database1.png" />
</image>
</ImageView>
<Label layoutX="57.0" layoutY="81.0" prefHeight="19.0" prefWidth="34.0" text="SQL" textFill="YELLOW">
<font>
<Font name="System Bold Italic" size="14.0" />
</font>
</Label>
<Label layoutX="38.0" layoutY="97.0" prefHeight="20.0" prefWidth="73.0" text="Developer" textFill="YELLOW">
<font>
<Font name="System Bold Italic" size="14.0" />
</font>
</Label>
<ProgressIndicator fx:id="pg1" layoutX="8.0" layoutY="7.0" prefHeight="108.0" prefWidth="122.0" progress="1.0" radius="60.0" />
</children>
</AnchorPane>
</children>
</VBox>
</children>
</VBox>
</children>
</VBox>
</children>
</VBox>
</children>
</VBox>
</children>
</AnchorPane>
Loading Screen Design
I am in the process of creating a javafx desktop application. The problem I'm encountering is if I add a controller to my fxml files the controls dissapear somehow. The program uses a fade transition to switch between the fxml files
AnchorPane reorderLevels,purchaseorder,onlineSales,generalLedger
,cashBook,payments,departmentalTransfers
,purchaseInvoice
,productMantainance,
branchTransfers,stockMovement,invoiceRegistration,stockTake;
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#Override
public void initialize(URL url, ResourceBundle rb) {
//load all the fxml screens when the buttons are clicked
try {
//screens for the application
reorderLevels = FXMLLoader.load(getClass().getResource("ReorderLevels.fxml"));
purchaseorder = FXMLLoader.load(getClass().getResource("PurchaseOrder.fxml"));
onlineSales = FXMLLoader.load(getClass().getResource("OnlineSales.fxml"));
generalLedger = FXMLLoader.load(getClass().getResource("GeneralLedger.fxml"));
cashBook = FXMLLoader.load(getClass().getResource("CashBook.fxml"));
departmentalTransfers = FXMLLoader.load(getClass().getResource("DepartmentalTransfers.fxml"));
purchaseInvoice = FXMLLoader.load(getClass().getResource("PurchaseInvoice.fxml"));
productMantainance = FXMLLoader.load(getClass().getResource("ProductMantainance.fxml"));
branchTransfers = FXMLLoader.load(getClass().getResource("BranchTransfers.fxml"));
stockMovement = FXMLLoader.load(getClass().getResource("StockMovement.fxml"));
payments = FXMLLoader.load(getClass().getResource("Payments.fxml"));
invoiceRegistration = FXMLLoader.load(getClass().getResource("InvoiceRegistration.fxml"));
stockTake = FXMLLoader.load(getClass().getResource("StockTake.fxml"));
//set each and every individual node when the buttons are clicked
setNode(reorderLevels);
} catch (IOException ex) {
Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void setNode(Node node) {
holderPane.getChildren().clear();
holderPane.getChildren().add((Node) node);
//the transition between the screens
FadeTransition ft = new FadeTransition(Duration.millis(1));
ft.setNode(node);
ft.setFromValue(0.1);
ft.setToValue(1);
ft.setCycleCount(1);
ft.setAutoReverse(false);
ft.play();
}
/* screens */
#FXML
private void switchReorderLevels(ActionEvent event) {
setNode(reorderLevels);
}
#FXML
private void switchOnlineSales(ActionEvent event) {
setNode(onlineSales);
}
#FXML
private void switchGeneralLedger(ActionEvent event) {
setNode(generalLedger);
}
#FXML
private void switchPurchaseOrder(ActionEvent event) {
setNode(purchaseorder);
}
#FXML
private void switchCashBook(ActionEvent event) {
setNode(cashBook);
}
#FXML
private void switchAlert(ActionEvent event) {
setNode(purchaseorder);
}
#FXML
private void switchPayments(ActionEvent event) {
setNode(payments);
}
#FXML
private void switchDepartmentalTransfers(ActionEvent event) {
setNode(departmentalTransfers);
}
#FXML
private void switchPurchaseInvoice(ActionEvent event) {
setNode(purchaseInvoice);
}
#FXML
private void switchProductMantainance(ActionEvent event) {
setNode(productMantainance);
}
#FXML
private void switchBranchTransfers(ActionEvent event) {
setNode(branchTransfers);
}
//this is a screen that will displayone of the layouts that will show re order levels
<AnchorPane id="AnchorPane" prefHeight="713.0" prefWidth="1219.0" style="-fx-background-color: white;" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label layoutX="24.0" layoutY="17.0" prefHeight="30.0" prefWidth="285.0" style="-fx-font-size: 20; -fx-font-weight: bold; -fx-text-fill: #7387A8;" text="ReOrder Levels" />
<Separator layoutX="25.0" layoutY="54.0" prefHeight="5.0" prefWidth="1191.0" />
<Pane fx:id="tbl_reorderLevels" layoutX="25.0" layoutY="108.0" prefHeight="413.0" prefWidth="1174.0" style="-fx-background-color: #EFEFEF;">
<children>
<JFXComboBox fx:id="cmd_reOrder_productCode" layoutX="48.0" layoutY="33.0" prefHeight="25.0" prefWidth="267.0" promptText="Product Code" />
<JFXTextField fx:id="txt_reOrder_reorderLevel" labelFloat="true" layoutX="48.0" layoutY="91.0" prefHeight="25.0" prefWidth="267.0" promptText="Reorder Level" />
//this is the root layout that has buttons that will navigate between the screens using a fade transition
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.effect.InnerShadow?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<!-- root layout -->
<AnchorPane id="AnchorPane" nodeOrientation="LEFT_TO_RIGHT" prefHeight="623.0" prefWidth="1271.0" style="-fx-background-color: #fff;" xmlns="http://javafx.com/javafx/9.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller = "dashboard.FXMLDocumentController">
<children>
<Pane layoutX="-2.0" prefHeight="81.0" prefWidth="1272.0" style="-fx-background-color: #0b8dee;" styleClass="head-background" stylesheets="#style.css" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label fx:id="labelEstock" layoutX="204.0" layoutY="-3.0" prefHeight="88.0" prefWidth="536.0" style="-fx-shape: round;" stylesheets="#custom.css" text="Oasys Estock" textFill="WHITE">
<font>
<Font name="Brush Script MT Italic" size="36.0" />
</font>
</Label>
<!-- <ImageView fx:id="imageEstock" fitHeight="110.0" fitWidth="92.0" layoutX="102.0" layoutY="8.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image
url="#../../../../AndroidStudioProjects/OasysEstock/app/src/main/res/drawable/fortified_icon.png" />
</image>
</ImageView> -->
</children>
</Pane>
<VBox layoutY="85.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="518.0" prefWidth="122.0" style="-fx-background-color: #0b8dee; -fx-background-radius: 15;">
<children>
<JFXButton id="btnReorderLevels" fx:id="btnReorderLevels" buttonType="RAISED" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" onAction="#switchReorderLevels" prefHeight="47.0" prefWidth="107.0" style="-fx-background-radius: 100;" text="ReOrder Levels" textFill="#f5f0f0">
<VBox.margin>
<Insets />
</VBox.margin>
<font>
<Font name="Calibri" size="12.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnInvoiceRegistration" onAction="#switchInvoiceRegistration" prefHeight="25.0" prefWidth="121.0" text="Invoice Registration" textFill="#f8f4f4" />
<JFXButton fx:id="btnPurchaseOrder" buttonType="RAISED" onAction="#switchPurchaseOrder" prefHeight="34.0" prefWidth="107.0" text="Purchase Order" textFill="#f5f0f0">
<font>
<Font name="Cambria" size="12.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnOnlineSales" onAction="#switchOnlineSales" prefHeight="39.0" prefWidth="107.0" text="Online Sales" textFill="#fff9f9">
<font>
<Font name="Calibri" size="12.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnGeneralLedger" onAction="#switchGeneralLedger" prefHeight="40.0" prefWidth="108.0" text="General Ledger" textFill="#f2eeee" />
<JFXButton fx:id="btnCashBook" onAction="#switchCashBook" prefHeight="35.0" prefWidth="104.0" text="Cash Book" textFill="#fffefe" />
<JFXButton fx:id="btnPayments" buttonType="RAISED" onAction="#switchPayments" prefHeight="25.0" prefWidth="114.0" text="Payments" textFill="#fcf6f6" />
<JFXButton fx:id="btnDepartmentalTransfers" buttonType="RAISED" layoutX="10.0" layoutY="205.0" onAction="#switchDepartmentalTransfers" prefHeight="25.0" prefWidth="114.0" text="Dept Transfers" textFill="#fcf6f6" />
<JFXButton fx:id="btnProductMantainance" buttonType="RAISED" layoutX="10.0" layoutY="230.0" onAction="#switchProductMantainance" prefHeight="56.0" prefWidth="121.0" text="Product Mantainance" textFill="#fcf6f6">
<font>
<Font size="11.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnPurchaseInvoice" buttonType="RAISED" layoutX="10.0" layoutY="255.0" onAction="#switchPurchaseInvoice" prefHeight="56.0" prefWidth="121.0" text="Purchase Invoice" textFill="#fcf6f6">
<font>
<Font size="11.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnBranchTransfers" buttonType="RAISED" layoutX="10.0" layoutY="311.0" onAction="#switchBranchTransfers" prefHeight="56.0" prefWidth="121.0" text="Branch Transfers" textFill="#fcf6f6">
<font>
<Font size="11.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnStockMovement" buttonType="RAISED" layoutX="10.0" layoutY="367.0" onAction="#switchStockMovement" prefHeight="56.0" prefWidth="121.0" text="Stock Movement" textFill="#fcf6f6">
<font>
<Font size="11.0" />
</font>
</JFXButton>
<JFXButton fx:id="btnStockTake" buttonType="RAISED" layoutX="10.0" layoutY="448.0" onAction="#switchStockTake" prefHeight="56.0" prefWidth="121.0" text="Stock Take" textFill="#fcf6f6">
<font>
<Font size="11.0" />
</font>
</JFXButton>
</children>
<effect>
<InnerShadow blurType="TWO_PASS_BOX" choke="0.58" color="#212122" height="26.69" radius="10.620000000000001" width="17.79" />
</effect>
</VBox>
<AnchorPane fx:id="holderPane" layoutX="125.0" layoutY="96.0" prefHeight="507.0" prefWidth="1134.0"/>
</children>
</AnchorPane>
My issue is to set the textarea height to the tab-content-size, but the textarea takes only a part of the content.
I tried different values as maxvalue for maxHeight-property and prefHeight, but no success. There's no problem with the width, its fits the tab-content. Thanks for your help!
The main program:
public class Main extends Application {
public static void main(String[] args) {
Application.launch(Main.class, (java.lang.String[])null);
}
#Override
public void start(Stage primaryStage) {
String resourcePath = "resources/fxml/ExampleFZ.fxml";
URL location = Main.class.getResource(resourcePath);
try {
VBox page = (VBox) FXMLLoader.load(location);
Scene scene = new Scene(page);
primaryStage.setScene(scene);
primaryStage.setTitle("Example FZ");
primaryStage.show();
} catch(Exception ex) {Logger.getLogger(Main.class.getName()).log(Level.SEVERE,null, ex);
}
}
}
The FXML-Code:
<VBox fx:id="rootBox" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.ExampleFZcontroller">
<children>
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="70.0" minWidth="70.0" prefWidth="70.0" />
<ColumnConstraints hgrow="SOMETIMES" />
<ColumnConstraints hgrow="SOMETIMES" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button fx:id="myButton" mnemonicParsing="false" onAction="#myButtonClicked" text="Button" GridPane.halignment="CENTER" />
</children>
</GridPane>
<TabPane fx:id="myTabPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab fx:id="myTab" text="MyTab">
<content>
<TextArea fx:id="myTextArea" maxHeight="1.7976931348623157E308" text="myText" />
</content></Tab>
</tabs></TabPane>
</children>
<stylesheets>
<URL value="#../css/ExampleFZ.css" />
</stylesheets>
</VBox>
The Controller-Code:
public class ExampleFZcontroller {
#FXML
VBox rootBox;
#FXML
private Button myButton;
#FXML
private TabPane myTabPane;
#FXML
private Tab myTab;
#FXML
private TextArea myTextArea;
#FXML
void myButtonClicked(ActionEvent event) {
myTextArea.appendText("\nonce again");
}
}
The css-file:
.tab-header-background {
-fx-background-color: grey ;
.text-area {
-fx-border-width: 5px;
-fx-border-color: red ;
}[enter image description here][1]
this is the result (see the image):
The text area is filling the tab's content; the problem is that the tab pane is not growing when the window increases size. You can fix this with the VBox layout constraint vgrow:
<TabPane fx:id="myTabPane" VBox.vgrow="ALWAYS" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab fx:id="myTab" text="MyTab">
<content>
<TextArea fx:id="myTextArea" maxHeight="1.7976931348623157E308"
text="myText" />
</content>
</Tab>
</tabs>
</TabPane>
my screens scale well at the preview of scenebuilder:
but do not likewise at runtime...
This is the controller class for the FXML:
public class SelectionScreenController implements Initializable,
ControlledScreen {
#FXML
ToggleGroup rbgSelection;
#FXML
RadioButton radHazopEaXls;
#FXML
RadioButton radHaraEaXls;
#FXML
RadioButton radHaraXlsEa;
#FXML
RadioButton radHazopXlsEa;
#FXML
RadioButton radFmeaEaXls;
#FXML
RadioButton radFmeaXlsEa;
ScreensController myController;
#Override
public void initialize(URL url, ResourceBundle rb) {
SafetyDataExchange.primaryStage.sizeToScene();
}
public void setScreenParent(ScreensController screenParent) {
myController = screenParent;
}
#FXML
private void goToNextScreen(ActionEvent event) {
if (rbgSelection.getSelectedToggle().equals(radHaraEaXls)) {
myController.setScreen(SafetyDataExchange.screen2ID);
SafetyDataExchange.primaryStage.sizeToScene();
} else if (rbgSelection.getSelectedToggle().equals(radHaraXlsEa)) {
myController.setScreen(SafetyDataExchange.screen3ID);
SafetyDataExchange.primaryStage.sizeToScene();
} else if (rbgSelection.getSelectedToggle().equals(radHazopEaXls)) {
myController.setScreen(SafetyDataExchange.screen4ID);
SafetyDataExchange.primaryStage.sizeToScene();
}
}
}
This is the FXML:
<BorderPane xmlns="http://javafx.com/javafx/8.0.111"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="at.v2c2.safetydataexchange.gui.SelectionScreenController">
<center>
<VBox spacing="10.0">
<children>
<GridPane VBox.vgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0"
prefWidth="100.0" />
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0"
prefWidth="100.0" />
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0"
prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints vgrow="ALWAYS" />
<RowConstraints vgrow="ALWAYS" />
<RowConstraints vgrow="ALWAYS" />
</rowConstraints>
<children>
<Label text="HAZOP" />
<Label text="FMEA" GridPane.rowIndex="2" />
<RadioButton id="radHaraEaXls" fx:id="radHaraEaXls"
mnemonicParsing="false" selected="true" text="EA->XLS"
GridPane.columnIndex="1" GridPane.rowIndex="1">
<toggleGroup>
<ToggleGroup fx:id="rbgSelection" />
</toggleGroup>
</RadioButton>
<RadioButton id="radFmeaEaXls" fx:id="radFmeaEaXls"
mnemonicParsing="false" text="EA->XLS" toggleGroup="$rbgSelection"
GridPane.columnIndex="1" GridPane.rowIndex="2" />
<RadioButton id="radHazopXlsEa" fx:id="radHazopXlsEa"
mnemonicParsing="false" text="XLS->EA" toggleGroup="$rbgSelection"
GridPane.columnIndex="2" />
<RadioButton id="radFmeaXlsEa" fx:id="radFmeaXlsEa"
mnemonicParsing="false" text="XLS->EA" toggleGroup="$rbgSelection"
GridPane.columnIndex="2" GridPane.rowIndex="2" />
<Label text="HARA" GridPane.rowIndex="1" />
<RadioButton id="radHazopEaXls" fx:id="radHazopEaXls"
mnemonicParsing="false" text="EA->XLS" toggleGroup="$rbgSelection"
GridPane.columnIndex="1" />
<RadioButton id="radHaraXlsEa" fx:id="radHaraXlsEa"
mnemonicParsing="false" text="XLS->EA (csv)" toggleGroup="$rbgSelection"
GridPane.columnIndex="2" GridPane.rowIndex="1" />
</children>
</GridPane>
<Button mnemonicParsing="false" onAction="#goToNextScreen" text="Next"
/>
</children>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
</VBox>
</center>
<top>
<MenuBar BorderPane.alignment="CENTER">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Exit" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Log">
<items>
<MenuItem mnemonicParsing="false" text="Toggle Hide/Show" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
</top>
</BorderPane>
Also refreshing the project in Eclipse did not help.
Does anyone know how to fix this?
SceneBuilder is not injecting fields from controller class to FXML despite being annotated by #FXML. Instead when I enter the ID in fx:id on Scene Builder the error message ""no injectable field found in fxml controller class for the id" is instead shown.
I have managed to get it working in the past, where the ID shows a drop down menu and you simply select the appropriate field; however I'm unsure why it has stopped working.
FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" stylesheets="#../../common/gui/common_style.css" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="vehicles.logic.addVehicle">
<children>
<Text fill="WHITE" layoutX="304.0" layoutY="263.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Registration Number">
<font>
<Font size="19.0" />
</font></Text>
<Text fill="WHITE" layoutX="305.0" layoutY="162.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Model">
<font>
<Font size="19.0" />
</font></Text>
<Text fill="WHITE" layoutX="307.0" layoutY="215.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Make">
<font>
<Font size="19.0" />
</font></Text>
<Text fill="WHITE" layoutX="306.0" layoutY="314.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Engine Size">
<font>
<Font size="19.0" />
</font></Text>
<Text fill="WHITE" layoutX="307.0" layoutY="363.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Fuel Type">
<font>
<Font size="19.0" />
</font></Text>
<Text fill="WHITE" layoutX="308.0" layoutY="415.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Colour">
<font>
<Font size="19.0" />
</font></Text>
<Text fill="WHITE" layoutX="306.0" layoutY="472.0" strokeType="OUTSIDE" strokeWidth="0.0" text="MOT Renewal Date">
<font>
<Font size="19.0" />
</font></Text>
<Text fill="WHITE" layoutX="307.0" layoutY="536.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Last Service Date">
<font>
<Font size="19.0" />
</font></Text>
<Text fill="WHITE" layoutX="309.0" layoutY="597.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Current Mileage">
<font>
<Font size="19.0" />
</font></Text>
<TextField fx:id="model" layoutX="538.0" layoutY="142.0" prefHeight="25.0" prefWidth="170.0" />
<TextField fx:id="make" layoutX="539.0" layoutY="195.0" prefHeight="25.0" prefWidth="170.0" />
<TextField fx:id="regnum" layoutX="540.0" layoutY="244.0" prefHeight="25.0" prefWidth="170.0" />
<TextField fx:id="engine" layoutX="539.0" layoutY="295.0" prefHeight="25.0" prefWidth="170.0" />
<TextField fx:id="fueltype" layoutX="540.0" layoutY="344.0" prefHeight="25.0" prefWidth="170.0" />
<TextField fx:id="colour" layoutX="540.0" layoutY="396.0" prefHeight="25.0" prefWidth="170.0" />
<TextField fx:id="mileage" layoutX="540.0" layoutY="577.0" prefHeight="25.0" prefWidth="170.0" />
<DatePicker fx:id="motrenewal" layoutX="539.0" layoutY="453.0" />
<DatePicker fx:id="servicedate" layoutX="541.0" layoutY="515.0" />
<Button fx:id="add" layoutX="927.0" layoutY="604.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="71.0" text="Add" />
<Button fx:id="back" layoutX="820.0" layoutY="604.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="71.0" text="Back" />
<Text fill="WHITE" layoutX="527.0" layoutY="90.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Add Vehicle">
<font>
<Font size="43.0" />
</font>
</Text>
</children>
</AnchorPane>
Controller:
package vehicles.logic;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TextField;
/**
* FXML Controller class
*
* #author ugonw
*/
public class addVehicle implements Initializable {
#FXML
private TextField model;
#FXML
private TextField make;
#FXML
private TextField regnum;
#FXML
private TextField engine;
#FXML
private TextField fueltype;
#FXML
private TextField colour;
#FXML
private TextField mileage;
#FXML
private DatePicker motrenewal;
#FXML
private DatePicker servicedate;
#FXML
private Button add;
#FXML
private Button back;
/**
* Initializes the controller class.
*/
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
a workaround is to open the xml file in your IDE and manually adding the id name to that file. So if Scenebuilder hasen't done this for you and the object concerns a textfield for example, then the tag will look like this.
<TextField />
You should add the fx:id="your_id_name" to it like this:
<TextField fx:id="userName" />
It should work like a charm after saving the xml file. Hope this helps.