You mean maybe like a JPopupMenu? I think you should go off and read a Swing tutorial before you start asking random questions like this one -- that's assuming you are asking about GUI applications. After you do that you may well find that your questions have been answered. Right now you are just asking from a position of total ignorance, and that doesn't lead to good questions.
Here is a simple demonstration of a JPopupMenu with Shortcut Accelerators:
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.KeyEvent;
import java.awt.Event;
class Test extends JFrame {
private JLabel label;
private JPopupMenu jpm;
private JMenuItem changeTextItem;
private JMenuItem resetTextItem;
public Test() {
initComponents();
}
private void initComponents() {
label = new JLabel("Right-click on me, and select Change Text (or press CTRL+G)");
label.setSize(400, 20);
label.setLocation(5, 5);
jpm = new JPopupMenu();
changeTextItem = new JMenuItem("Change Text");
changeTextItem.setMnemonic((int)'C');
changeTextItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, Event.CTRL_MASK));
resetTextItem = new JMenuItem("Reset Text");
resetTextItem.setMnemonic((int)'R');
resetTextItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.CTRL_MASK));
label.add(jpm);
jpm.add(changeTextItem);
jpm.add(resetTextItem);
this.getContentPane().setLayout(null);
this.getContentPane().add(label);
this.pack();
this.setSize(500, 300);
this.setLocationRelativeTo(null);
this.setTitle("Test Application");
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
label.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
if( evt.getButton() == MouseEvent.BUTTON3 )
jpm.show(label, evt.getX(), evt.getY());
}
});
changeTextItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
label.setText("You clicked on the menu-item!");
}
});
resetTextItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
label.setText("Right-click on me, and select Change Text (or press CTRL+G)");
}
});
}
public static void main(String[] argv) { new Test().setVisible(true); }
}