How to put a user button with drop-down options in Java

1

I am doing a system in NetBeans in which you have users and in the main screen I want to put a button where the user's image is and when pressing it, a menu containing the option to close session is displayed. Thanks in advance

    
asked by Cristopher 05.08.2017 в 22:09
source

2 answers

1

I have a similar solution, but with a JLabel instead of a button.

You can do it with the Swing control Popup Menu in the category of Swing Menus of the palette, Drag it and put it in your form it will be added in the category of Other components Right click and place your pointer in Add From palette and select Menu item select that menu item and in the properties tab, find the property label and write what do you want that option to say, then to the Menu item that you added, right click > > events > > Action > > actionPerformed. there you will write your code to close session.

to make it appear by right clicking on the label you will do the following: right click on the label > > events > > mouse > > mouseReleased. there you will write this code:

if(evt.isPopupTrigger())
{
     TuPopupMenu.show(evt.getComponent(),evt.getX(),evt.getY());
}

will look like this:

and voila, you already have the menu when you right click on the user's photo. I hope it was helpful:)

    
answered by 05.08.2017 / 23:55
source
0

What you want to do is quite simple, if you are using Swing, you can use a ComboBox, which is a drop-down menu. Here is the documentation of it.

Leela, and if you have any doubt, do not hesitate to ask.

    
answered by 05.08.2017 в 22:31