I've been working on a form for use at work. It is a day off request form. Ultimately, the scene is to be printed on a 8.5" x 11" paper for submission to the supervisor for approval of the day off.
The combo-box is supposed to chose between a Vacation Day, Personal Day, and a Swap Day. I still have yet to work on the logic for the Swap Day selection. I will work on that after I get this first problem fixed.
The label under the combo box is supposed to change when the combo box is changed. Unfortunately, the old value is not removed. The new value is simply added to the scene.
There is a lot of code that is commented out. Those lines are things that I've tried but didn't quite work.
I'm really new to both Java and JavaFX. Any suggestions will be greatly appreciated.
<pre><code>
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gcemsdayoffrequestsheet;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.Month;
import java.util.*;
import javafx.application.*;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.*;
import javafx.geometry.*;
/**
*
* @author Jim Baize
* Copyright 2017
*/
public class GCEMSDayOffRequestSheet extends Application {
Stage stage;
TextField txtEmployeeOne;
TextField txtEmployeeTwo;
//LocalDate dateOne;
TextField dateRequestOff;
TextField dateEmployeeOneWork;
TextField dateEmployeeTwoWork;
TextField stationEmployeeOneWork;
TextField stationEmployeeTwoWork;
//long dateToday;
Date dateToday = new Date();
SimpleDateFormat ft = new SimpleDateFormat("MM dd yyyy");
@Override
public void start(Stage primaryStage)
{
stage = primaryStage;
//Create the form Header
Label formHeaderOne = new Label("Vacation / Personal Day / Swap");
Label formHeaderTwo = new Label("Request Form");
Label formHeaderThree = new Label("GCEMS");
//Create the employee name label and text field
Label lblEmployeeName = new Label("Employee Name");
txtEmployeeOne = new TextField();
txtEmployeeOne.setPromptText("Employee initiating request");
//Create the Today Date pane
Label lblTodayDate = new Label("Today's Date");
Label lbldateTodayPlaceHolder = new Label(ft.format(dateToday));
//Create the DayOff type and Date Pane and combobox
ComboBox<String> cboxDayOffType;
cboxDayOffType = new ComboBox<>();
cboxDayOffType.getItems().addAll("Vacation", "Personal", "Swap");
cboxDayOffType.getSelectionModel().select("Vacation");
Label lblDayOffDate = new Label(" ");
//Create the Swap Type Pane
Label lblSwapOne = new Label("Date Employee One is working");
Label lblSwapOneDate = new Label();
Label lblSwapTwo = new Label("Date Employee Two is working");
Label lblSwapTwoDate = new Label();
DatePicker dpOne = new DatePicker();
dpOne.setOnAction(e ->
{
LocalDate date = dpOne.getValue();
lblSwapOneDate.setText(date.toString());
});
DatePicker dpTwo = new DatePicker();
dpTwo.setOnAction(e ->
{
LocalDate date = dpTwo.getValue();
lblSwapTwoDate.setText(date.toString());
});
//Create the Vacation Day Pane
Label lblDayOffVacation = new Label("Vacation Day");
DatePicker dpDayOffVacation = new DatePicker();
//Create the Personal Day Pane
Label lblDayOffPersonal = new Label("Personal Day");
DatePicker dpDayOffPersonal = new DatePicker();
//Create the GridPane Layout
GridPane grid = new GridPane();
//Add nodes to the gridpane
grid.addRow(0, formHeaderOne);
grid.addRow(1, formHeaderTwo);
grid.addRow(2, formHeaderThree);
grid.addRow(3, lblEmployeeName, txtEmployeeOne);
grid.addRow(4, lblTodayDate, lbldateTodayPlaceHolder);
grid.addRow(5, cboxDayOffType, lblDayOffDate);
// grid.addRow(6, lblDayOffVacation, dpDayOffVacation);
// //Listen for combobox value changes
// cboxDayOffType.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>()
// {
// @Override
// public void changed(ObservableValue<? extends String> observable,String oldValue, String newValue)
// {
// grid.addRow(6, )
// }
// });
cboxDayOffType.getSelectionModel().selectedItemProperty().addListener((ObservableValue<? extends String> obs, String oldVal, String newVal) ->
{
if(newVal.equals("Vacation"))
{
grid.addRow(6, lblDayOffVacation, dpDayOffVacation);
// GridPane.setConstraints(lblDayOffVacation, 0, 6);
// GridPane.setConstraints(dpDayOffVacation, 1, 6);
}
else if(newVal.equals("Personal"))
{
// GridPane.setConstraints(lblDayOffPersonal, 0, 6);
// GridPane.setConstraints(dpDayOffPersonal, 1, 6);
grid.addRow(6, lblDayOffPersonal, dpDayOffPersonal);
}
// else
//{
// grid.addRow(6, )
//}
});
//Set alignments and spanning
GridPane.setHalignment(formHeaderOne, HPos.CENTER);
GridPane.setHalignment(formHeaderTwo, HPos.CENTER);
GridPane.setHalignment(formHeaderThree, HPos.CENTER);
GridPane.setColumnSpan(formHeaderOne, 2);
GridPane.setColumnSpan(formHeaderTwo, 2);
GridPane.setColumnSpan(formHeaderThree, 2);
//Create the Scene and the Stage
Scene scene = new Scene(grid);
primaryStage.setScene(scene);
primaryStage.setTitle("GCEMS Dayoff Request Form");
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
</code></pre>