How to add a calendar in the Frame or Panel in Java

1

I'm developing a Java project that handles dates. The main idea is to place a medium-sized calendar on the main screen , dates that already have a scheduled event should have a coloration (blue, orange, etc.) and when hovering over the menu it should show something like a pop-up and show a brief description of the event.

The project is being developed using JavaFx combined with elements of Swing . My searches only gave me the JCalendar that does not meet my needs.

Any tips are welcome. My focus here are ideas PS: I'm a beginner here ....

    
asked by anonymous 13.09.2018 / 14:20

1 answer

0

Basically you'll have to implement a dayCellFactory , this will allow you to manipulate how the calendar cells will be rendered. Example of commented documentation:

DatePicker dp = new DatePicker();

dp.setDayCellFactory(new Callback<DatePicker, DateCell>() {

    @Override
    public DateCell call(DatePicker arg0) {
        return new DateCell() {
            @Override
            public void updateItem(LocalDate item, boolean empty) {
                // Chamada obrigatória ao renderizador da superclasse
                super.updateItem(item, empty);

                // Aqui estamos trocando a cor do background de um dia específico
                if(MonthDay.from(item).equals(MonthDay.of(9, 15))) {
                    setStyle("-fx-background-color: #ff4444;");
                }
                // Aqui estamos desabilitando a data do dia seguinte
                if(item.equals(LocalDate.now().plusDays(1))) {
                    setDisable(true);
                }
            }
        };
    }
});

It looks like this after running:

UsingthislogicyoucanimplementaclasscalledEvent,withaLocalDateandadescriptionasattributes,andgothroughanarrayofeventsinsidethefactorybypaintingthemaccordingly.

AsforthePopUpissueyoucanusethe setTooltip that this component inherits from the Control class (The tooltip is half bugged). Or you can use ControlsFX's PopOver , a well-known library of custom components for JavaFX.

    
13.09.2018 / 20:33