I'm trying to figure out a way to toggle the JavaFX DatePicker between month view and week view. I'm new to JavaFX and fairly new to Java in general. I'm not even sure if there is a week view available in JavaFX.
I've searched other StackOverflow questions and found mostly answers about development in Android that didn't really answer my question. The app I'm working on is going to be a desktop application.
Here is some example code that I've been using to try to figure this out-
Main Class:
package Application;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
public class Main extends Application {
private Stage primaryStage;
@Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
mainWindow();
}
public void mainWindow() {
try {
FXMLLoader loader = new FXMLLoader(Main.class.getResource("DatePickerView.fxml"));
AnchorPane pane = loader.load();
Scene scene = new Scene(pane);
MainWindowController mainWindowController = loader.getController();
mainWindowController.setMain(this);
primaryStage.setScene(scene);
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
Main Controller:
package Application;
import javafx.fxml.FXML;
import javafx.scene.control.DatePicker;
public class MainWindowController {
@FXML private DatePicker datePicker;
private Main main;
public void setMain(Main main){
this.main = main;
}
}
FXML File:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="300.0" prefWidth="500.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="Application.MainWindowController">
<children>
<DatePicker fx:id="datePicker" layoutX="141.0" layoutY="94.0" />
</children>
</AnchorPane>
This is just a very simple window with a DatePicker that I wrote to try to figure this out. If anyone knows of a way to switch to a week view in the DatePicker I would really appreciate any insight.