时候输入账号那样子,可以有个下拉列表选择以往登录过的账号,那就选择ContextMenu
测试代码
package testmenu;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class TestMenu extends Application {
@Override
public void start(Stage stage) {
MenuBar bar = new MenuBar();
//创建菜单1,2,3,4
Menu menu1 = new Menu("文件");
Menu menu2 = new Menu("哈哈");
Menu menu3 = new Menu("信息");
Menu menu4 = new Menu("帮助");
bar.getMenus().addAll(menu1,menu2,menu3,menu4);//将menu1,2,3,4添加到MenuBar中
BorderPane Bpane = new BorderPane();
Bpane.setTop(bar);
Scene scene = new Scene(Bpane);
stage.setScene(scene);
stage.setHeight(225);
stage.setWidth(255);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}