FXML displaying windows in other tabs - java

I have problem with displaying windows in my program. In the first window it is necessary to write in username and password and choose one option (Admin/Student). Then click button 'Login'. Additionaly I added also another label with message (if log data are good or not). But if I click this button, nothing happens. I don't know why.
LoginApp.java
public class LoginController implements Initializable {
LoginModel loginModel = new LoginModel();
#FXML
private AnchorPane ap;
#FXML
private Label loginstatus;
#FXML
private Label dbstatus;
#FXML
private TextField username;
#FXML
private PasswordField password;
#FXML
private ComboBox<option> combobox;
#FXML
private Button loginbutton;
public void initialize(URL url, ResourceBundle rb) {
if (this.loginModel.isDatabaseConnected()) {
this.dbstatus.setText("Connected to Database");
} else {
this.dbstatus.setText("Not connected to Database");
}
this.combobox.setItems(FXCollections.observableArrayList(option.values()));
}
#FXML
public void login(ActionEvent event) {
//combobox.setEditable(false);
try {
if (this.loginModel.isLogin(this.username.getText(), this.password.getText(),
((option) this.combobox.getValue()).toString())) {
Stage stage = (Stage) this.loginbutton.getScene().getWindow();
stage.close();
switch (((option) this.combobox.getValue()).toString()) {
case "Student":
studentLogin();
break;
case "Admin":
adminLogin();
System.out.println("Dadasd");
break;
}
} if (this.loginModel.isLogin(this.username.getText(), this.password.getText(),
((option) this.combobox.getValue()).toString())) {
this.loginstatus.setText("Connected");
} else
{
this.loginstatus.setText("Denied");
}
} catch (Exception localException) {
}
try {
this.username.setText("");
this.password.setText("");
}catch (Exception localException){
}
}
public void studentLogin() {
//combobox.setEditable(false);
try {
Stage userStage = new Stage();
FXMLLoader loader = new FXMLLoader();
Parent root = (Parent) loader.load(getClass().getResource("/students/studentFXML.fxml").openStream());
StudentController studentController = (StudentController) loader.getController();
Scene scene = new Scene(root);
userStage.setScene(scene);
userStage.setTitle("Student Board");
userStage.setResizable(false);
userStage.show();
} catch (IOException ex) {
ex.printStackTrace();
}
}
public void adminLogin() {
//combobox.setEditable(false);
try {
Stage adminStage = new Stage();
FXMLLoader adminLoader = new FXMLLoader();
Pane adminroot = (Pane) adminLoader.load(getClass().getResource("/admin/tabs/admin.fxml").openStream());
AdminController adminController = (AdminController) adminLoader.getController();
Scene scene = new Scene(adminroot);
adminStage.setScene(scene);
adminStage.setTitle("Admin Board");
adminStage.setResizable(false);
adminStage.show();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
login.fxml
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="350.0" prefWidth="350.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="loginapp.LoginController">
<children>
<Label layoutX="14.0" layoutY="14.0" prefHeight="17.0" prefWidth="86.0" text="DB status" />
<Label fx:id="dbstatus" layoutX="101.0" layoutY="14.0" prefHeight="17.0" prefWidth="216.0" />
<Label fx:id="loginstatus" layoutX="14.0" layoutY="217.0" prefHeight="17.0" prefWidth="79.0" />
<TextField fx:id="username" layoutX="101.0" layoutY="79.0" prefHeight="25.0" prefWidth="216.0" promptText="user name" />
<Label layoutX="14.0" layoutY="83.0" prefHeight="17.0" prefWidth="79.0" text="UserName" />
<Label layoutX="14.0" layoutY="124.0" prefHeight="17.0" prefWidth="79.0" text="Password" />
<PasswordField fx:id="password" layoutX="101.0" layoutY="120.0" prefHeight="25.0" prefWidth="216.0" promptText="password" />
<ComboBox fx:id="combobox" layoutX="101.0" layoutY="169.0" prefHeight="25.0" prefWidth="216.0" promptText="Admin/Student" />
<Button fx:id="loginbutton" layoutX="100.0" layoutY="213.0" mnemonicParsing="false" onAction="#login" prefHeight="25.0" prefWidth="216.0" text="Login" />
</children>
</AnchorPane>
StudentController.java
public class StudentController implements Initializable {
#FXML
private TextField firstname;
#FXML
private TextField lastname;
#FXML
private TextField email;
#FXML
private DatePicker dob;
#FXML
private TableView<StudentData> studenttable;
#FXML
private TableColumn<StudentData, String> firstnamecolumn;
#FXML
private TableColumn<StudentData, String> lastnamecolumn;
#FXML
private TableColumn<StudentData, String> emailcolumn;
#FXML
private TableColumn<StudentData, String> dobcolumn;
private ObservableList<StudentData> data;
private dbConnection dc;
private String sql = "SELECT * FROM students";
public void initialize(URL url, ResourceBundle rb) {
this.dc = new dbConnection();
}
#FXML
private void loadStudentData(ActionEvent event) throws SQLException {
try {
Connection conn = dbConnection.getConnection();
this.data = FXCollections.observableArrayList();
ResultSet rs = conn.createStatement().executeQuery(sql);
while (rs.next()) {
this.data.add(new StudentData(rs.getString(1), rs.getString(2), rs.getString(3),
rs.getString(4))); }
} catch (SQLException ex) {
System.err.println("Error : " + ex);
}
this.firstnamecolumn.setCellValueFactory(new PropertyValueFactory<StudentData, String>("firstName"));
this.lastnamecolumn.setCellValueFactory(new PropertyValueFactory<StudentData, String>("lastName"));
this.emailcolumn.setCellValueFactory(new PropertyValueFactory<StudentData, String>("email"));
this.dobcolumn.setCellValueFactory(new PropertyValueFactory<StudentData, String>("DOB"));
this.studenttable.setItems(null);
this.studenttable.setItems(this.data);
}
#FXML
private void addStudent (ActionEvent event) {
String sqlAdd = "INSERT INTO students (firstName, lastName, email, DOB) VALUES (?, ?, ?, ?)";
try {
Connection conn = dbConnection.getConnection();
PreparedStatement stmt = conn.prepareStatement(sqlAdd);
stmt.setString(2, this.firstname.getText());
stmt.setString(3, this.lastname.getText());
stmt.setString(4, this.email.getText());
stmt.setString(5, this.dob.getEditor().getText());
stmt.execute();
stmt.close();
}catch (SQLException ex) {
System.err.println("Error :" + ex);
}
}
#FXML
private void clearFields(ActionEvent event) {
this.firstname.setText("");
this.lastname.setText("");
this.email.setText("");
this.dob.setValue(null);
}
}
studentFXML.fxml
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="360.0"
prefWidth="640.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="students.StudentController">
<children>
<TabPane prefHeight="360.0" prefWidth="640.0" tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab text="Student">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="360.0" prefWidth="640.0">
<children>
<HBox layoutX="156.0" prefHeight="330.0" prefWidth="490.0">
<children>
<TableView fx:id="studenttable" prefHeight="330.0" prefWidth="490.0">
<columns>
<TableColumn fx:id="idcolumn" prefWidth="75.0" text="ID"/>
<TableColumn fx:id="firstnamecolumn" prefWidth="106.0"
text="First Name"/>
<TableColumn fx:id="lastnamecolumn" prefWidth="112.0" text="Last Name"/>
<TableColumn fx:id="emailcolumn" prefWidth="108.0" text="Email"/>
<TableColumn fx:id="dobcolumn" minWidth="0.0" prefWidth="82.0"
text="DOB"/>
</columns>
</TableView>
</children>
</HBox>
<VBox prefHeight="337.0" prefWidth="159.0">
<children>
<Label prefHeight="19.0" prefWidth="160.0" text="Add student">
<padding>
<Insets left="10.0"/>
</padding>
<VBox.margin>
<Insets/>
</VBox.margin>
</Label>
<TextField fx:id="id">
<VBox.margin>
<Insets left="10.0" right="10.0" top="10.0"/>
</VBox.margin>
</TextField>
<TextField fx:id="firstname" layoutX="10.0" layoutY="29.0"
promptText="First Name">
<VBox.margin>
<Insets left="10.0" right="10.0"/>
</VBox.margin>
</TextField>
<TextField fx:id="lastname" layoutX="10.0" layoutY="54.0"
promptText="Last Name">
<VBox.margin>
<Insets left="10.0" right="10.0"/>
</VBox.margin>
</TextField>
<TextField fx:id="email" layoutX="10.0" layoutY="54.0" promptText="Email">
<VBox.margin>
<Insets left="10.0" right="10.0"/>
</VBox.margin>
</TextField>
<DatePicker fx:id="dob" prefWidth="200.0">
<VBox.margin>
<Insets left="10.0" right="10.0"/>
</VBox.margin>
</DatePicker>
<Button mnemonicParsing="false" onAction="#addStudent" prefHeight="17.0"
prefWidth="140.0" text="Add Data">
<VBox.margin>
<Insets left="10.0"/>
</VBox.margin>
</Button>
<Button layoutX="20.0" layoutY="164.0" mnemonicParsing="false"
onAction="#clearFields" prefHeight="17.0" prefWidth="140.0"
text="Clear Form">
<VBox.margin>
<Insets left="10.0"/>
</VBox.margin>
</Button>
<Button layoutX="20.0" layoutY="189.0" mnemonicParsing="false"
onAction="#loadStudentData" prefHeight="17.0" prefWidth="140.0"
text="Load Form">
<VBox.margin>
<Insets left="10.0"/>
</VBox.margin>
</Button>
<Button mnemonicParsing="false" prefHeight="25.0" prefWidth="152.0"
text="Delete Data">
<VBox.margin>
<Insets left="10.0" right="10.0"/>
</VBox.margin>
</Button>
</children>
</VBox>
</children>
</AnchorPane>
</content>
</Tab>
</tabs>
</TabPane>
</children>
option.java
public enum option {
Admin, Student;
private option() {}
public String value() {
return name();
}
public static option fromvalue (String v) {
return valueOf(v);
}
}

Related

javaFX tableview auto scroll to last

I'm new to java/javaFX so be patient with me.
The problem I'm having is that I don't get auto scrolling to work.
I've tried these solutions but didn't get them to work:
javafx tableview auto scroll to the last
JavaFX how to add ChangeListener to auto scroll TableView
Main.java
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.image.Image;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage stage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("DogRegister.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setMinHeight(900);
stage.setMinWidth(1200);
stage.setResizable(false);
stage.setTitle("Dog Registry");
Image image = new Image("/image/paw.png");
stage.getIcons().add(image);
stage.show();
stage.setOnCloseRequest(event -> {
event.consume();
exit(stage);
});
} catch(Exception e) {
e.printStackTrace();
}
}
public void exit(Stage stage){
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Exit");
alert.setHeaderText("You're about to exit!");
alert.setContentText("Are you sure you want to exit?: ");
if(alert.showAndWait().get() == ButtonType.OK){
System.out.println("You successfully exited!");
stage.close();
}
}
public static void main(String[] args) {
launch(args);
}
}
Controller.java
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
public class DogRegisterController implements Initializable {
#FXML
private TableView<Dog> dogTable;
#FXML
private TableColumn<Dog, Integer> idCol;
#FXML
private TableColumn<Dog, String> nameCol;
#FXML
private TableColumn<Dog, String> BreedCol;
#FXML
private TableColumn<Dog, Integer> ageCol;
#FXML
private TableColumn<Dog, Integer> weightCol;
#FXML
private TableColumn<Dog, Double> tailCol;
#FXML
private TextField idField;
#FXML
private TextField nameField;
#FXML
private TextField breedField;
#FXML
private TextField ageField;
#FXML
private TextField weightField;
#FXML
private Button removeBtn;
#FXML
private Button submitBtn;
#Override
public void initialize(URL location, ResourceBundle resources) {
idCol.setCellValueFactory(new PropertyValueFactory<Dog, Integer>("id"));
nameCol.setCellValueFactory(new PropertyValueFactory<Dog, String>("name"));
BreedCol.setCellValueFactory(new PropertyValueFactory<Dog, String>("breed"));
ageCol.setCellValueFactory(new PropertyValueFactory<Dog, Integer>("age"));
weightCol.setCellValueFactory(new PropertyValueFactory<Dog, Integer>("weight"));
tailCol.setCellValueFactory(new PropertyValueFactory<Dog, Double>("tailLength"));
setupTable();
}
#FXML
void submit(ActionEvent event){
Dog dog = new Dog(nameField.getText(), breedField.getText(),
Integer.parseInt(ageField.getText()), Integer.parseInt(weightField.getText()));
ObservableList<Dog> dogs = dogTable.getItems();
dogs.add(dog);
dogTable.setItems(dogs);
}
#FXML
void edit(ActionEvent event){
ObservableList<Dog> currentTableData = dogTable.getItems();
int currentDogId = Integer.parseInt(idField.getText());
for(Dog dog : currentTableData){
if(dog.getId() == currentDogId) {
dog.setId(Integer.parseInt(idField.getText()));
dog.setName(nameField.getText());
dog.setBreed(breedField.getText());
dog.setAge(Integer.parseInt(ageField.getText()));
dog.setWeight(Integer.parseInt(weightField.getText()));
dogTable.setItems(currentTableData);
dogTable.refresh();
idField.clear();
nameField.clear();
breedField.clear();
ageField.clear();
weightField.clear();
break;
}
}
}
#FXML
void rowClicked(MouseEvent event){
Dog clickedDog = dogTable.getSelectionModel().getSelectedItem();
idField.setText(String.valueOf(clickedDog.getId()));
nameField.setText(String.valueOf(clickedDog.getName()));
breedField.setText(String.valueOf(clickedDog.getBreed()));
ageField.setText(String.valueOf(clickedDog.getAge()));
weightField.setText(String.valueOf(clickedDog.getWeight()));
}
#FXML
void removeDog(ActionEvent event){
int selectedID = dogTable.getSelectionModel().getSelectedIndex();
dogTable.getItems().remove(selectedID);
idField.clear();
nameField.clear();
breedField.clear();
ageField.clear();
weightField.clear();
dogTable.refresh();
}
public static <S> void addAutoScroll(final TableView<S> dogTable) {
if (dogTable == null) {
throw new NullPointerException();
}
dogTable.getItems().addListener((ListChangeListener<S>) (c -> {
c.next();
final int size = dogTable.getItems().size();
if (size > 0) {
dogTable.scrollTo(size - 1);
}
}));
}
private void setupTable(){
Dog dog0 = new Dog("Luna", "Eurasier", 3, 22);
Dog dog1 = new Dog("Skye", "Dachshund", 4, 5);
Dog dog2 = new Dog("Bella", "Dachs", 2, 3);
Dog dog3 = new Dog("Sky", "Tax", 3, 3);
dogTable.getItems().addAll(dog0, dog1, dog2, dog3);
}
}
Dog.java
import java.util.concurrent.atomic.AtomicInteger;
public class Dog {
private static final AtomicInteger _ID = new AtomicInteger(0);
private String name;
private String breed;
private int age;
private int weight;
private double tailLength;
private int id;
public Dog(String name, String breed, int age, int weight){
this.id = _ID.incrementAndGet();
this.name = name;
this.breed = breed;
this.age = age;
this.weight = weight;
this.tailLength = getTailLength();
}
public double getTailLength(){
if (breed.toLowerCase().equals("tax") || breed.toLowerCase().equals("dachshund")|| breed.toLowerCase().equals("dachs")){
return 3.7;
} else {
return (age * weight) / 10.0;
}
}
public int getId() { return id; }
public void setId(int id){ this.id = id; }
public String getName() { return name; }
public void setName(String name){ this.name = name; }
public String getBreed() { return breed; }
public void setBreed(String breed){this.breed = breed;}
public int getWeight() { return weight; }
public void setWeight(int weight) { this.weight = weight; }
public int getAge() { return age; }
public void setAge(int age) { this.age = age; }
}
GUI.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.String?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane fx:id="mainPane" minHeight="900.0" minWidth="1200.0" prefHeight="900.0" prefWidth="1200.0" styleClass="pane" stylesheets="#StyleSheet.css" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="DogRegisterController">
<children>
<TableView fx:id="dogTable" layoutX="586.0" layoutY="160.0" onMouseClicked="#rowClicked" prefHeight="700.0" prefWidth="600.0" stylesheets="#StyleSheet.css" AnchorPane.rightAnchor="60.0" AnchorPane.topAnchor="100.0">
<columns>
<TableColumn fx:id="idCol" minWidth="50.0" prefWidth="50.0" text="ID" />
<TableColumn fx:id="nameCol" minWidth="140.0" prefWidth="140.0" text="Name" />
<TableColumn fx:id="BreedCol" minWidth="140.0" prefWidth="140.0" text="Breed" />
<TableColumn fx:id="ageCol" minWidth="80.0" text="Age" />
<TableColumn fx:id="weightCol" minWidth="80.0" text="Weight" />
<TableColumn fx:id="tailCol" minWidth="96.0" prefWidth="96.0" text="Tail-length" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
<styleClass>
<String fx:value="column-header" />
<String fx:value="column-header-background" />
<String fx:value="corner" />
<String fx:value="filler" />
<String fx:value="table-cell" />
<String fx:value="table-row-cell" />
<String fx:value="table-view" />
</styleClass>
</TableView>
<ImageView fitHeight="100.0" fitWidth="150.0" layoutX="220.0" layoutY="100.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="#image/paw.png" />
</image>
</ImageView>
<VBox prefHeight="900.0" prefWidth="560.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="ID" textAlignment="CENTER">
<font>
<Font size="14.0" />
</font>
<VBox.margin>
<Insets left="100.0" right="100.0" top="260.0" />
</VBox.margin>
</Text>
<TextField fx:id="idField" editable="false" prefHeight="35.0" styleClass="text-field" stylesheets="#StyleSheet.css">
<VBox.margin>
<Insets bottom="5.0" left="100.0" right="100.0" top="5.0" />
</VBox.margin>
<padding>
<Insets left="10.0" />
</padding>
</TextField>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Name" textAlignment="CENTER">
<font>
<Font size="14.0" />
</font>
<VBox.margin>
<Insets left="100.0" right="100.0" />
</VBox.margin>
</Text>
<TextField fx:id="nameField" layoutX="10.0" layoutY="27.0" prefHeight="35.0" styleClass="text-field" stylesheets="#StyleSheet.css">
<VBox.margin>
<Insets bottom="5.0" left="100.0" right="100.0" top="5.0" />
</VBox.margin>
<padding>
<Insets left="10.0" />
</padding>
</TextField>
<Text layoutX="10.0" layoutY="39.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Breed" textAlignment="CENTER">
<font>
<Font size="14.0" />
</font>
<VBox.margin>
<Insets left="100.0" right="100.0" />
</VBox.margin>
</Text>
<TextField fx:id="breedField" layoutX="10.0" layoutY="127.0" prefHeight="35.0" styleClass="text-field" stylesheets="#StyleSheet.css">
<VBox.margin>
<Insets bottom="5.0" left="100.0" right="100.0" top="5.0" />
</VBox.margin>
<padding>
<Insets left="10.0" />
</padding>
</TextField>
<Text layoutX="10.0" layoutY="57.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Age" textAlignment="CENTER">
<font>
<Font size="14.0" />
</font>
<VBox.margin>
<Insets left="100.0" right="100.0" />
</VBox.margin>
</Text>
<TextField fx:id="ageField" layoutX="10.0" layoutY="144.0" prefHeight="35.0" styleClass="text-field" stylesheets="#StyleSheet.css">
<VBox.margin>
<Insets bottom="5.0" left="100.0" right="100.0" top="5.0" />
</VBox.margin>
<padding>
<Insets left="10.0" />
</padding>
</TextField>
<Text layoutX="10.0" layoutY="71.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Weight" textAlignment="CENTER">
<font>
<Font size="14.0" />
</font>
<VBox.margin>
<Insets left="100.0" right="100.0" />
</VBox.margin>
</Text>
<TextField fx:id="weightField" layoutX="10.0" layoutY="160.0" prefHeight="35.0" styleClass="text-field" stylesheets="#StyleSheet.css">
<VBox.margin>
<Insets bottom="5.0" left="100.0" right="100.0" top="5.0" />
</VBox.margin>
<padding>
<Insets left="10.0" />
</padding>
</TextField>
<HBox prefHeight="100.0" prefWidth="200.0">
<children>
<Button fx:id="submitBtn" alignment="CENTER" mnemonicParsing="false" onAction="#submit" prefHeight="40.0" prefWidth="140.0" stylesheets="#../../Assignment-3/src/style.css" text="Submit">
<font>
<Font size="14.0" />
</font>
<HBox.margin>
<Insets left="25.0" right="25.0" top="10.0" />
</HBox.margin>
</Button>
<Button fx:id="editBtn" alignment="CENTER" layoutX="10.0" layoutY="10.0" mnemonicParsing="false" onAction="#edit" prefHeight="40.0" prefWidth="140.0" stylesheets="#../../Assignment-3/src/style.css" text="Edit">
<font>
<Font size="14.0" />
</font>
<HBox.margin>
<Insets left="25.0" right="25.0" top="10.0" />
</HBox.margin>
</Button>
</children>
<VBox.margin>
<Insets bottom="5.0" left="100.0" right="100.0" top="5.0" />
</VBox.margin>
</HBox>
</children>
</VBox>
<Button fx:id="removeBtn" alignment="CENTER" layoutX="770.0" layoutY="825.0" mnemonicParsing="false" onAction="#removeDog" prefHeight="40.0" prefWidth="140.0" stylesheets="#../../Assignment-3/src/style.css" text="Remove" AnchorPane.bottomAnchor="35.0">
<font>
<Font size="14.0" />
</font>
</Button>
</children>
</AnchorPane>
got it working thanks to #jewelsea
had forgotten to add "addAutoScroll(dogTable)" to setupTable method so the auto scroll was never called.
Controller.java
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
public class DogRegisterController implements Initializable {
public static <S> void addAutoScroll(final TableView<S> dogTable) {
if (dogTable == null) {
throw new NullPointerException();
}
dogTable.getItems().addListener((ListChangeListener<S>) (c -> {
c.next();
final int size = dogTable.getItems().size();
if (size > 0) {
dogTable.scrollTo(size - 1);
}
}));
}
private void setupTable(){
Dog dog0 = new Dog("Luna", "Eurasier", 3, 22);
Dog dog1 = new Dog("Skye", "Dachshund", 4, 5);
Dog dog2 = new Dog("Bella", "Dachs", 2, 3);
Dog dog3 = new Dog("Sky", "Tax", 3, 3);
dogTable.getItems().addAll(dog0, dog1, dog2, dog3);
addAutoScroll(dogTable);
}
}

Couldn't add listener to text field javafx

I am trying to add listener to the textfield in the controler but cudnt do it . i coudnt find any options of textfield in the controler while using the fx:id given to that specific text field.
sample.fxml
<?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.RadioButton?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.effect.Reflection?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<fx:root maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="294.0" prefWidth="883.0" style="-fx-background-color: #000000;" stylesheets="#style.css" type="AnchorPane" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="controler">
<children>
<Label layoutX="28.0" layoutY="55.0" text="Enter Text : " AnchorPane.leftAnchor="28.0">
<font>
<Font size="15.0" />
</font>
</Label>
<TextField fx:id="msg_tb" alignment="CENTER" layoutX="117.0" layoutY="52.0" prefHeight="25.0" prefWidth="342.0" style="-fx-background-radius: 10;" stylesheets="#style.css" AnchorPane.leftAnchor="117.0" AnchorPane.rightAnchor="424.0" />
<TextField fx:id="n_msg_tb" alignment="CENTER" layoutX="117.0" layoutY="93.0" prefHeight="25.0" prefWidth="342.0" style="-fx-background-radius: 10;" stylesheets="#style.css" AnchorPane.leftAnchor="117.0" AnchorPane.rightAnchor="424.0" />
<Button fx:id="reset_b" alignment="CENTER" layoutX="602.0" layoutY="171.0" mnemonicParsing="false" onAction="#reset" style="-fx-text-fill: #FFFFFF; -fx-background-radius: 20;" stylesheets="#style.css" text="RESET" AnchorPane.rightAnchor="161.0">
<font>
<Font name="Calibri Bold" size="31.0" />
</font>
<effect>
<Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
</effect>
</Button>
<VBox layoutX="495.0" layoutY="31.0" prefHeight="169.0" prefWidth="167.0" spacing="3.0" stylesheets="#style.css" AnchorPane.rightAnchor="221.0">
<children>
<RadioButton fx:id="er" mnemonicParsing="false" onAction="#er_action" prefHeight="17.0" prefWidth="92.0" stylesheets="#application.css" text="ENCRIPTION" textFill="#797979">
<toggleGroup>
<ToggleGroup fx:id="group1" />
</toggleGroup>
</RadioButton>
<AnchorPane fx:id="ebox" prefHeight="150.0" prefWidth="167.0">
<children>
<Label contentDisplay="RIGHT" graphicTextGap="20.0" layoutX="7.0" layoutY="2.0" prefHeight="25.0" prefWidth="131.0" stylesheets="#application.css" text="NUMBER LETTER">
<graphic>
<Button minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#e_nl" prefHeight="15.0" prefWidth="15.0" text="*">
<effect>
<Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
</effect>
</Button>
</graphic>
<padding>
<Insets top="15.0" />
</padding>
</Label>
<Label contentDisplay="RIGHT" graphicTextGap="60.0" layoutX="8.0" layoutY="27.0" prefHeight="25.0" prefWidth="131.0" stylesheets="#application.css" text="AT-BASH">
<graphic>
<Button graphicTextGap="0.0" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#e_at" prefHeight="15.0" prefWidth="15.0" text="Button">
<effect>
<Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
</effect>
</Button>
</graphic>
<padding>
<Insets top="15.0" />
</padding>
</Label>
<Label contentDisplay="RIGHT" graphicTextGap="20.0" layoutX="8.0" layoutY="52.0" prefHeight="25.0" prefWidth="105.0" stylesheets="#style.css" text="CEASER">
<graphic>
<TextField fx:id="e_key_tb" onAction="#e_c_key_tb" prefHeight="25.0" prefWidth="40.0" promptText="KEY" style="-fx-background-radius: 10;" stylesheets="#style.css" />
</graphic>
<padding>
<Insets top="15.0" />
</padding>
</Label>
<Button alignment="CENTER" disable="true" layoutX="110.0" layoutY="67.0" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#e_c" prefHeight="25.0" prefWidth="40.0" style="-fx-background-radius: 10;" stylesheets="#application.css" text="CEASER" textAlignment="CENTER">
<font>
<Font name="System Italic" size="8.0" />
</font>
<effect>
<Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
</effect>
</Button>
</children>
</AnchorPane>
</children>
</VBox>
<VBox layoutX="662.0" layoutY="31.0" prefHeight="169.0" prefWidth="167.0" spacing="3.0" stylesheets="#style.css" AnchorPane.rightAnchor="54.0">
<children>
<RadioButton fx:id="dr" mnemonicParsing="false" onAction="#dr_action" prefHeight="17.0" prefWidth="98.0" stylesheets="#application.css" text="DECRIPTION" textFill="#797979" toggleGroup="$group1" />
<AnchorPane fx:id="dbox" prefHeight="150.0" prefWidth="167.0" visible="false">
<children>
<Label contentDisplay="RIGHT" graphicTextGap="20.0" layoutX="7.0" layoutY="2.0" prefHeight="25.0" prefWidth="131.0" stylesheets="#application.css" text="NUMBER LETTER">
<graphic>
<Button minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="15.0" prefWidth="15.0" text="*">
<effect>
<Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
</effect>
</Button>
</graphic>
<padding>
<Insets top="15.0" />
</padding>
</Label>
<Label contentDisplay="RIGHT" graphicTextGap="60.0" layoutX="8.0" layoutY="27.0" prefHeight="25.0" prefWidth="131.0" stylesheets="#application.css" text="AT-BASH">
<graphic>
<Button graphicTextGap="0.0" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" prefHeight="15.0" prefWidth="15.0" text="Button">
<effect>
<Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
</effect>
</Button>
</graphic>
<padding>
<Insets top="15.0" />
</padding>
</Label>
<Label contentDisplay="RIGHT" graphicTextGap="20.0" layoutX="8.0" layoutY="52.0" prefHeight="25.0" prefWidth="105.0" stylesheets="#style.css" text="CEASER">
<graphic>
<TextField fx:id="d_key_tb" onAction="#d_c_key_tb" prefHeight="25.0" prefWidth="40.0" promptText="KEY" style="-fx-background-radius: 10;" stylesheets="#style.css" />
</graphic>
<padding>
<Insets top="15.0" />
</padding>
</Label>
<Button disable="true" layoutX="110.0" layoutY="67.0" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#d_c" prefHeight="25.0" prefWidth="40.0" style="-fx-background-radius: 10;" stylesheets="#application.css" text="CEASER" textAlignment="CENTER">
<font>
<Font name="System Italic" size="8.0" />
</font>
<effect>
<Reflection fraction="0.41" topOffset="0.65" topOpacity="0.73" />
</effect>
</Button>
</children>
</AnchorPane>
</children>
</VBox>
</children>
</fx:root>
controler.java
import java.io.FileNotFoundException;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.AnchorPane;
public class controler implements Initializable {
#FXML
private TextField msg_tb;
#FXML
private TextField n_msg_tb;
#FXML
private Button reset_b;
#FXML
private RadioButton er;
#FXML
private ToggleGroup group1;
#FXML
private RadioButton dr;
#FXML
private AnchorPane ebox;
#FXML
private AnchorPane dbox;
#FXML
public TextField e_key_tb;
#FXML
private TextField d_key_tb;
#FXML
void d_c(ActionEvent event) {
}
#FXML
void d_c_key_tb(ActionEvent event) {
}
#FXML
void dr_action(ActionEvent event) {
dbox.setVisible(true);
dbox.setDisable(false);
ebox.setVisible(false);
ebox.setDisable(true);
}
#FXML
void e_at(ActionEvent event) {
}
#FXML
void e_c(ActionEvent event) {
}
#FXML
void e_c_key_tb(ActionEvent event) {
}
#FXML
void e_nl(ActionEvent event) {
}
#FXML
void er_action(ActionEvent event) {
ebox.setVisible(true);
ebox.setDisable(false);
dbox.setVisible(false);
dbox.setDisable(true);
}
#FXML
void reset(ActionEvent event) {
}
#Override
public void initialize(URL location, ResourceBundle resources) {
ArrayList<morse> mkey = new ArrayList<>();
try {
morse.load(mkey);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public TextField getMsg_tb() {
return msg_tb;
}
public void setMsg_tb(TextField msg_tb) {
this.msg_tb = msg_tb;
}
public TextField getN_msg_tb() {
return n_msg_tb;
}
public void setN_msg_tb(TextField n_msg_tb) {
this.n_msg_tb = n_msg_tb;
}
public Button getReset_b() {
return reset_b;
}
public void setReset_b(Button reset_b) {
this.reset_b = reset_b;
}
public RadioButton getEr() {
return er;
}
public void setEr(RadioButton er) {
this.er = er;
}
public ToggleGroup getGroup1() {
return group1;
}
public void setGroup1(ToggleGroup group1) {
this.group1 = group1;
}
public RadioButton getDr() {
return dr;
}
public void setDr(RadioButton dr) {
this.dr = dr;
}
public AnchorPane getEbox() {
return ebox;
}
public void setEbox(AnchorPane ebox) {
this.ebox = ebox;
}
public AnchorPane getDbox() {
return dbox;
}
public void setDbox(AnchorPane dbox) {
this.dbox = dbox;
}
public TextField getE_key_tb() {
return e_key_tb;
}
public void setE_key_tb(TextField e_key_tb) {
this.e_key_tb = e_key_tb;
}
public TextField getD_key_tb() {
return d_key_tb;
}
public void setD_key_tb(TextField d_key_tb) {
this.d_key_tb = d_key_tb;
}
e_key_tb.textProperty().addListener((obs, oldText, newText) -> {
System.out.println("Text changed from "+ oldText +" to "+newText);
});
}
}
when I am trying to add the listener at the end it is not working. I can't get any options for textfield when I do e_key_tb. and ctrl+space where it is supposed to give a drop down box with a bunch of suggestions ... I used the scene-builder to provide id and copied the controller skeliton from the scene-builder ... later when I'm trying to use the textfield it made me create getters and setters for all the textfields can you explain me y it s happening and I never used listeners before.
Here is a short demonstration of adding a listener to a TextField. This can also serve as an example for mcve for the issue:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.TextField?>
<HBox prefHeight="75.0" prefWidth="150.0" alignment="CENTER"
xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" fx:controller="tests.Controler">
<children>
<TextField fx:id="msg_tb" prefHeight="25.0" prefWidth="100.0" style="-fx-background-radius: 10;" />
</children>
</HBox>
The controller :
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextField;
public class Controler implements Initializable {
#FXML
private TextField msg_tb;
#Override
public void initialize(URL arg0, ResourceBundle arg1) {
msg_tb.textProperty().addListener((obs, oldText, newText) -> {
System.out.println("Text changed from "+ oldText +" to "+newText);
});
}
}
Test it:
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class FxmlMain extends Application {
#Override
public void start(Stage primaryStage) throws Exception {
Pane root = FXMLLoader.load(getClass().getResource("xml/FxmlMain.fxml"));
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
public static void main(String[] args) { launch(args);}
}

Values get swapped in table column when trying to filter Observable list by Applying filterlist and sortedlist

I'm creating a gate pass software which uses Table view to directly add data to MYSQL database, I added a search textField to search entries from Tutorial
and whenever I search using that textField everything works fine but in back ground these errors appears
"C:\Program Files\Java\jdk1.8.0_102\bin\java" -Didea.launcher.port=7537 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.3.4\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_102\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_102\jre\lib\rt.jar;C:\Program Files (x86)\MySQL\Connector.J 5.1\mysql-connector-java-5.1.40-bin.jar;C:\Users\Suraj\IdeaProjects\DemoFinal\out\production\DemoFinal;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.3.4\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain sample.Main
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:246)
at com.sun.glass.ui.View.handleKeyEvent(View.java:546)
at com.sun.glass.ui.View.notifyKey(View.java:966)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
when ever i press a key for search every thing works great , but after every keypress these errors gets generated.
And also after search my column values gets swapped Like I have two columns one for address and other for email, after search they start to show each others data inside them their data gets swapped.
package sample;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.collections.transformation.SortedList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.function.Predicate;
public class DataController implements Initializable {
Config config = new Config();
Connection connection = DatabaseConnection.getConnection();
int ids;
#FXML
private TextArea Address;
#FXML
private Label LabelFilter;
#FXML
private TextField TextFiledFilter;
#FXML
private TextField Lname;
#FXML
private TextField PhoneNo;
#FXML
private Button btnAdd;
#FXML
private TableColumn<EntryData, String> firstname;
#FXML
private TableColumn<EntryData, String> address;
#FXML
private TableColumn<?, ?> Timee;
#FXML
private TableColumn<EntryData, String> emailid;
#FXML
private TableColumn<EntryData, Double> phoneno;
#FXML
private TableColumn<EntryData, String> lastname;
#FXML
private TableColumn<EntryData, Integer> id;
#FXML
private TableColumn<?, ?> Datee;
#FXML
private TextField mailId;
#FXML
private Menu menuFile;
#FXML
private MenuBar MenuBar;
#FXML
private MenuItem MenuItemFilter;
#FXML
private TextField Fname;
#FXML
private TableView TableID;
ObservableList<EntryData> list = FXCollections.observableArrayList();
ObservableList<EntryData> FilterData = FXCollections.observableArrayList();
#FXML
void addBtnAction(ActionEvent event) throws SQLException {
String query = "INSERT INTO DemoFinal(id,name,lastname,phone_no,email_id,Address) Values(?,?,?,?,?,?)";
PreparedStatement statement = connection.prepareStatement(query);
statement.setInt(1, ++ids);
statement.setString(2, Fname.getText());
statement.setString(3, Lname.getText());
statement.setDouble(4, Double.parseDouble(PhoneNo.getText()));
statement.setString(5, mailId.getText());
statement.setString(6, Address.getText());
statement.execute();
Fname.clear();
Lname.clear();
mailId.clear();
Address.clear();
PhoneNo.clear();
TableID.getItems().addAll(list);
statement.close();
}
public DataController() throws Exception {
}
public void factorySettings() {
id.setCellValueFactory(new PropertyValueFactory<EntryData, Integer>("id"));
firstname.setCellValueFactory(new PropertyValueFactory<EntryData, String>("name"));
lastname.setCellValueFactory(new PropertyValueFactory<EntryData, String>("lastname"));
phoneno.setCellValueFactory(new PropertyValueFactory<EntryData, Double>("phone_no"));
emailid.setCellValueFactory(new PropertyValueFactory<EntryData, String>("email"));
address.setCellValueFactory(new PropertyValueFactory<EntryData, String>("address"));
}
#Override
public void initialize(URL location, ResourceBundle resources) {
if (connection != null) {
try {
DatabaseConnection.getConnection();
update();
} catch (Exception e) {
e.printStackTrace();
}
} else {
config.alert(Alert.AlertType.ERROR, "Database Server May be Down Check Logs");
}
FilteredList <EntryData> filteredList= new FilteredList<EntryData>(list ,e-> true);
TextFiledFilter.textProperty().addListener((observable, oldValue, newValue) ->{
filteredList.setPredicate((Predicate<?super EntryData>) EntryData->{
if(newValue==null||newValue.isEmpty()){
return true;
}
String iid= String.valueOf(EntryData.getId());
String tolowercase= newValue.toLowerCase();
if (EntryData.getName().toLowerCase().contains(tolowercase)){
return true;
}
else if(EntryData.getLastname().contains(tolowercase)){
return true;
}
else if (EntryData.getEmail().toLowerCase().contains(tolowercase)){
return true;
}
else if(EntryData.getAddress().toLowerCase().contains(tolowercase)){
return true;
}
else if(String.valueOf(EntryData.getId()).contains(newValue)) {
return true;
}
else if (String.valueOf(EntryData.getPhone_no()).contains(newValue)){
return true;
}
return false;
} );
});
SortedList<EntryData> sortedList= new SortedList<>(filteredList);
sortedList.comparatorProperty().bind(TableID.comparatorProperty());
TableID.setItems(sortedList);
}
public void update() throws SQLException {
factorySettings();
ResultSet resultSet = null;
try {
resultSet = connection.createStatement().executeQuery("SELECT * FROM DemoFinal");
} catch (SQLException e) {
e.printStackTrace();
}
while (resultSet.next()) {
ids = resultSet.getInt("id");
list.add(new EntryData(ids, resultSet.getDouble("phone_no"),
resultSet.getString("name"), resultSet.getString("lastname"), resultSet.getString("email_id"),
resultSet.getString("Address")));
}
TableID.getItems().addAll(list);
resultSet.close();
}
#FXML
void OnMenuFilter(ActionEvent event) {
LabelFilter.setText("Filter");
TextFiledFilter.setScaleX(1);
TextFiledFilter.setScaleY(1);
}
#FXML
void OnactionTextField(ActionEvent event) {
}
#FXML
void keyRelesed(ActionEvent event) {
}
}
FXML file
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="716.0" prefWidth="1224.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.DataController">
<center>
<TableView fx:id="TableID" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<columns>
<TableColumn fx:id="id" prefWidth="51.0" text="ID" />
<TableColumn fx:id="firstname" prefWidth="133.0" text="First Name" />
<TableColumn fx:id="lastname" prefWidth="106.0" text="Last Name" />
<TableColumn fx:id="emailid" prefWidth="121.0" text="Email-Id" />
<TableColumn fx:id="phoneno" prefWidth="75.0" text="Phone No" />
<TableColumn fx:id="address" prefWidth="233.0" text="Address" />
<TableColumn fx:id="Timee" minWidth="0.0" prefWidth="88.0" text="Time of entry" />
<TableColumn fx:id="Datee" minWidth="0.0" prefWidth="132.0" text="Date of Entry" />
</columns>
</TableView>
</center>
<left>
<VBox prefHeight="528.0" prefWidth="255.0" BorderPane.alignment="CENTER">
<children>
<TextField fx:id="Fname" promptText="First Name">
<VBox.margin>
<Insets bottom="40.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</TextField>
<TextField fx:id="Lname" promptText="Last Name">
<VBox.margin>
<Insets bottom="40.0" left="5.0" right="5.0" />
</VBox.margin>
</TextField>
<TextField fx:id="mailId" promptText="Email-Id">
<VBox.margin>
<Insets bottom="40.0" left="5.0" right="5.0" />
</VBox.margin>
</TextField>
<TextField fx:id="PhoneNo" promptText="Phone_No">
<VBox.margin>
<Insets bottom="40.0" left="5.0" right="5.0" />
</VBox.margin>
</TextField>
<TextArea fx:id="Address" prefHeight="200.0" prefWidth="200.0" promptText="Address">
<VBox.margin>
<Insets left="5.0" right="5.0" />
</VBox.margin>
</TextArea>
<Button fx:id="btnAdd" mnemonicParsing="false" onAction="#addBtnAction" text="Add">
<VBox.margin>
<Insets left="180.0" top="20.0" />
</VBox.margin>
</Button>
</children>
</VBox>
</left>
<top>
<MenuBar fx:id="MenuBar" BorderPane.alignment="CENTER">
<menus>
<Menu fx:id="menuFile" mnemonicParsing="false" text="File">
<items>
<MenuItem fx:id="MenuItemFilter" mnemonicParsing="false" onAction="#OnMenuFilter" text="Filter" />
<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>
</top>
<bottom>
<HBox BorderPane.alignment="CENTER">
<children>
<Label fx:id="LabelFilter" />
<TextField fx:id="TextFiledFilter" onAction="#OnactionTextField" onKeyReleased="#keyRelesed" scaleX="0.0" scaleY="0.0" />
</children>
<BorderPane.margin>
<Insets bottom="20.0" left="255.0" />
</BorderPane.margin>
</HBox>
</bottom>
</BorderPane>

javafx tabpane's pane content not working and tab not switching

Hi i have made a javafx app with loading New Tabs inside TabPane.Application running great except the New Tabs Button,TextFields are not working and also the switching of in tabpane is not working.
FXML
<GridPane id="content" alignment="CENTER" prefHeight="310.0" prefWidth="800.0" styleClass="mainParent" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.gvj.sndp.view.controller.HomeController">
<children>
<SplitPane dividerPositions="0.18421052631578946" prefHeight="160.0" prefWidth="200.0" GridPane.rowIndex="2">
<items>
<TreeView fx:id="menuTreeView" prefHeight="273.0" prefWidth="115.0" />
<TabPane fx:id="tabPane" mouseTransparent="true" prefHeight="200.0" prefWidth="200.0" rotateGraphic="true" />
</items>
</SplitPane>
<HBox alignment="CENTER_LEFT" prefHeight="100.0" prefWidth="200.0" GridPane.rowIndex="1">
<children>
<JFXButton buttonType="RAISED" onAction="#addMemberSelect" prefHeight="33.0" prefWidth="37.0" text="AM">
<opaqueInsets>
<Insets />
</opaqueInsets>
<HBox.margin>
<Insets left="5.0" />
</HBox.margin>
</JFXButton>
<JFXButton buttonType="RAISED" onAction="#addSelfHelpSelect" prefHeight="33.0" prefWidth="55.0" text="ASH">
<HBox.margin>
<Insets left="5.0" />
</HBox.margin>
</JFXButton>
<JFXButton onAction="#addOfficeBarrierSelect" prefHeight="35.0" prefWidth="43.0" text="AOB">
<HBox.margin>
<Insets left="5.0" />
</HBox.margin>
</JFXButton>
</children>
</HBox>
<HBox />
</children>
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" minWidth="-1.0" prefWidth="-1.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="35.0" minHeight="22.0" prefHeight="30.0" valignment="CENTER" vgrow="ALWAYS" />
<RowConstraints maxHeight="35.0" minHeight="22.0" prefHeight="22.0" valignment="CENTER" vgrow="ALWAYS" />
<RowConstraints valignment="CENTER" vgrow="ALWAYS" />
</rowConstraints>
</GridPane>
When the user click the button a new tab is create and loaded to the TabPane.
Why isn't not working.What i'm doing wrong??
Controller
#FXML
private TabPane tabPane;
#FXML
private void addMemberSelect() {
App.getInstance().showProgressIndicator(myController);
Task<FXMLLoader> task = new Task<FXMLLoader>() {
#Override
protected FXMLLoader call() throws Exception {
return new FXMLLoader(App.class.getResource(Screens.ADD_MEMBER));
}
#Override
protected void succeeded() {
super.succeeded();
Tab tabA = new Tab("Add Member");
final ScrollPane scrollPane = new ScrollPane();
scrollPane.setFitToHeight(true);
scrollPane.setFitToWidth(true);
try {
scrollPane.setContent(get().load());
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
tabA.setContent(scrollPane);
tabPane.getTabs().add(tabA);
App.getInstance().hideProgressIndicator(myController);
}
#Override
protected void failed() {
super.failed();
App.getInstance().hideProgressIndicator(myController);
}
};
new Thread(task).start();
}

Dynamic change of JavaFX controls from other objects

I'm working on a simple javaFX desktop software, it essentially allow a user to control various lights via serial communication.
It's composed of three classes:
he UI Controller (written using javaFX scene builder 2.0 and a custom library for material-like controls, jfoenix)
a "Storage" object with static properties (like which light is on and what color it should display), this class must contain only static properites, so that there are no conflicts with other objects trying to modify some values.
This object is also responsable for the serial communication (using jssc)
A threaded object that controls lights using timers
I must say that i have a working solution built using swing, but i honestly don't like it at all...
Here's the compiled UI: http://imgur.com/esWFsgh
There are two problems:
I want that each button on the top (like "barra 1") displays the status of the corrisponding light, for example, if "barra 1" is on, it should be green, when it's off, it should be red. the problem here is that i have to create an object of the controller class in order to access to all the buttons, but as it should be, in the instantiated object, all the buttons are gone, i should recreate them, and that's obivuosly not the solution... what can i do?
That's simple, I already know that my "listener" is incorrect, but I just can't find the mistake... as soon as I drag any of the sliders, a Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: argument type mismatch exception is thrown... (and there's no reference to any of my classes)
Here you can find the code:
Storage class
package com.matteoformenti.rgbcontroller;
import java.awt.*;
/**
* Created by Matteo on 28/12/2015.
*/
public class Storage
{
private static final String ON_COLOR = "#4CAF50";
private static final String OFF_COLOR = "#F44336";
private static Color color;
private static boolean bars[] = {false, false, false, false, false};
private static boolean circles[] = new boolean[2];
private static boolean usePot = false;
//-------------------------------------------------------//
public static boolean getBarValue(int barNumber)
{
return bars[barNumber];
}
public static void setAllBars(boolean value)
{
for(boolean v : bars)
v = value;
setAllBarsColors();
}
public static boolean[] getAllBars()
{
return bars;
}
public static void setCircleValue(int circleNumber, boolean value)
{
circles[circleNumber-1] = value;
}
public static boolean getCircleValue(int circleNumber)
{
return circles[circleNumber-1];
}
public static void setAllCircles(boolean value)
{
for(boolean v : circles)
v = value;
}
public static boolean[] getAllCircles()
{
return circles;
}
public static void setColor(Color c)
{
color = c;
}
public static void setRed(int red)
{
if(red > 255)
red = 255;
if(red < 0)
red = 0;
int g = color.getGreen();
int b = color.getBlue();
color = new Color(red, g, b);
}
public static void setGreen(int green)
{
if(green > 255)
green = 255;
if(green < 0)
green = 0;
int r = color.getRed();
int b = color.getBlue();
color = new Color(r, green, b);
}
public static void setBlue(int blue)
{
if(blue > 255)
blue = 255;
if(blue < 0)
blue = 0;
int g = color.getGreen();
int r = color.getRed();
color = new Color(r, g, blue);
}
public static void setHue(int h)
{
int rgb = Color.HSBtoRGB(h, 100, 100);
int red = (rgb >> 16) & 0xFF;
int green = (rgb >> 8) & 0xFF;
int blue = rgb & 0xFF;
color = new Color(red, green, blue);
}
public static void invertBarValue(int i)
{
bars[i] = !bars[i];
setBarColor(i);
}
public static void invertCircleValue(int i)
{
circles[i] = !circles[i];
}
public static void setBarColor(int i)
{
Controller c = new Controller();
c.test();
/*Controller.bar1.setStyle("-fx-background-color: " + ON_COLOR + ";");
if (bars[i] == true)
Controller.getBarButton(i).setStyle("-fx-background-color: " + ON_COLOR + ";");
if (bars[i] == false)
Controller.getBarButton(i).setStyle("-fx-background-color: " + OFF_COLOR + ";");*/
}
public static void setAllBarsColors()
{/*
for (int i = 0; i < 5; i++)
{
if (bars[i] == true)
Controller.getBarButton(i + 1).setStyle("-fx-background-color: " + ON_COLOR + ";");
if (bars[i] == false)
Controller.getBarButton(i + 1).setStyle("-fx-background-color: " + OFF_COLOR + ";");
}*/
}
}
Controller class:
package com.matteoformenti.rgbcontroller;
import com.jfoenix.controls.JFXButton;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ColorPicker;
import javafx.scene.control.Slider;
import javafx.scene.layout.Background;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import java.awt.*;
public class Controller
{
#FXML
private JFXButton bar1;
#FXML
private JFXButton bar2;
#FXML
private JFXButton bar3;
#FXML
private JFXButton bar4;
#FXML
private JFXButton bar5;
#FXML
private JFXButton circle1;
#FXML
private JFXButton circle2;
#FXML
private Slider rSlider;
#FXML
private Slider gSlider;
#FXML
private Slider bSlider;
#FXML
private Slider aSlider;
#FXML
private JFXButton pot;
#FXML
private JFXButton stroboBars;
#FXML
private Button stroboBarsConfig;
#FXML
private JFXButton stroboCircles;
#FXML
private Button stroboCirclesConfig;
#FXML
private JFXButton fadeColors;
#FXML
private Button fadeColorsConfig;
#FXML
private ColorPicker colorPicker;
#FXML
private Pane frame;
public void test()
{
bar1.setStyle("-fx-background-color: #33b5e5;");
}
#FXML
void bar1Pressed(ActionEvent event)
{
Storage.invertBarValue(0);
}
#FXML
void bar2Pressed(ActionEvent event) {Storage.invertBarValue(1);}
#FXML
void bar3Pressed(ActionEvent event)
{
Storage.invertBarValue(2);
}
#FXML
void bar4Pressed(ActionEvent event) {Storage.invertBarValue(3);}
#FXML
void bar5Pressed(ActionEvent event) {Storage.invertBarValue(4);}
#FXML
void circle1Pressed(ActionEvent event) {
}
#FXML
void circle2Pressed(ActionEvent event) {
}
#FXML
void potPressed(ActionEvent event) {
}
#FXML
void rSliderChanged(ActionEvent event)
{
}
#FXML
void gSliderChanged(ActionEvent event) {
}
#FXML
void bSliderChanged(ActionEvent event) {
}
#FXML
void aSliderChanged(ActionEvent event) {
}
#FXML
void colorPickerChanged(ActionEvent event)
{
Color colorAWT = Utility.javaFXtoAWTColor(colorPicker.getValue());
frame.setStyle("-fx-background-color: #" + colorPicker.getValue().toString().substring(2,8) + ";");
}
#FXML
void stroboBarsPressed(ActionEvent event) {
}
#FXML
void stroboBarsConfigPressed(ActionEvent event) {
}
#FXML
void stroboCirclesPressed(ActionEvent event) {
}
#FXML
void stroboCirclesConfigPressed(ActionEvent event) {
}
#FXML
void fadeColorsPressed(ActionEvent event) {
}
#FXML
void fadeColorsConfigPressed(ActionEvent event) {
}
}
And the fxml layout
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.paint.*?>
<?import com.jfoenix.controls.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<Pane fx:id="frame" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="260.0" prefWidth="620.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.matteoformenti.rgbcontroller.Controller">
<children>
<HBox fx:id="buttonsBox1" layoutY="30.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="40.0" prefWidth="620.0">
<children>
<JFXButton fx:id="bar1" alignment="CENTER" buttonType="RAISED" onAction="#bar1Pressed" ripplerFill="WHITE" style="-fx-background-color: #F44336;" text="Barra 1">
<font>
<Font name="Roboto Light" size="12.0" />
</font>
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="5.0" top="10.0" />
</HBox.margin>
</JFXButton>
<JFXButton fx:id="bar2" alignment="CENTER" buttonType="RAISED" layoutX="20.0" layoutY="20.0" onAction="#bar2Pressed" ripplerFill="WHITE" style="-fx-background-color: #F44336;" text="Barra 2">
<font>
<Font name="Roboto Light" size="12.0" />
</font>
<HBox.margin>
<Insets bottom="10.0" left="5.0" right="5.0" top="10.0" />
</HBox.margin>
</JFXButton>
<JFXButton fx:id="bar3" alignment="CENTER" buttonType="RAISED" layoutX="80.0" layoutY="10.0" onAction="#bar3Pressed" ripplerFill="WHITE" style="-fx-background-color: #F44336;" text="Barra 3">
<font>
<Font name="Roboto Light" size="12.0" />
</font>
<HBox.margin>
<Insets bottom="10.0" left="5.0" right="5.0" top="10.0" />
</HBox.margin>
</JFXButton>
<JFXButton fx:id="bar4" alignment="CENTER" buttonType="RAISED" layoutX="135.0" layoutY="10.0" onAction="#bar4Pressed" ripplerFill="WHITE" style="-fx-background-color: #F44336;" text="Barra 4">
<font>
<Font name="Roboto Light" size="12.0" />
</font>
<HBox.margin>
<Insets bottom="10.0" left="5.0" right="5.0" top="10.0" />
</HBox.margin>
</JFXButton>
<JFXButton fx:id="bar5" alignment="CENTER" buttonType="RAISED" layoutX="190.0" layoutY="10.0" onAction="#bar5Pressed" ripplerFill="WHITE" style="-fx-background-color: #F44336;" text="Barra 5">
<font>
<Font name="Roboto Light" size="12.0" />
</font>
<HBox.margin>
<Insets bottom="10.0" left="5.0" right="5.0" top="10.0" />
</HBox.margin>
</JFXButton>
<JFXButton fx:id="circle1" alignment="CENTER" buttonType="RAISED" layoutX="280.0" layoutY="20.0" onAction="#circle1Pressed" ripplerFill="WHITE" style="-fx-background-color: #F44336;" text="Cerchio 1">
<font>
<Font name="Roboto Light" size="12.0" />
</font>
<HBox.margin>
<Insets bottom="10.0" left="20.0" right="5.0" top="10.0" />
</HBox.margin>
</JFXButton>
<JFXButton fx:id="circle2" alignment="CENTER" buttonType="RAISED" layoutX="340.0" layoutY="10.0" onAction="#circle2Pressed" ripplerFill="WHITE" style="-fx-background-color: #F44336;" text="Cerchio 2">
<font>
<Font name="Roboto Light" size="12.0" />
</font>
<HBox.margin>
<Insets left="5.0" right="5.0" top="10.0" />
</HBox.margin>
</JFXButton>
<JFXButton fx:id="pot" alignment="CENTER" buttonType="RAISED" layoutX="395.0" layoutY="10.0" onAction="#potPressed" ripplerFill="WHITE" style="-fx-background-color: #F44336;" text="Potenziometri">
<font>
<Font name="Roboto Light" size="12.0" />
</font>
<HBox.margin>
<Insets left="20.0" top="10.0" />
</HBox.margin>
</JFXButton>
</children>
</HBox>
<HBox alignment="CENTER" fillHeight="false" layoutY="80.0" prefHeight="40.0" prefWidth="620.0">
<children>
<VBox prefHeight="200.0" prefWidth="100.0" HBox.hgrow="ALWAYS">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="17.0" prefWidth="135.0" text="Rosso" textAlignment="CENTER" />
<Slider fx:id="rSlider" max="255.0" onDragDetected="#rSliderChanged" value="128.0" />
</children>
<HBox.margin>
<Insets left="10.0" right="10.0" />
</HBox.margin>
</VBox>
<VBox prefHeight="200.0" prefWidth="100.0" HBox.hgrow="ALWAYS">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="17.0" prefWidth="135.0" text="Verde" textAlignment="CENTER" />
<Slider fx:id="gSlider" max="255.0" onDragDetected="#gSliderChanged" value="128.0" />
</children>
<HBox.margin>
<Insets left="10.0" right="10.0" />
</HBox.margin>
</VBox>
<VBox layoutX="110.0" layoutY="10.0" prefHeight="200.0" prefWidth="100.0" HBox.hgrow="ALWAYS">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="17.0" prefWidth="135.0" text="Blu" textAlignment="CENTER" VBox.vgrow="ALWAYS" />
<Slider fx:id="bSlider" max="255.0" onDragDetected="#bSliderChanged" value="128.0" />
</children>
<HBox.margin>
<Insets left="10.0" right="10.0" />
</HBox.margin>
</VBox>
<VBox layoutX="210.0" layoutY="10.0" prefHeight="200.0" prefWidth="100.0" HBox.hgrow="ALWAYS">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="17.0" prefWidth="135.0" text="Luminosità" textAlignment="CENTER" />
<Slider fx:id="aSlider" max="255.0" onDragDetected="#aSliderChanged" value="128.0" />
</children>
<HBox.margin>
<Insets left="10.0" right="10.0" />
</HBox.margin>
</VBox>
</children>
</HBox>
<ColorPicker fx:id="colorPicker" layoutX="10.0" layoutY="130.0" onAction="#colorPickerChanged" prefHeight="25.0" prefWidth="600.0" />
<HBox alignment="TOP_CENTER" layoutY="175.0" prefHeight="50.0" prefWidth="620.0">
<children>
<HBox prefHeight="50.0" prefWidth="150.0">
<children>
<JFXButton fx:id="stroboBars" alignment="CENTER" buttonType="RAISED" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" onAction="#stroboBarsPressed" ripplerFill="WHITE" style="-fx-background-color: #F44336;" text="Strobo Barre" textAlignment="CENTER" HBox.hgrow="ALWAYS">
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="5.0" top="10.0" />
</HBox.margin>
</JFXButton>
<Button fx:id="stroboBarsConfig" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#stroboBarsConfigPressed" prefHeight="25.0" prefWidth="25.0" style="-fx-background-color: #33b5e5;" textFill="#33b5e5">
<HBox.margin>
<Insets bottom="10.0" right="10.0" top="10.0" />
</HBox.margin>
</Button>
</children>
</HBox>
<HBox layoutX="150.0" layoutY="10.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="50.0" prefWidth="150.0">
<children>
<JFXButton fx:id="stroboCircles" alignment="CENTER" buttonType="RAISED" onAction="#stroboCirclesPressed" ripplerFill="WHITE" style="-fx-background-color: #F44336;" text="Strobo Cerchi" textAlignment="CENTER" HBox.hgrow="ALWAYS">
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="5.0" top="10.0" />
</HBox.margin>
</JFXButton>
<Button fx:id="stroboCirclesConfig" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#stroboCirclesConfigPressed" prefHeight="25.0" prefWidth="25.0" style="-fx-background-color: #33b5e5;" textFill="#33b5e5">
<HBox.margin>
<Insets bottom="10.0" right="10.0" top="10.0" />
</HBox.margin>
</Button>
</children>
</HBox>
<HBox layoutX="320.0" layoutY="10.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="50.0" prefWidth="150.0">
<children>
<JFXButton fx:id="fadeColors" alignment="CENTER" buttonType="RAISED" onAction="#fadeColorsPressed" ripplerFill="WHITE" style="-fx-background-color: #F44336;" text="Strobo Cerchi" textAlignment="CENTER" HBox.hgrow="ALWAYS">
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="5.0" top="10.0" />
</HBox.margin>
</JFXButton>
<Button fx:id="fadeColorsConfig" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#fadeColorsConfigPressed" prefHeight="25.0" prefWidth="25.0" style="-fx-background-color: #33b5e5;" textFill="#33b5e5">
<HBox.margin>
<Insets bottom="10.0" right="10.0" top="10.0" />
</HBox.margin>
</Button>
</children>
</HBox>
</children>
</HBox>
</children>
</Pane>
Thanks a ton for your help, have a nice day!!
Formenti Matteo
The exception you are getting is because you are trying to hook a MouseEvent handler to an ActionEvent handler - see here. Changing the argument type to MouseEvent should get rid of the exception.
However! this event deals with drag-and-drop, which is probably not what you are after! See this tutorial - you should either bind to the value property of the slider, or add a ChangeListener to it.

Categories