我在菜单栏中有一个顶级菜单,如下所示:收入费用用户。我试图将用户放在菜单栏的最右边,但没有成功我使用了边框窗格。有没有办法把前两个菜单放在左边,第三个菜单浮到右边?
收入费用用户
public class Budget extends Application {
Stage window;
BorderPane layout;
@Override
public void start(Stage primaryStage) {
window = primaryStage;
window.setTitle("First stage");
Menu income = new Menu("Income");
Menu expense = new Menu("Expense");
Menu users = new Menu ("Users");
MenuItem addIncome = new MenuItem("Add Income..");
income.getItems().add(addIncome);
income.getItems().add(new MenuItem("List All Incomes"));
expense.getItems().add(new MenuItem("Add Expense..."));
expense.getItems().add(new MenuItem("List All Expenses"));
users.getItems().add(new MenuItem("Switch User"));
users.getItems().add(new MenuItem("Log In"));
users.getItems().add(new MenuItem("Log Off"));
MenuBar menuBar = new MenuBar();
menuBar.getMenus().addAll(income, expense, users);
layout = new BorderPane();
layout.setTop(menuBar);
Scene scene = new Scene(layout, 600, 400);
//Scene scene = new Scene(grid, 600, 400);
window.setScene(scene);
window.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
答案 0 :(得分:0)
使用2个不同的菜单栏,然后将它们放入HBox
。左边的菜单栏将包含“收入”和“费用”,而右边的菜单栏将包含“用户”。使用HBox的对齐选项。