javafx2中的Menuitem工具提示 [英] Menuitem tooltip in javafx2
本文介绍了javafx2中的Menuitem工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
javafx2中有两个问题.
There are two questions in javafx2..
- 如何为菜单项设置工具提示
- 如何设置菜单项的大小(宽度)
请告诉我您的答案.
推荐答案
The answer to both questions direct to the class CustomMenuItem, which wraps an arbitrary Node and puts it into a menu. For example, the following creates a rectangle within a menu with a certain width, height and ToolTip:
public void start(final Stage stage) throws Exception {
Group root = new Group();
final Menu menu1 = new Menu("File");
MenuBar menuBar = new MenuBar();
menuBar.getMenus().add(menu1);
MenuItem menu12 = new MenuItem("Open");
menu1.getItems().add(menu12);
Rectangle rect = new Rectangle();
rect.setHeight(100);
rect.setWidth(100);
Tooltip t = new Tooltip("A Rectangle ToolTip");
Tooltip.install(rect, t);
CustomMenuItem customMenuItem = new CustomMenuItem(rect);
customMenuItem.setHideOnClick(false);
menu1.getItems().add(customMenuItem);
root.getChildren().add(menuBar);
Scene scene = new Scene(root,800,600);
stage.setScene(scene);
stage.show();
}
这篇关于javafx2中的Menuitem工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文