Java Reference
In-Depth Information
leftAlignButton.setId("leftAlignButton");
leftAlignButton.setToggleGroup(alignToggleGroup);
ToggleButton centerAlignButton = new ToggleButton();
centerAlignButton.setGraphic(new Circle(8, Color.ORANGE));
centerAlignButton.setId("centerAlignButton");
centerAlignButton.setToggleGroup(alignToggleGroup);
ToggleButton rightAlignButton = new ToggleButton();
rightAlignButton.setGraphic(new Circle(8, Color.CYAN));
rightAlignButton.setId("rightAlignButton");
rightAlignButton.setToggleGroup(alignToggleGroup);
ToolBar toolBar = new ToolBar(
newButton,
editButton,
deleteButton,
new Separator(Orientation.VERTICAL),
boldButton,
italicButton,
new Separator(Orientation.VERTICAL),
leftAlignButton,
centerAlignButton,
rightAlignButton
);
alignToggleGroup.selectToggle(alignToggleGroup.getToggles().get(0));
alignToggleGroup.selectedToggleProperty().addListener((ov, oldValue, newValue) -> {
ToggleButton tb = ((ToggleButton) alignToggleGroup.getSelectedToggle());
if (tb != null) {
System.out.println(tb.getId() + " selected");
}
});
return toolBar;
}
Defining Graphical Buttons
As shown in Figure 6-1 , toolbar buttons often have a graphic rather than a title. They also often have a tooltip that pops
up when the mouse cursor hovers over the button, as demonstrated in Step 4 of the exercise. In the following snippet
from Listing 6-4, the toolbar button that causes a New Document to be created is defined with a graphic and tooltip, as
well as an action to be performed when the toolbar button is selected:
Button newButton = new Button();
newButton.setGraphic(new ImageView(new Image(getClass().getResourceAsStream
("images/paper.png"))));
newButton.setId("newButton");
newButton.setTooltip(new Tooltip("New Document... Ctrl+N"));
newButton.setOnAction(e -> System.out.println("New toolbar button clicked"));
 
Search WWH ::




Custom Search