Stack Exchange
Designing a phonebook menu bar, filter and sorting order buttons included
I designed a phonebook application using JavaFX (trying to follow Material Design by Google, as you can see in the screenshot).
The code below is the code that handles the ButtonBar next to the search bar, but I'm new to JavaFX and I want to know if this is really poorly written and organized.
package gui;

import data.Contact;
import data.Database;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.ObservableList;
import javafx.scene.control.MenuButton;
import javafx.scene.control.RadioMenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.ToggleGroup;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import model.ContactListOrderManager;
import model.ListOrder;

import java.io.FileInputStream;
import java.io.IOException;

public class ListButtonsController {
    private final SimpleObjectProperty<MenuButton> orderButton;
    private final SimpleObjectProperty<MenuButton> filterButton;
    private final SimpleObjectProperty<OrderButtonController> orderButtonController;
    private final SimpleObjectProperty<ObservableList<Contact>> contactList;

    public ListButtonsController(MenuButton orderButton, MenuButton filterButton,
                                 ObservableList<Contact> contactList) {
        this.orderButton = new SimpleObjectProperty<>(orderButton);
        this.filterButton = new SimpleObjectProperty<>(filterButton);
        var orderButtonControl = new OrderButtonController(this);
        this.orderButtonController = new SimpleObjectProperty<>(orderButtonControl);
        this.contactList = new SimpleObjectProperty<>(contactList);
    }

    protected MenuButton getOrderButton() {
        return orderButton.get();
    }

    protected MenuButton getFilterButton() {
        return filterButton.get();
    }

    private OrderButtonController getOrderButtonController() {
        return orderButtonController.get();
    }

    public ObservableList<Contact> getContactList() {
        return contactList.get();
    }

    public void listButtonsSetup() throws IOException {
        getOrderButtonController().orderButtonSetup();
        setButtonsStyle();
        setButtonsIcons();
        AnchorPane.setLeftAnchor(getOrderButton(), 290d);
        AnchorPane.setTopAnchor(getOrderButton(), 1.5);
        AnchorPane.setLeftAnchor(getFilterButton(), 240d);
        AnchorPane.setTopAnchor(getFilterButton(), 1.5);
    }

    private void setButtonsIcons() throws IOException {
        try (var filterInput = new FileInputStream("icons/filter_black_24dp.png");
             var orderInput = new FileInputStream("icons/sort_black_24dp.png")) {
            getOrderButton().setGraphic(new ImageView(new Image(orderInput)));
            getFilterButton().setGraphic(new ImageView(new Image(filterInput)));
        }
    }

    private void setButtonsStyle() {
        getOrderButton().getStylesheets().add("file:stylesheets/menu-button.css");
        getOrderButton().getStyleClass().add("menu-button");
        getFilterButton().getStylesheets().add("file:stylesheets/menu-button.css");
        getFilterButton().getStyleClass().add("menu-button");
    }

}

class OrderButtonController {
    private final ListButtonsController generalController;
    private final MenuButton orderButton;

    protected OrderButtonController(ListButtonsController controller) {
        this.generalController = controller;
        this.orderButton = generalController.getOrderButton();
    }

    protected void orderButtonSetup() {
        var ordinatorGroup = new ToggleGroup();
        var alphabeticalOrderItem = new RadioMenuItem("Alphabetically");
        alphabeticalOrderItem.setSelected(true);
        ordinatorGroup.getToggles().add(alphabeticalOrderItem);
        var separator = new SeparatorMenuItem();
        var orderGroup = new ToggleGroup();
        var ascendingRadioItem = new RadioMenuItem("Ascending");
        ascendingRadioItem.setSelected(true);
        var descendingRadioItem = new RadioMenuItem("Descending");
        orderGroup.getToggles().addAll(ascendingRadioItem, descendingRadioItem);

        descendingRadioItem.setOnAction(actionEvent ->
                ContactListOrderManager.sortList(generalController.getContactList(),
                        ListOrder.getOrdering((RadioMenuItem) orderGroup.getSelectedToggle()),
                        descendingRadioItem.isSelected()));
        ascendingRadioItem.setOnAction(actionEvent ->
                ContactListOrderManager.sortList(generalController.getContactList(),
                        ListOrder.getOrdering((RadioMenuItem) orderGroup.getSelectedToggle()),
                        descendingRadioItem.isSelected()));
        alphabeticalOrderItem.setOnAction(actionEvent ->
                ContactListOrderManager.sortList(generalController.getContactList(),
                        ListOrder.ALPHABETIC, descendingRadioItem.isSelected()));

        setMenusStyle(alphabeticalOrderItem, ascendingRadioItem, descendingRadioItem);
        orderButton.getItems().addAll(alphabeticalOrderItem, separator, ascendingRadioItem, descendingRadioItem);
    }

    private void setMenusStyle(RadioMenuItem... menus) {
        for (RadioMenuItem menu : menus) {
            menu.getStyleClass().add("order-menu");
        }
    }
}



Where is the FXML file? Are you trying to create a custom node? Either way, I am not sure SimpleObjectProperty<MenuButton> orderButton using ObjectProperty in this manner is good. It should be MenuButton orderButton. I don't know if I truly understand what you are doing here and why.
