Skip to content

Instantly share code, notes, and snippets.

@seraphy
Created April 12, 2019 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seraphy/aa378db051adc82a5fda37bf835859ce to your computer and use it in GitHub Desktop.
Save seraphy/aa378db051adc82a5fda37bf835859ce to your computer and use it in GitHub Desktop.
JavaFXのMenuBarのダンプ
private void dump(MenuBar menuBar) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
pw.println("<MenuBar>");
pw.println(" <menus>");
for (Menu menu : menuBar.getMenus()) {
dump(menu, pw, " ");
}
pw.println(" </menus>");
pw.println("</MenuBar>");
System.out.println(sw.toString());
}
private void dump(MenuItem menu, PrintWriter pw, String indent) {
String className = menu.getClass().getSimpleName();
pw.print(indent + "<" + className + " ");
pw.print("text=\"" + menu.getText() + "\"");
if (menu instanceof Menu) {
pw.println(">");
pw.println(indent + " <items>");
for (MenuItem item : ((Menu) menu).getItems()) {
dump(item, pw, indent + " ");
}
pw.println(indent + " </items>");
pw.println(indent + "</" + className +">");
} else {
pw.println("/>");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment