Basically when i update my .fxml file, i can't see the new stuff...it's like showing the old version of the .fxml...with the old stuff... and yes i save the file...
This is my Main.java
package Library.Assistant.Ui.Main;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class MainLoader extends Application {
public static void main(String arg[]) {
launch(arg);
}
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Main.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
This is my Main.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXTextField?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="548.0" prefWidth="617.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Library.Assistant.Ui.Main.MainController">
<children>
<MenuBar maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Delete" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
<GridPane fx:id="grid" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" VBox.vgrow="ALWAYS">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<TabPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" tabClosingPolicy="UNAVAILABLE" GridPane.rowSpan="2147483647">
<tabs>
<Tab text="Book Issue">
<content>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0">
<children>
<HBox alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" VBox.vgrow="ALWAYS">
<children>
<TextField fx:id="enterBookID" promptText="Enter Book ID" />
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" HBox.hgrow="ALWAYS">
<children>
<Label text="Book Name" />
<Label text="Author" />
</children>
</VBox>
</children>
</HBox>
<HBox alignment="CENTER" layoutX="10.0" layoutY="10.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" VBox.vgrow="ALWAYS">
<children>
<TextField promptText="Enter Member ID" />
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" HBox.hgrow="ALWAYS">
<children>
<Label text="Member Name" />
<Label text="Contact" />
</children>
</VBox>
</children>
</HBox>
<HBox alignment="CENTER" layoutX="10.0" layoutY="404.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" VBox.vgrow="ALWAYS">
<children>
<JFXButton maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Issue" HBox.hgrow="ALWAYS" />
</children>
</HBox>
</children>
</VBox>
</content>
</Tab>
<Tab text="Renew / Submission">
<content>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
<children>
<BorderPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" VBox.vgrow="ALWAYS">
<top>
<JFXTextField alignment="CENTER" promptText="Enter Book ID" BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets bottom="20.0" left="10.0" right="10.0" top="10.0" />
</BorderPane.margin>
</JFXTextField>
</top>
<center>
<ListView maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" BorderPane.alignment="CENTER" />
</center>
<bottom>
<HBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" BorderPane.alignment="CENTER">
<children>
<JFXButton maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Renew" HBox.hgrow="ALWAYS" />
<JFXButton maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Submission" HBox.hgrow="ALWAYS" />
</children>
<BorderPane.margin>
<Insets />
</BorderPane.margin>
</HBox>
</bottom>
</BorderPane>
</children>
</VBox>
</content>
</Tab>
</tabs>
</TabPane>
<Button contentDisplay="TOP" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Add Member" GridPane.columnIndex="1">
<graphic>
<ImageView fitHeight="50.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#add_mem.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button contentDisplay="TOP" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Add Book" GridPane.columnIndex="1" GridPane.rowIndex="1">
<graphic>
<ImageView fitHeight="50.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#add_book.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button contentDisplay="TOP" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="View Members" GridPane.columnIndex="1" GridPane.rowIndex="2">
<graphic>
<ImageView fitHeight="50.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#list_mem.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button contentDisplay="TOP" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="View Books" GridPane.columnIndex="1" GridPane.rowIndex="3">
<graphic>
<ImageView fitHeight="50.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#list_book.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button contentDisplay="TOP" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Settings" GridPane.columnIndex="1" GridPane.rowIndex="4">
<graphic>
<ImageView fitHeight="50.0" fitWidth="50.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#settings.png" />
</image>
</ImageView>
</graphic>
</Button>
</children>
</GridPane>
</children>
</VBox>
I just can't understand why it's showing the old version of the file...yesterday everything was working fine.I was adding new stuff and it was showing them properly, but today it keeps showing the version from yesterday...no matter how many stuff i change..
Related
In my application, I am switching fxml files for changing the views because I don't properly know the concepts of Scene and Parent roots. all of my fxml files have an AnchorPane(600,400). This is how my start method looks like.
#Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("loginpage.fxml"));
primaryStage.setTitle("Eye Ratina Scanner");
primaryStage.setScene(new Scene(root, 600, 400));
primaryStage.show();
}
this is how I am changing views.
AnchorPane pane = FXMLLoader.load(getClass().getResource("../loginpage.fxml"));
dashpane.getChildren().setAll(pane) //dashpane is AnchorPane
I made the whole app in size of 600:400. Now I want that when I click on the window maximize button, all of the components resize larger and preserve the ratio. two images are attached below to show what's happening.when i click on maximize
normal 600:400 view
now I don't want to bind each button, imageview, anchorpane, text fields, labels, and so on. It will take too long since I have around 42 fxml files. Can we achieve our results by a single snippet? I didn't find any other post having exactly the same issue.
thanks for answering in advance. I totally appreciate your help.
Here is a sample layout. It uses a VBox as the root. It uses an AnchorPane. Inside the AnchorPane is a GridPane. You will still need to do work to make the ImageView and Label text grow as the Stage gets bigger.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Circle?>
<?import javafx.scene.text.Font?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: lightblue;" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<children>
<HBox maxHeight="400.0" prefHeight="75.0" VBox.vgrow="SOMETIMES">
<children>
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Dashboard" HBox.hgrow="ALWAYS">
<font>
<Font name="System Bold" size="19.0" />
</font>
</Label>
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Analytics" HBox.hgrow="ALWAYS">
<font>
<Font name="System Bold" size="19.0" />
</font>
</Label>
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Settings" HBox.hgrow="ALWAYS">
<font>
<Font name="System Bold" size="19.0" />
</font>
</Label>
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Notifications" HBox.hgrow="ALWAYS">
<font>
<Font name="System Bold" size="19.0" />
</font>
</Label>
<Label alignment="CENTER" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" text="Logout" HBox.hgrow="ALWAYS">
<font>
<Font name="System Bold" size="19.0" />
</font>
</Label>
</children>
</HBox>
<AnchorPane prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: grey;" VBox.vgrow="ALWAYS">
<children>
<GridPane hgap="20.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" vgap="20.0" AnchorPane.bottomAnchor="20.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="20.0">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
</rowConstraints>
<children>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: white;">
<children>
<Circle fill="DODGERBLUE" radius="25.0" stroke="BLACK" strokeType="INSIDE" VBox.vgrow="ALWAYS" />
<Label text="Label" />
<Label text="Label" />
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: white;" GridPane.columnIndex="1">
<children>
<Circle fill="DODGERBLUE" radius="25.0" stroke="BLACK" strokeType="INSIDE" />
<Label text="Label" />
<Label text="Label" />
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: white;" GridPane.columnIndex="3" GridPane.rowIndex="1">
<children>
<Circle fill="DODGERBLUE" radius="40.0" stroke="BLACK" strokeType="INSIDE" />
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: white;" GridPane.columnIndex="2" GridPane.rowIndex="1">
<children>
<Circle fill="DODGERBLUE" radius="25.0" stroke="BLACK" strokeType="INSIDE" />
<Label text="Label" />
<Label text="Label" />
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: white;" GridPane.columnIndex="1" GridPane.rowIndex="1">
<children>
<Circle fill="DODGERBLUE" radius="25.0" stroke="BLACK" strokeType="INSIDE" />
<Label text="Label" />
<Label text="Label" />
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: white;" GridPane.rowIndex="1">
<children>
<Circle fill="DODGERBLUE" radius="25.0" stroke="BLACK" strokeType="INSIDE" />
<Label text="Label" />
<Label text="Label" />
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: white;" GridPane.columnIndex="3">
<children>
<Circle fill="DODGERBLUE" radius="25.0" stroke="BLACK" strokeType="INSIDE" />
<Label text="Label" />
<Label text="Label" />
</children>
</VBox>
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" style="-fx-background-color: white;" GridPane.columnIndex="2">
<children>
<Circle fill="DODGERBLUE" radius="25.0" stroke="BLACK" strokeType="INSIDE" />
<Label text="Label" />
<Label text="Label" />
</children>
</VBox>
</children>
</GridPane>
</children>
</AnchorPane>
</children>
</VBox>
In scene builder preview button is on exact spot i.e bottom right corner without any gap but when i run my application there is gap.
Button is on a pane and pane is placed on top of anchor pane.
How can i fix this issue?
same thing happening with other components when i placed them on far right or far bottom.
Please examin the sample. Pay attention to min_width, min_height, pref_width, pref_height, max_width, max_height, vgrow, hgrow attributues in SceneBuiler.
The main concept is that type of pane you use sholud give you desired layout. It should not be hardcoded.
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<HBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<children>
<VBox style="-fx-background-color: yellow;">
<children>
<StackPane VBox.vgrow="ALWAYS">
<children>
<Button mnemonicParsing="false" text="Menu Button" />
</children>
</StackPane>
<StackPane VBox.vgrow="ALWAYS">
<children>
<Button mnemonicParsing="false" text="Menu Button" />
</children>
</StackPane>
<StackPane layoutX="10.0" layoutY="210.0" VBox.vgrow="ALWAYS">
<children>
<Button mnemonicParsing="false" text="Menu Button" />
</children>
</StackPane>
<StackPane layoutX="10.0" layoutY="276.0" VBox.vgrow="ALWAYS">
<children>
<Button mnemonicParsing="false" text="Menu Button" />
</children>
<VBox.margin>
<Insets />
</VBox.margin>
</StackPane>
<StackPane layoutX="10.0" layoutY="310.0" VBox.vgrow="ALWAYS">
<children>
<Button mnemonicParsing="false" text="Menu Button" />
</children>
</StackPane>
</children>
</VBox>
<VBox style="-fx-background-color: red;" HBox.hgrow="ALWAYS">
<children>
<StackPane prefHeight="150.0" prefWidth="200.0" style="-fx-background-color: green;" VBox.vgrow="ALWAYS">
<children>
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" style="-fx-background-color: purple;">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Label" />
<TextField GridPane.columnIndex="1" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label text="Label" GridPane.rowIndex="1" />
<Label text="Label" GridPane.rowIndex="2" />
</children>
</GridPane>
</children>
</StackPane>
<HBox alignment="TOP_RIGHT">
<children>
<Button mnemonicParsing="false" text="Button" />
</children>
</HBox>
</children>
</VBox>
</children>
</HBox>
Have you put constraints in the layout section of the button? It could be related to that. Check layout x and layout of the button and the pref size x and y of AnchorPane, if that is same, the button must be on the left-bottom corner of the pane.
I want to create three pop-up windows in JavaFX. These windows are almost the same, but they differ in styles. For example, the user deletion window has a black title field, green to activate the user, and red to block. I want to create only one such window in FXML, and then pass the styles as a parameter. How can I do this and is this even possible?
you can either create a custom dialog window or use javafx native dialog window
---------------here i i have created a custom dialog window and i change the colors and icons dynamically as i need
-------FXML-------------------
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<GridPane xmlns:fx="http://javafx.com/fxml/1" style="-fx-border-color: red;" xmlns="http://javafx.com/javafx/8.0.141">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="194.0" minHeight="10.0" prefHeight="117.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="113.0" minHeight="10.0" prefHeight="113.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<AnchorPane prefHeight="113.0" prefWidth="400.0" style="-fx-background-color: e34c5e;">
<children>
<ImageView fitHeight="82.0" fitWidth="104.0" layoutX="153.0" layoutY="18.0" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="17.0" AnchorPane.leftAnchor="153.0" AnchorPane.rightAnchor="165.0" AnchorPane.topAnchor="18.0">
<image>
<Image url="#../Images/eror_icon.png" />
</image>
</ImageView>
</children></AnchorPane>
<AnchorPane layoutX="10.0" layoutY="10.0" prefHeight="129.0" prefWidth="400.0" style="-fx-background-color: white;" GridPane.rowIndex="1">
<children>
<GridPane layoutX="84.0" layoutY="-5.0" prefHeight="99.0" prefWidth="400.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="43.0" minHeight="10.0" prefHeight="39.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="27.0" minHeight="10.0" prefHeight="22.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="36.0" minHeight="10.0" prefHeight="36.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="50.0" prefWidth="401.0" text="Item Not Selected !">
<font>
<Font name="System Bold" size="19.0" />
</font>
</Label>
<Label alignment="CENTER" layoutX="10.0" layoutY="43.0" prefHeight="50.0" prefWidth="401.0" text="Item to Purchase Is Not Selected..Select an Item" GridPane.rowIndex="1" />
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0" GridPane.rowIndex="2">
<children>
<JFXButton fx:id="btnOk" buttonType="RAISED" onMouseClicked="#btnOkClicked" prefHeight="32.0" prefWidth="121.0" style="-fx-background-color: e34c5e; -fx-background-radius: 80;" text="Ok" textFill="WHITE">
<HBox.margin>
<Insets bottom="2.0" top="2.0" />
</HBox.margin>
<font>
<Font name="System Bold" size="15.0" />
</font>
</JFXButton>
</children>
</HBox>
</children>
</GridPane>
</children>
</AnchorPane>
</children>
</GridPane>
--------------------Controller--------
package Controllers;
import javafx.scene.control.Dialog;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
public class CustomAlertDialogBox {
private Dialog currentDialog;
public CustomAlertDialogBox(Dialog dialog) {
this.currentDialog = dialog;
}
public void btnOkClicked(MouseEvent mouseEvent) {
Stage stage = (Stage) currentDialog.getDialogPane().getScene().getWindow();
stage.close();
}
}
check this for native dialog box
http://code.makery.ch/blog/javafx-dialogs-official/
public class DoctorsController implements Initializable {
#FXML
private JFXComboBox<String> comboSpecialization;
#FXML
private JFXComboBox<String> comboDepartment;
#FXML
private ToggleGroup q;
/**
* Initializes the controller class.
* #param url
* #param rb
*/
#Override
public void initialize(URL url, ResourceBundle rb) {
// Populate Comboboxe with static options,
comboSpecialization.getItems().addAll("Pychologist","Psychiatric","Gynaecologist"
+"Pathologist","Cardiologist","Orginologist","unspecified");
comboSpecialization.getSelectionModel().selectLast();
comboDepartment.getItems().addAll("Pychology","Maternity","OutPatient"
+ "Mourtuary","Others");
comboDepartment.getSelectionModel().selectLast();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXComboBox?>
<?import com.jfoenix.controls.JFXProgressBar?>
<?import com.jfoenix.controls.JFXRadioButton?>
<?import com.jfoenix.controls.JFXTabPane?>
<?import com.jfoenix.controls.JFXTextArea?>
<?import com.jfoenix.controls.JFXTextField?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<AnchorPane id="AnchorPane" prefHeight="684.0" prefWidth="1105.0" stylesheets="#../styles/styles.css" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="doctors.DoctorsController">
<children>
<JFXTabPane layoutX="138.0" layoutY="100.0" prefHeight="684.0" prefWidth="1105.0" tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<tabs>
<Tab text="MANAGE DOCOTRS">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<HBox layoutX="23.0" layoutY="33.0" prefHeight="135.0" prefWidth="1068.0" spacing="30.0">
<children>
<AnchorPane prefHeight="110.0" prefWidth="393.0" style="-fx-background-color: #00ADD8;" styleClass="card-unpadded">
<children>
<Pane layoutX="-1.0" prefHeight="141.0" prefWidth="23.0" style="-fx-background-color: #007390;" />
<ImageView fitHeight="97.0" fitWidth="124.0" layoutX="33.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#../imgs/doctor.png" />
</image>
</ImageView>
<Label layoutX="182.0" layoutY="14.0" prefHeight="67.0" prefWidth="89.0" styleClass="custom-white-title-label" text="16" />
<Label layoutX="182.0" layoutY="76.0" prefHeight="31.0" prefWidth="210.0" styleClass="custom-white-label" text="Registered doctors" />
<Label layoutX="182.0" layoutY="107.0" prefHeight="33.0" prefWidth="210.0" styleClass="custom-white-label" text="We need you." />
</children>
</AnchorPane>
<AnchorPane prefHeight="166.0" prefWidth="393.0" style="-fx-background-color: #DD4B39;" styleClass="card-unpadded">
<children>
<Pane layoutX="-1.0" prefHeight="166.0" prefWidth="23.0" style="-fx-background-color: #C74433;" />
<ImageView fitHeight="125.0" fitWidth="124.0" layoutX="33.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#../imgs/Appointment.png" />
</image>
</ImageView>
<Label layoutX="209.0" layoutY="14.0" prefHeight="67.0" prefWidth="89.0" styleClass="custom-white-title-label" text="57 of 100 " />
<Label layoutX="182.0" layoutY="76.0" prefHeight="31.0" prefWidth="210.0" styleClass="custom-white-label" text="Unattended appointments" />
<JFXProgressBar layoutX="179.0" layoutY="120.0" progress="0.52" />
</children>
</AnchorPane>
<AnchorPane prefHeight="157.0" prefWidth="205.0" style="-fx-background-color: #F39C12;" styleClass="card">
<children>
<VBox layoutX="14.0" layoutY="14.0" prefHeight="85.0" prefWidth="159.0">
<children>
<Label prefHeight="31.0" prefWidth="153.0" styleClass="custom-white-title-label" text="TODAY" />
<Label prefHeight="20.0" prefWidth="152.0" styleClass="custom-white-title-label" text="Monday" />
<Label prefHeight="20.0" prefWidth="151.0" styleClass="custom-white-title-label" text="12/07/2017" />
</children>
</VBox>
<ImageView fitHeight="31.0" fitWidth="50.0" layoutX="143.0" layoutY="102.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#../imgs/Copyright.png" />
</image>
</ImageView>
</children>
</AnchorPane>
</children>
</HBox>
<AnchorPane layoutX="23.0" layoutY="224.0" prefHeight="413.0" prefWidth="1057.0" styleClass="card-unpadded">
<children>
<VBox layoutX="20.0" layoutY="14.0" prefHeight="380.0" prefWidth="415.0" spacing="10.0">
<children>
<JFXTextField focusColor="#00add8" labelFloat="true" promptText="First Name" unFocusColor="#868282" />
<JFXTextField focusColor="#00add8" labelFloat="true" layoutX="10.0" layoutY="10.0" promptText="Last Name" unFocusColor="#868282" />
<JFXTextField focusColor="#00add8" labelFloat="true" layoutX="10.0" layoutY="46.0" promptText="Email address" unFocusColor="#868282" />
<JFXTextField focusColor="#00add8" labelFloat="true" layoutX="10.0" layoutY="82.0" promptText="Phone Number" unFocusColor="#868282" />
<JFXTextField focusColor="#00add8" labelFloat="true" layoutX="10.0" layoutY="118.0" promptText="Identity Number" unFocusColor="#868282" />
<JFXTextArea maxWidth="404.0" minWidth="404.0" prefHeight="98.0" prefWidth="404.0" promptText="Additional Information" />
</children>
<padding>
<Insets left="20.0" top="10.0" />
</padding>
</VBox>
<VBox layoutX="525.0" layoutY="17.0" prefHeight="376.0" prefWidth="511.0" spacing="10.0">
<children>
<VBox prefHeight="82.0" prefWidth="541.0">
<children>
<Label style="-fx-text-fill: #868282;" text="Level of Specialization" />
<JFXComboBox fx:id="comboSpecialization" prefHeight="40.0" prefWidth="494.0">
<VBox.margin>
<Insets left="100.0" />
</VBox.margin>
</JFXComboBox>
</children>
</VBox>
<VBox layoutX="10.0" layoutY="10.0" prefHeight="82.0" prefWidth="541.0">
<children>
<Label prefHeight="20.0" prefWidth="112.0" style="-fx-text-fill: #868282;" text="Department" />
<JFXComboBox fx:id="comboDepartment" prefHeight="40.0" prefWidth="499.0">
<VBox.margin>
<Insets left="100.0" />
</VBox.margin>
</JFXComboBox>
</children>
</VBox>
<VBox layoutX="10.0" layoutY="92.0" prefHeight="82.0" prefWidth="541.0">
<children>
<Label prefHeight="20.0" prefWidth="222.0" style="-fx-text-fill: #868282;" text="Taking Appointments" />
<HBox alignment="CENTER_LEFT" prefHeight="100.0" prefWidth="200.0" spacing="30.0">
<children>
<JFXRadioButton selected="true" text="YES">
<toggleGroup>
<ToggleGroup fx:id="q" />
</toggleGroup></JFXRadioButton>
<JFXRadioButton layoutX="10.0" layoutY="10.0" text="NO" toggleGroup="$q" />
</children>
<padding>
<Insets left="100.0" right="20.0" />
</padding>
</HBox>
</children>
</VBox>
<Separator prefWidth="200.0" />
<HBox alignment="CENTER_RIGHT" prefHeight="77.0" prefWidth="511.0" spacing="20.0">
<children>
<JFXButton styleClass="cancel-button" text="Cancel" />
<JFXButton prefHeight="27.0" prefWidth="78.0" styleClass="green-btn" text="Edit" />
<JFXButton layoutX="72.0" layoutY="10.0" prefHeight="37.0" prefWidth="100.0" styleClass="blue-btn" text="Save" />
</children>
<padding>
<Insets right="20.0" />
</padding>
</HBox>
</children>
<padding>
<Insets left="20.0" top="20.0" />
</padding>
</VBox>
</children>
</AnchorPane>
</children>
</AnchorPane>
</content>
</Tab>
<Tab text="DETAILS">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<SplitPane dividerPositions="0.6173228346456693" layoutX="16.0" layoutY="6.0" orientation="VERTICAL" prefHeight="649.0" prefWidth="1105.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="388.0" prefWidth="1103.0">
<children>
<TextField layoutX="787.0" layoutY="14.0" prefHeight="30.0" prefWidth="302.0" promptText="Search doctor by name" styleClass="search-box" />
<TableView layoutX="11.0" layoutY="53.0" prefHeight="326.0" prefWidth="1080.0">
<columns>
<TableColumn editable="false" prefWidth="389.0" text="C1" />
<TableColumn editable="false" prefWidth="168.0" sortable="false" text="C2" />
<TableColumn editable="false" prefWidth="171.0" sortable="false" text="C2" />
<TableColumn editable="false" prefWidth="250.0" sortable="false" text="C2" />
</columns>
</TableView>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="240.0" prefWidth="1103.0">
<children>
<HBox layoutX="30.0" layoutY="14.0" prefHeight="210.0" prefWidth="1043.0" spacing="30.0">
<children>
<GridPane prefHeight="219.0" prefWidth="493.0" styleClass="card">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="195.0" minWidth="10.0" prefWidth="106.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="321.0" minWidth="10.0" prefWidth="321.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Personal Details" />
<Label prefHeight="20.0" prefWidth="83.0" text="Contacts" GridPane.rowIndex="4" />
<Label prefHeight="20.0" prefWidth="300.0" styleClass="blue-label" text="ID No 30229182" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label prefHeight="20.0" prefWidth="300.0" styleClass="blue-label" text="Doctor" GridPane.columnIndex="1" />
<Label prefHeight="20.0" prefWidth="300.0" styleClass="blue-label" text="Daniel" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label prefHeight="20.0" prefWidth="300.0" styleClass="blue-label" text="Mungatana" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label prefHeight="20.0" prefWidth="300.0" styleClass="green-label" text="0717160344" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Label prefHeight="20.0" prefWidth="300.0" styleClass="green-label" text="danmlayah#gmail.com" GridPane.columnIndex="1" GridPane.rowIndex="5" />
</children>
</GridPane>
<GridPane prefHeight="219.0" prefWidth="520.0" styleClass="card">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="239.0" minWidth="10.0" prefWidth="186.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="302.0" minWidth="10.0" prefWidth="302.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Speciality" />
<Label text="Taking Appointments ?" GridPane.rowIndex="2" />
<Label text="Pending Appointments" GridPane.rowIndex="3" />
<Label prefHeight="20.0" prefWidth="280.0" styleClass="yellow-label" text="Cardiologist" GridPane.columnIndex="1" />
<Label prefHeight="20.0" prefWidth="280.0" styleClass="yellow-label" text="Department of Cardiology" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label prefHeight="20.0" prefWidth="279.0" styleClass="red-label" text="YES" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<HBox alignment="CENTER_LEFT" prefHeight="100.0" prefWidth="200.0" spacing="5.0" GridPane.columnIndex="1" GridPane.rowIndex="3">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="30.0" prefWidth="98.0" style="-fx-font-weight: bold;" styleClass="green-label" text="12" />
<JFXButton buttonType="RAISED" prefHeight="30.0" prefWidth="99.0" style="-fx-background-color: rgb(0, 166, 90); -fx-text-fill: white; -fx-font-size: 14; -fx-font-weight: bold;" text="View" />
</children>
</HBox>
<JFXButton buttonType="RAISED" ripplerFill="#53eb11" styleClass="blue-btn" text="Edit Info" GridPane.columnIndex="1" GridPane.rowIndex="5" />
</children>
</GridPane>
</children>
</HBox>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
</content>
</Tab>
</tabs>
</JFXTabPane>
</children>
</AnchorPane>
I am using scene builder for building the application.
I have added several panes and image views inside a scene right now i have a fixed resolution of 1366*768, which works fine.
But when the resolution is not matched the elements in the scene are not aligned properly , is there any solution to fix this issue.
Application running on 800*600 resolution
Application running on 1024*768 resolution
Appplication running on 1366*768 resolution
I'm having this weird behavior when I run my JavaFx app:
As you can see the elements aren't properly aligned. I've created that view using SceneBuilder and there isn't that gap in the editor.
My view is composed of a GridPane. The right cells (on the pic) of the GridPane each contains an HBox, each containing elements (buttons / text fields). I haven't configured anything specific here and am not using any CSS.
Here's the full FXML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="MyController">
<children>
<GridPane hgap="3.0" vgap="3.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints>
<ColumnConstraints hgrow="NEVER" />
<ColumnConstraints hgrow="NEVER" />
<ColumnConstraints hgrow="ALWAYS" />
</columnConstraints>
<rowConstraints>
<RowConstraints vgrow="SOMETIMES" />
<RowConstraints vgrow="SOMETIMES" />
<RowConstraints vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="label1" />
<Label text="label2" GridPane.rowIndex="1" />
<Button defaultButton="true" mnemonicParsing="false" onAction="#handleGo" text="Go!" GridPane.rowIndex="2">
<graphic>
<TextField fx:id="iterations" alignment="CENTER" prefWidth="43.0" style="-fx-padding: 0.166667em 0.333333em 0.166667em 0.333333em;" text="50000" />
</graphic></Button>
<Button fx:id="selectFileButton" maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleFileSelection" text="Select file" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<HBox spacing="3.0" GridPane.columnIndex="2">
<children>
<TextField fx:id="customValue" editable="false" HBox.hgrow="ALWAYS" />
<Button fx:id="deleteButton" mnemonicParsing="false" onAction="#handleDelete" text="Delete" visible="false" />
</children>
</HBox>
<HBox spacing="3.0" GridPane.columnIndex="2" GridPane.rowIndex="1">
<children>
<Button fx:id="editButton" mnemonicParsing="false" text="Edit" />
<Button mnemonicParsing="false" text="New" />
</children>
</HBox>
<ComboBox fx:id="selection" maxWidth="1.7976931348623157E308" onAction="#handleSelection" GridPane.columnIndex="1" />
</children>
</GridPane>
</children>
</AnchorPane>
Am I missing something ?
The default alignment for controls in GridPane (Maybe for controls in general?) is CENTER_LEFT, while for HBox the default is TOP_LEFT. Adding
alignment="CENTER_LEFT"
to your HBox should align them properly.