JavaFX creating series for linechart: null - javafx

I am creating a new window controller in which I process data to be put into a linechart.
Though in the end the new window shows an empty LineChart. When I debug the line in which the series is put into the Linechart, the IDE states "series[null]".
So what am I missing?
Class of the new window:
public class ChartWindow {
Map<Job, List<LoadTestResultStatus>> lTRSMapOfJobs;
final LineChart lineChartMain;
Job originJob;
XYChart.Series series;
boolean lTRSfilled=false;
ObjectHub objectHub;
public ChartWindow(Job job, ObjectHub objectHub) {
this.objectHub = objectHub;
series = new XYChart.Series();
final NumberAxis xAxis = new NumberAxis();
final NumberAxis yAxis = new NumberAxis();
xAxis.setLabel("Time");
yAxis.setLabel("Time");
lineChartMain = new LineChart<Number, Number>(xAxis, yAxis);
lTRSMapOfJobs = new HashMap<>();
originJob = job;
lTRSMapOfJobs.put(job, objectHub.getDbManagement().getLTRSListOfJobFromDB(job));
fillLineChart();
}
public void fillLineChart() {
Platform.runLater(new Runnable() {
#Override
public void run() {
objectHub.getGuiReporter().statusStart(0);
objectHub.getGuiReporter().progressbarAddAmountOfStep(lTRSMapOfJobs.get(originJob).size());
}
});
for (LoadTestResultStatus l : lTRSMapOfJobs.get(originJob)) {
objectHub.getExecutor().submit(new Runnable() {
#Override
public void run() {
XYChart.Data xyChart = new XYChart.Data(l.getTs(), l.getLt());
try {
addToSeries(xyChart);
objectHub.getGuiReporter().progressbarAddStep();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
//TODO heavy CPU load:(
while(!lTRSfilled){
if(ObjectHub.getGuiReporter().progressBarDifference()==0){
lTRSfilled = true;
}
}
lineChartMain.getData().addAll(series);
}
void addToSeries(XYChart.Data xyChart) {
synchronized (this) {
series.getData().add(xyChart);
}
}
public Map<Job, List<LoadTestResultStatus>> getlTRSMapOfJobs() {
return lTRSMapOfJobs;
}
public void setlTRSMapOfJobs(Map<Job, List<LoadTestResultStatus>> lTRSMapOfJobs) {
this.lTRSMapOfJobs = lTRSMapOfJobs;
}
public LineChart getLineChartMain() {
return lineChartMain;
}
}
MainController method who processes the new window:
public void showLineChartForJob() {
progressBarLabel.setText("Preparing Linechart calculation...");
ChartWindow object to request executorservices
Thread createChartWindow = new Thread(new Runnable() {
#Override
public void run() {
int jobId = Integer.parseInt(visualizeTabIdInputTextField.getText());
Job lineChartJob = new Job(objectHub);
for (Job j : objectHub.getLtResultManagement().getjobSet()) {
if (j.getNumber() == jobId) {
lineChartJob = j;
break;
}
}
chartWindowList.add(new ChartWindow(lineChartJob, objectHub));
Platform.runLater(new Runnable() {
#Override
public void run() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/ChartWindow.fxml"));
fxmlLoader.setController(chartWindowList.get(0));
StackPane secondaryLayout = new StackPane();
try {
secondaryLayout.getChildren().setAll(Collections.singleton(fxmlLoader.load()));
} catch (IOException e) {
e.printStackTrace();
}
Scene secondScene = new Scene(secondaryLayout, 1200, 1600);
Stage newWindow = new Stage();
newWindow.setTitle("Second Stage");
newWindow.setScene(secondScene);
newWindow.setX(50);
newWindow.setY(50);
newWindow.show();
}
});
}
});
createChartWindow.setName("createChartWindowThread");
createChartWindow.start();
}
Capture from debug taken at the last line of the First Controller:
Regards

Ok, case closed:
Failure was to not adress the scene to the linechart:
Scene secondScene = new Scene(secondaryLayout, 1200, 1600);
Fixed by obtaining the chart from the controller:
Scene secondScene = new Scene(chartWindowList.get(0).lineChartMain, 1200, 1600);

Related

Create Nodes within Loop

Note: this is an updatet version of the initial question.
Whats now beeing asked is how I can get access to the values of a certain row for calculations purposes. For example how can I calculate the difference betweeen values of the expensesColumn and the earningsColumn? (Because there was to much code within my questions, I deleted most of the imports)
package application;
import javafx.application.Application;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {Table.create(primaryStage);}
catch(Exception e) {e.printStackTrace();}
}
public static void main(String[] args) {
launch(args);
}
}
package application;
public class UserJava {
private String member;
private double expenses;
private double earnings;
//Getter und Setter
public String getMember() {
return member;
}
public void setMember(String member) {
this.member = member;
}
public double getExpenses() {
return expenses;
}
public void setExpenses(double expenses) {
this.expenses = expenses;
}
public double getEarnings() {
return earnings;
}
public void setEarnings(double earnings) {
this.earnings = earnings;
}
}
package application;
import javafx.stage.Stage;
public class Table {
static TableView<UserJava> table;
public static void create (Stage primaryStage){
try {
GridPane primarygridpane = new GridPane();
HBox hboxTable = new HBox(10);
//Definition der Tabelle
TableColumn<UserJava, String> userColumn = new TableColumn<>("Name");
userColumn.setCellValueFactory(new PropertyValueFactory<>("member"));
userColumn.setMinWidth(200);
TableColumn<UserJava, Double> expensesColumn = new TableColumn<>("Ausgaben");
expensesColumn.setCellValueFactory(new PropertyValueFactory<>("expenses"));
expensesColumn.setMinWidth(100);
TableColumn<UserJava, Double> earningsColumn = new TableColumn<>("Pfand");
earningsColumn.setCellValueFactory(new PropertyValueFactory<>("earnings"));
earningsColumn.setMinWidth(100);
table = new TableView<>();
table.getColumns().addAll(userColumn, expensesColumn, earningsColumn);
TextField tfMember = new TextField();
tfMember.setMinWidth(200);
tfMember.setPromptText("Name");
TextField tfExpenses = new TextField();
tfExpenses.setMinWidth(100);
tfExpenses.setPromptText("Ausgaben");
TextField tfEarnings = new TextField();
tfEarnings.setMinWidth(100);
tfEarnings.setPromptText("Pfand");
Button btnAdd = new Button("Hinzufügen");
Button btnDelete = new Button("Löschen");
hboxTable.getChildren().addAll(tfMember, tfExpenses, tfEarnings, btnAdd, btnDelete);
table.setEditable(true);
userColumn.setCellFactory(TextFieldTableCell.forTableColumn());
// table.setItems(getUser());
//Sonstiges
Scene scene = new Scene(primarygridpane,725,400);
Text titel = new Text("Application");
titel.setFont(Font.font("Arial", FontWeight.BOLD, 28));
primarygridpane.add(titel, 0, 0, 2, 1);
primarygridpane.add(table, 0, 2);
primarygridpane.add(hboxTable, 0, 3);
// scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
//Funktionen
btnAdd.setOnAction(new EventHandler<ActionEvent>(){
#Override
public void handle(ActionEvent e) {
try {
UserJava user = new UserJava();
user.setMember(tfMember.getText());
user.setExpenses(Double.parseDouble(tfExpenses.getText()));
user.setEarnings(Double.parseDouble(tfEarnings.getText()));
table.getItems().add(user);
tfMember.clear();
tfExpenses.clear();
tfEarnings.clear();
System.out.println(table.getItems());
}
catch (NumberFormatException Ausnahme) {}
}
});
btnDelete.setOnAction(new EventHandler<ActionEvent>(){
#Override
public void handle(ActionEvent e) {
try {
ObservableList<UserJava> userSelected, userAll;
userAll = table.getItems();
userSelected = table.getSelectionModel().getSelectedItems();
userSelected.forEach(userAll::remove);
System.out.println();
}
catch (java.util.NoSuchElementException Ausnahme) {}
}
});
}
catch (Exception e) {e.printStackTrace();}
}
public ObservableList<UserJava> getUser(){
ObservableList<UserJava> user = FXCollections.observableArrayList();
user.add(new UserJava());
return user;
}
public void changeCell(CellEditEvent<?, ?> ediditedCell) {
UserJava personSelected = table.getSelectionModel().getSelectedItem();
personSelected.setMember(ediditedCell.getNewValue().toString());
}
}

ProgressIndicator finishes when I start another Stage

I want to create an application starter. The ProgressIndicator should running during start of the new Stage in new Thread. But if I click at the start button the ProgressIndicator stops running.
It works if I make some I/O and ProgressIndicator shows progress. It is apparently not possible to update two stages in JavaFX in parallel or does anyone have a solution for me?
public class Main extends Application {
public void start(Stage primaryStage) {
primaryStage.setScene(new Scene(new UserVC().getView(), 600, 200));
primaryStage.show();
userVC.autologin();
}
public static void main(String[] args) { launch(args); }
}
public class UserView extends BorderPane {
private ProgressIndicator progressIndicator = new ProgressIndicator();
public UserView() {
super.setCenter(createContent());
}
public Node createContent() {
HBox userbox = new HBox();
userbox.getChildren().add(progressIndicator);
progressIndicator.show();
return userbox;
}
}
public class UserVC {
private UserView view = new UserView();
public UserVC() {
}
public void autologin() {
Task<Void> task = new Task<Void>() {
#Override public Void call() throws InterruptedException {
try {
Thread.sleep(1000);
Platform.runLater(new Runnable() {
#Override public void run() {
Stage stage = new Stage();
stage.setScene(new Scene(new MainControlVC().getView(), 900, 300));
stage.show();
}
});
}
catch(Exception e) {
e.printStackTrace();
}
return null;
}
};
view.getProgressIndicator().progressProperty().unbind();
view.getProgressIndicator().progressProperty().bind(task.progressProperty());
new Thread(task).start();
}
}
I changed the Task to Thread and it works fine now:
Thread thread = new Thread() {
public void run() {
mainController = new MainControlVC(dataDirectory, user);
Platform.runLater(new Runnable() {
#Override public void run() {
Stage stage = new Stage();
Scene scene = new Scene(mainController.getView(), mainController.getWidth(), mainController.getHeight());
stage.setScene(scene);
stage.show();
}
});
}
};
thread.start();

