Posts

Showing posts with the label menu

How to make any imagebutton a menu button

How to make any imagebutton a menu button I have an imageButton in a xml file. Now want to make it a menu button, so that when a user click on the button it should show the drop down menus. But I am not able to figure out what are the possible solution(s). Can anyone help? 2 Answers 2 If you're trying to show a drop down menu when clicking an ImageButton (or any other View ), try this: final ImageButton imageButton = // get your ImageButton from the XML here final PopupMenu dropDownMenu = new PopupMenu(getContext(), imageButton); final Menu menu = dropDownMenu.getMenu(); // add your items: menu.add(0, 0, 0, "An item"); menu.add(0, 1, 0, "Another item"); // OR inflate your menu from an XML: dropDownMenu.getMenuInflater().inflate(R.menu.some_menu, menu); dropDownMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuIte...

java.lang.IllegalArgumentException: Children: duplicate children added: parent = VBox@872be7

java.lang.IllegalArgumentException: Children: duplicate children added: parent = VBox@872be7 Am trying to read some values from MySQL database and display it in a Menu in JavaFX. My code is below. Previously I used Buttons instead of Menu. It worked fine, but I don't felt better with Buttons, so I decided to use Menu. I got the exception mentioned in the heading when I Ran this code. private VBox userSelection() throws ClassNotFoundException, SQLException { VBox vb1 = new VBox(); vb1.setPadding(new Insets(40, 150, 20, 200)); vb1.setSpacing(20); MenuBar menuBar = new MenuBar(); Menu menuFile1 = new Menu("CHOOSE YOUR ACCOUNT"); menuFile1.setStyle("-fx-border-color: green; -fx-font-size: 14pt; " + "-fx-font-family: Comic Sans MS; -fx-padding: 1 10 1 1"); Text scenetitle2 = new Text("Choose Your Account"); scenetitle2.setFont(Font.font("Tahoma", FontWeight.BOLD, 20)); scenetitle2.setUnderl...