SplitMenuButton 만들기

Very similar to the MenuButton, the SplitMenuButton pops up a ContextMenu when the down arrow is clicked. In addition, when the main part of the SplitMenuButton is clicked, the behavior is that of a Button. Both of these behaviors are demonstrated in Steps 22 and 23 of the previous exercise when interacting with the SplitMenuButton shown in Figure 6-9. The following snippet from Listing 6-12 realizes these behaviors:

MenuItem splitMenuA = new MenuItem("MenuItem A");
splitMenuA.setOnAction(e -> System.out.println(e.getEventType()
        + " occurred on Menu Item A"));
MenuItem splitMenuB = new MenuItem("MenuItem B");
SplitMenuButton splitMenuButton = new SplitMenuButton(splitMenuA, splitMenuB);
splitMenuButton.setText("SplitMenuButton");
splitMenuButton.setOnAction(e -> System.out.println(e.getEventType()
        + " occurred on SplitMenuButton"));

Let’s move away from the button-like UI controls and turn our attention to some UI controls that accept text input, starting with the TextField.