How to access table data from outside the controller in javafx

I'm trying to create a material inventory program that uses a tableview. I have a controller that will show statistics based on that tableview but I'm not sure how to access the live data from that view.
My MainApp loads the last saved table and my MaterialOverviewController has the tableview.
I have a RootLayoutController which is my main layout controller which has a simple file menu but also is where the OnFloorStatsController is loaded from.
I can obviously create a new MainApp when the OnFloorStatsController is loaded but this only loads the sample data that was entered by default.
How do I access the live data from the MainApp?
Here is my MainApp code:
public class MainApp extends Application {
private Stage primaryStage;
private BorderPane rootLayout;
private ObservableList<Material> materialData = FXCollections.observableArrayList();
#Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
this.primaryStage.setTitle("Label Inventory");
this.primaryStage.getIcons().add(new Image("file:resources/images/1462487405_Mask.png"));
initRootLayout();
showMaterialOverview();
}
public MainApp() {
// Add some sample data
}
public ObservableList<Material> getMaterialData() {
return materialData;
}
/**
* Initializes the root layout and tries to load the last opened
* material file.
*/
public void initRootLayout() {
try {
// Load root layout from fxml file.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class
.getResource("RootLayout.fxml"));
rootLayout = (BorderPane) loader.load();
// Show the scene containing the root layout.
Scene scene = new Scene(rootLayout);
primaryStage.setScene(scene);
// Give the controller access to the main app.
RootLayoutController controller = loader.getController();
controller.setMainApp(this);
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
// Try to load last opened person file.
File file = getMaterialFilePath();
if (file != null) {
loadMaterialDataFromFile(file);
}
}
public void showMaterialOverview() {
try {
// Load material overview.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource("MaterialOverview.fxml"));
AnchorPane materialOverview = (AnchorPane) loader.load();
// Set material overview into the center of root layout.
rootLayout.setCenter(materialOverview);
// Give the controller access to the main app.
MaterialOverviewController controller = loader.getController();
controller.setMainApp(this);
} catch (IOException e) {
e.printStackTrace();
}
}
public void showOnFloorStatistics() {
try {
// Load the fxml file and create a new stage for the popup.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource("OnFloorStats.fxml"));
AnchorPane page = (AnchorPane) loader.load();
Stage dialogStage = new Stage();
dialogStage.setTitle("Material On Floor");
dialogStage.initModality(Modality.WINDOW_MODAL);
dialogStage.initOwner(primaryStage);
Scene scene = new Scene(page);
dialogStage.setScene(scene);
// Set the material into the controller.
OnFloorStatsController controller = loader.getController();
controller.start(dialogStage);
dialogStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
public void showBarChartTest() {
try {
// Load the fxml file and create a new stage for the popup.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource("BarChartTestLayout.fxml"));
AnchorPane page = (AnchorPane) loader.load();
Stage dialogStage = new Stage();
dialogStage.setTitle("Detailed Bar Chart");
//
dialogStage.initModality(Modality.WINDOW_MODAL);
dialogStage.initOwner(primaryStage);
Scene scene = new Scene(page);
dialogStage.setScene(scene);
// Set the material into the controller.
BarChartTest controller = loader.getController();
controller.start(dialogStage);
dialogStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Returns the main stage.
* #return
*/
public Stage getPrimaryStage() {
return primaryStage;
}
public static void main(String[] args) {
launch(args);
}
}
And here is my MaterialOverViewController code:
public class MaterialOverviewController {
#FXML
private TableView<Material> materialTable;
private List<Material> materialId;
public TableView<Material> getMaterialTable() {
return materialTable;
}
// public void setMaterialTable(TableView<Material> materialTable) {
// this.materialTable = materialTable;
}
private ObservableList<Integer> rollsTotal = FXCollections.observableArrayList();
private ObservableList<String> materialNames = FXCollections.observableArrayList();
// Reference to the main application.
private MainApp mainApp;
/**
* The constructor.
* The constructor is called before the initialize() method.
*/
public MaterialOverviewController() {
}
/**
* Initializes the controller class. This method is automatically called
* after the fxml file has been loaded.
*/
#FXML
private void initialize() {
materialTotal = 0;
// Initialize the material table with columns.
pONumberColumn.setCellValueFactory(cellData -> cellData.getValue().pONumberProperty());
materialNameColumn.setCellValueFactory(cellData -> cellData.getValue().materialNameProperty());
materialIdColumn.setCellValueFactory(cellData -> cellData.getValue().materialIdProperty());
materialWidthColumn.setCellValueFactory(cellData -> cellData.getValue().materialWidthProperty().asObject());
qtyOrderedColumn.setCellValueFactory(cellData -> cellData.getValue().qtyOrderedProperty().asObject());
qtyReceivedColumn.setCellValueFactory(cellData -> cellData.getValue().qtyReceivedProperty().asObject());
qtyBackOrderedColumn.setCellValueFactory(cellData -> cellData.getValue().qtyBackOrderedProperty().asObject());
// qtyBackOrderedColumn.setCellValueFactory(cellData -> cellData.getValue().qtyBackOrderedProperty().asObject());
qtyOnFloorColumn.setCellValueFactory(cellData -> cellData.getValue().qtyOnFloorProperty().asObject());
// dateOrderedColumn.setCellValueFactory(cellData -> cellData.getValue().dateOrderedProperty().asString());
dateOrderedColumn.setCellValueFactory(cellData -> cellData.getValue().dateOrderedProperty().asString());
estArrivalColumn.setCellValueFactory(cellData -> cellData.getValue().dateExpectedProperty().asString());
supplierColumn.setCellValueFactory(cellData -> cellData.getValue().supplierProperty());
// Clear material details.
showMaterialDetails(null);
// Listen for selection changes and show the material details when changed.
materialTable.getSelectionModel().selectedItemProperty().addListener(
(observable, oldValue, newValue) -> showMaterialDetails(newValue));
}
public void setMainApp(MainApp mainApp) {
this.mainApp = mainApp;
// Add observable list data to the table
materialTable.setItems(mainApp.getMaterialData());
}
private void showMaterialDetails(Material material) {
if (material != null) {
// Fill the labels with info from the material object.
pONumberLabel.setText(material.getPoNumber());
materialIdLabel.setText(material.getMaterialId());
materialNameLabel.setText(material.getMaterialName());
materialWidthLabel.setText(String.valueOf(material.getMaterialWidth()));
qtyOrderedLabel.setText(Integer.toString(material.getQtyOrdered()));
qtyRecievedLabel.setText(Integer.toString(material.getQtyReceived()));
qtyBackOrderedLabel.setText(Integer.toString(material.getQtyOrdered()-material.getQtyReceived()));
// qtyBackOrderedLabel.setText(Integer.toString(material.getQtyBackOrdered()));
qtyOnFloorLabel.setText(Integer.toString(material.getQtyOnFloor()));
// dateOrderedLabel.setText(DateUtil.format(material.getDateOrdered()));
// dateOrderedLabel.equals(DateUtil.format(material.getDateOrdered()));
// dateOrderedLabel.setText(DatePicker(String.valueOf(material.getDateOrdered());
// estArrivalLabel.setText(material.getSupplier());
supplierLabel.setText(material.getSupplier());
String pattern = "MM/dd/yyyy";
// dateTestTextField.setText(DateUtil.format(material.getBirthday()));
dateOrderedLabel.setText(DateUtil.format(material.getDateOrdered()));
estArrivalLabel.setText(DateUtil.format(material.getDateExpected()));
//TODO: set running material totals
// getMaterialNames(Arrays.asList(material));
handleSelectMaterial();
}
}
}
public List getMaterialNames(List<Material> materials) {
for (Material name : materials) {
mainApp.getMaterialData();
if (!materialNames.contains(name)) {
materialNames.add(name.getMaterialName());
}
}
for (String name : materialNames) {
materialTextField.setText(name + "\n");
}
return Arrays.asList(materialNames);
}
}
}
Here is the bit of code that works from my RootLayoutController but I'm not sure why I can't do the same thing from the OnFloorStatsController:
public void setMainApp(MainApp mainApp) {
this.mainApp = mainApp;
}
#FXML
private void handlePrint() {
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(getClass().getResource("MaterialOverview.fxml"));
try {
AnchorPane frame = fxmlLoader.load();
} catch (IOException e) {
e.printStackTrace();
}
MaterialOverviewController c = fxmlLoader.getController();
//Loads data into table
c.setMainApp(mainApp);
I just need access to the live data from the MaterialOvewViewController
Here's the OnFloorStatsController:
private MainApp mainApp;
public TableView<Material> material;
/**
* Is called by the main application to give a reference back to itself.
*
* #param mainApp
*/
public void setMainApp(MainApp mainApp) {
this.mainApp = mainApp;
}
// final static String austria = "14532";
// final static String brazil = "78333";
// final static String france = "40443";
// final static String italy = "72825";
// final static String usa = "72829";
public void start(Stage stage) {
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(getClass().getResource("MaterialOverview.fxml"));
try {
AnchorPane frame = fxmlLoader.load();
} catch (IOException e) {
e.printStackTrace();
}
MaterialOverviewController c = fxmlLoader.getController();
//Loads data into table
c.setMainApp(mainApp);
stage.setTitle("Material On Floor");
final CategoryAxis xAxis = new CategoryAxis();
final NumberAxis yAxis = new NumberAxis();
final BarChart<String, Number> bc =
new BarChart<String, Number>(xAxis, yAxis);
bc.setTitle("Material On Floor");
xAxis.setLabel("Material");
yAxis.setLabel("Quantity");
XYChart.Series series1 = new XYChart.Series();
series1.setName("6 inch");
Integer floorTotal = 0;
for (Material id :mainApp.getMaterialData()) {
if (id.getMaterialWidth() < 6.9) {
floorTotal = id.getQtyOnFloor();
for (Material size : mainApp.getMaterialData()) {
if ( id.getMaterialId().equalsIgnoreCase(size.getMaterialId()) &&
size.getMaterialWidth() == id.getMaterialWidth()) {
floorTotal += size.getQtyOnFloor();
}
else {
floorTotal = id.getQtyOnFloor();
}

JavaFX StackPane/group prevents me from resizing screen

I cant get this to resize, it always go for the preferred size for each screen. This is not ideal for a full screen application. It bascially just becomes a little box in the top left corner =(
I've spent days on this now but cant get it to work.
Could anyone tell me what im doing wrong? thanks
Main class:
public class Main extends Application {
public static final String MAIN_SCREEN = "main";
public static final String MAIN_SCREEN_FXML = "../gui/main.fxml";
public static final String CUSTOMER_SCREEN = "customer_main";
public static final String CUSTOMER_SCREEN_FXML = "../gui/customer_main.fxml";
#Override
public void start(Stage primaryStage) {
primaryStage.setFullScreen(true);
primaryStage.centerOnScreen();
ScreensController mainContainer = new ScreensController();
mainContainer.loadScreen(Main.MAIN_SCREEN,
Main.MAIN_SCREEN_FXML);
mainContainer.loadScreen(Main.CUSTOMER_SCREEN,
Main.CUSTOMER_SCREEN_FXML);
mainContainer.setScreen(Main.MAIN_SCREEN);
Group root = new Group();
root.getChildren().addAll(mainContainer);
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
mainContainer.requestLayout();
}
public static void main(String[] args) {
launch(args);
}
First screen controller class (has FXML file):
public class MainScreenController implements ControlledScreen, Initializable{
ScreensController myController;
#FXML
private VBox mainScreen;
#FXML
private void mainScreenClicked(){
myController.setScreen(Main.CUSTOMER_SCREEN);
}
#Override
public void initialize(URL arg0, ResourceBundle arg1) {
}
#Override
public void setScreenParent(ScreensController screenParent) {
myController = screenParent;
}
Stack pane for a nice layout:
public class ScreensController extends StackPane {
public ScreensController(){
}
private HashMap<String, Node> screens = new HashMap<>();
public void addScreen(String name, Node screen) {
screens.put(name, screen);
}
public boolean loadScreen(String name, String resource) {
try {
FXMLLoader myLoader = new FXMLLoader(getClass().getResource(resource));
Parent loadScreen = (Parent) myLoader.load();
ControlledScreen myScreenControler =
((ControlledScreen) myLoader.getController());
myScreenControler.setScreenParent(this);
addScreen(name, loadScreen);
return true;
}catch(Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
return false;
}
}
public boolean setScreen(final String name) {
if(screens.get(name) != null) { //screen loaded
final DoubleProperty opacity = opacityProperty();
//Is there is more than one screen
if(!getChildren().isEmpty()){
Timeline fade = new Timeline(
new KeyFrame(Duration.ZERO,
new KeyValue(opacity,1.0)),
new KeyFrame(new Duration(1000),
new EventHandler() {
#Override
public void handle(Event t) {
//remove displayed screen
getChildren().remove(0);
//add new screen
getChildren().add(0, screens.get(name));
Timeline fadeIn = new Timeline(
new KeyFrame(Duration.ZERO,
new KeyValue(opacity, 0.0)),
new KeyFrame(new Duration(800),
new KeyValue(opacity, 1.0)));
fadeIn.play();
}
}, new KeyValue(opacity, 0.0)));
fade.play();
} else {
//no one else been displayed, then just show
setOpacity(0.0);
getChildren().add(screens.get(name));
Timeline fadeIn = new Timeline(
new KeyFrame(Duration.ZERO,
new KeyValue(opacity, 0.0)),
new KeyFrame(new Duration(2500),
new KeyValue(opacity, 1.0)));
fadeIn.play();
}
return true;
} else {
System.out.println("screen hasn't been loaded!\n");
return false;
}
}
public boolean unloadScreen(String name) {
if(screens.remove(name) == null) {
System.out.println("Screen didn't exist");
return false;
} else {
return true;
}
}
}
interface so that each screen knows its parent:
public interface ControlledScreen {
public void setScreenParent(ScreensController screenPage);
}
Second controller class to verify that the stackpane works (has FXML file):
public class CustomerMenuController implements ControlledScreen, Initializable {
ScreensController myController;
#FXML
private FlowPane customerMenuFlow;
#Override
public void initialize(URL location, ResourceBundle resources) {
for (int i = 0; i < 3;i++){
new Customer();
}
Button [] menuButtons = new Button[Customer.customers.size()];
for (int i = 0; i < Customer.customers.size();i++){
menuButtons[i] = new Button("Customer " + i);
customerMenuFlow.getChildren().add(menuButtons[i]);
}
}
#Override
public void setScreenParent(ScreensController screenParent) {
myController = screenParent;
}
}
You shouldn't use primaryStage.setFullScreen(true); for resizable applications. Not in this context anyway. Once you remove that line, the application will start with its preferred size, but then the user is able to drag the corners of the window to resize the application.

Javafx web browser

I am trying to add a history , backward and forward buttons that actually do there jobs , so the history opens a drop down menu that shows the links the user went to and provided with a clear button to delete them if wanted and the backward to move back and the forward to go the the page the user was on.
public Test4(){
initComponents();
}
public static void main(String ...args){
SwingUtilities.invokeLater(new Runnable() {
public void run() {
final JFrame frame = new JFrame();
frame.getContentPane().add(new Test4());
frame.setMinimumSize(new Dimension(640, 480));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
private void initComponents(){
jfxPanel = new JFXPanel();
createScene();
setLayout(new BorderLayout());
add(jfxPanel, BorderLayout.CENTER);
swingButton = new JButton();
swingButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Platform.runLater(new Runnable() {
public void run() {
webEngine.reload();
}
});
}
});
swingButton.setText("Reload");
add(swingButton, BorderLayout.SOUTH);
}
private void createScene() {
PlatformImpl.startup(new Runnable() {
public void run() {
stage = new Stage();
stage.setTitle("Hello Java FX");
stage.setResizable(true);
Group root = new Group();
Scene scene = new Scene(root,80,10);
stage.setScene(scene);
browser = new WebView();
webEngine = browser.getEngine();
webEngine.load("http://www.google.com");
ObservableList<Node> children = root.getChildren();
children.add(browser);
jfxPanel.setScene(scene);
}
});
}
}

Resources