articles.zip
at the same level as the output directory. This file contains the Help content generated with the content of our wiki.articles resources -- articles.xml -- index.html -- README.txtThe
articles.xml
contains the names and the paths of all the articles of the wiki, which will be used by the Help System.
public class JFXJavaHelp extends Application { @Override public void start(Stage primaryStage) { BorderPane root = createLayout(primaryStage); Scene scene = new Scene(root, 400, 400); primaryStage.setTitle("DocGenerator Help Tutorial"); primaryStage.setScene(scene); primaryStage.show(); } private void createContent(BorderPane root) { TextArea area = new TextArea(); area.setStyle("-fx-background-color: null;"); Insets insets = new Insets(10, 10, 10, 10); area.setPadding(insets); area.setText("my area content"); root.setCenter(area); } private void createMenu(VBox top) { MenuBar menuBar = new MenuBar(); top.getChildren().add(menuBar); Menu menu = new Menu("Help"); menuBar.getMenus().add(menu); MenuItem item = new MenuItem("Help Content"); menu.getItems().add(item); item.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { } }); } private BorderPane createLayout(Stage stage) { BorderPane root = new BorderPane(); VBox top = new VBox(); root.setTop(top); createContent(root); createMenu(top); return root; } public static void main(String[] args) { launch(args); } }
articles.zip
alongside our application. First we need to initialize our Help factory:@Override public void start(Stage primaryStage) { createFactory(); BorderPane root = createLayout(primaryStage); Scene scene = new Scene(root, 400, 400); primaryStage.setTitle("DocGenerator Help Tutorial"); primaryStage.setScene(scene); primaryStage.show(); }
private void createFactory() { URL url = this.getClass().getResource("resources/articles.zip"); factory = new JavaHelpFactory(url); try { factory.create(); } catch (IOException | SAXException ex) { ex.printStackTrace(); } }Now we will create a
JFXHelpContentViewer
, install the Help content on this viewer, and create our HelpWindow:private BorderPane createLayout(Stage stage) { BorderPane root = new BorderPane(); VBox top = new VBox(); root.setTop(top); try { viewer = new JFXHelpContentViewer(); factory.install(viewer); viewer.getHelpWindow(stage, "Help Content", 600, 700); } catch (IOException ex) { ex.printStackTrace(); } createContent(root); createMenu(top); return root; }The last step is to wire our help item to the help content:
private void createMenu(VBox top) { MenuBar menuBar = new MenuBar(); top.getChildren().add(menuBar); Menu menu = new Menu("Help"); menuBar.getMenus().add(menu); MenuItem item = new MenuItem("Help Content"); menu.getItems().add(item); item.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { viewer.showHelpDialog(menu.getGraphic()); } }); }See the full source code for the example
JavaHelpFactory
:
JavaHelpFactory factory = new JavaHelpFactory(url); factory.create();
JFXHelpContentViewer
and install the model on this viewer:
JFXHelpContentViewer viewer = new JFXHelpContentViewer(); factory.installModel(viewer);
viewer.getHelpWindow(stage, "Help Content", 600, 700)
but we did not need in this case to use this Window directly. It is performed by the viewer.showHelpDialog(menu.getGraphic())
code. We could have use the Help window or directly get the Help component by viewer.getHelpComponent()
docJGenerator Copyright (c) 2016-2023 Herve Girod. All rights reserved.