1. ToolBar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Orientation; import javafx.scene.control.Button; import javafx.scene.control.ContentDisplay; import javafx.scene.control.Separator; import javafx.scene.control.ToolBar; import javafx.scene.control.Tooltip; import javafx.scene.image.Image; import javafx.scene.image.ImageView; public class FxToolBar { ToolBar toolBar; public FxToolBar() { toolBar = new ToolBar(); } public ToolBar getToolBar() { return toolBar; } public void addToolBarItem(String title, String iconFile, String toolTip, Runnable runnable) { Button item = new Button(title); if( iconFile != null ) { Image image = new Image(getClass().getResourceAsStream(iconFile)); item.setGraphic(new ImageView(image)); } if( toolTip != null ) { item.setTooltip(new Tooltip(toolTip)); } item.setContentDisplay(ContentDisplay.TOP); item.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { runnable.run(); } }); toolBar.getItems().add(item); } public void addToolBarItem(String iconFile, String toolTip, Runnable runnable) { addToolBarItem(null,iconFile,toolTip,runnable); } public void addToolBarItem(String iconFile, Runnable runnable) { addToolBarItem(null,iconFile,null,runnable); } public void addTextToolBarItem(String title, String toolTip, Runnable runnable) { addToolBarItem(title,null,toolTip,runnable); } public void addTextToolBarItem(String title, Runnable runnable) { addToolBarItem(title,null,null,runnable); } public void addSeparator() { Separator separator = new Separator(); separator.setOrientation(Orientation.VERTICAL); toolBar.getItems().add(separator); } } |
댓글 없음:
댓글 쓰기