jpopupmenu

How do I create a right click context menu in Java Swing?

I'm working on a school project and we want to implement a right click pop-up menu in the gui. Currently we are doing something like creating a JMenu on right click and setting its location to that of the mouse's position... This seems really ugly and is very buggy, is there any better way of doing this? I'm sure there must be. ...

JPopupMenu Behavior

I prepared a small test case below. My problem is when i right click on the window. JPopupMenu show up but if i click anywhere outside the JWindow menu does not disappear. I have to click somewhere on the window to get rid of it which is not the expected behavior. EDIT: after reading akf's answer i switched to JFrame, when frame is in f...

How to animate showing of JPopupMenu?

I'd like to show increasingly more of a JPopupMenu so it appears to "slide out". It's not for menu items, where animation doesn't make too much sense. Instead it's for a panel with some real components (oh yeah, you can add any JComponent to JPopupMenu). JPopupMenu has many private fields and methods, which makes it hard to extend. Plus...

How to create a JButton with a menu ?

I want to create a Toolbar for my application. If you click a button on that toolbar , it will pop-up a menu , just like the toolbar of eclipse. I don't know how to do it in Swing. Can someone help me please ? I've try google but found nothing. ...

Show/Hide JMenuItems in a JPopupMenu based on a JTree's selection.

I have a JTree which displays a JPopupMenu when I right click nodes in the JTree. What is the best way to hide/show or enable/disable certain JMenuItems in my JPopupMenu based on the node selected in the JTree? The first solution that came to mind was to add a TreeSelectionListener to the JTree for the 'value changed' event. In the even...

Showing/hiding a JPopupMenu from a JButton; FocusListener not working?

Hi everyone, I needed a JButton with an attached dropdown style menu. So I took a JPopupMenu and attached it to the JButton in the way you can see in the code below. What it needs to do is this: show the popup when clicked hide it if clicked a second time hide it if an item is selected in the popup hide it if the user clicks somewher...

How to make JPopupMenu not take focus/mouse cursor?

Hello, I show() a JPopupMenu based on what the user types in a JTextField, however, when that happens the user typing on the keyboard will no longer write into the text field, unless with the mouse clicks again on the field, thus closing the popup menu. I want, like in Eclipse and NetBeans code completion feature, that the user may sti...

JPopupMenu should not lose focus

Hello everyone, Question about JPopupMenu behavior. I would like the JPopupMenu not to loose focus when it comes up. Also when JPopupMenu is in focus, the user should be able to click/update other parts of the Applet. Is this possible? Reason is that this JPopupMenu is displaying some codes and it needs to be kept open for reference....

Why isn't componentHidden called for my JPopupMenu?

I want to be notified when my JPopupMenu is hidden — whether because an item was selected, the menu was dismissed, or setVisible(false) was called on it. Here is my test code: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class A extends ComponentAdapter implements Runnable, ActionListener { private JBut...

JTabbedPane tabs

Alright, so I have a JTabbedPane in an application and it has several panels. Is it possible to assign a JPopupMenu to the actual tabs themselves instead of the JPanel? If it is possible, how would I do this? ...

Problem with JPopupMenu in a JTree

Hi guys I have this issue. In a custom JTree I implemented a JPopupMenu to display different JMenuItem according to the node selected using a MouseListener. The JPopupMenu is shown when the mouse right button is clicked. The problem is that if I don’t choose an Item from the PopupMenu but instead I select another node in the tree, eithe...

How to prevent JPopUpMenu disappearing when checking checkboxes in it?

I want to use JCheckBoxMenuItems in a JPopupMenu. It works, but the problem is that the popup menu disappears when a checkbox item has been checked or unchecked. So if one wants to check/uncheck several items, the popup needs to be launched repeatedly, which is irritating. Curiously, if I use just plain JCheckBox items in the menu (inst...

How to enable ESC-Close for an JPopupMenu, if the underlying window closes on ESC?

Imagine two common situations combined: A JDialog(or JFrame) which closes on VK_ESCAPE (set as key binding on the root pane) and an inner JPopupMenu which is supposed to close on ESC as well. The problem is: pressing escape always closes the dialog - event if the popup is visible. Apparently the popup doesn't even receive the key event s...

Java: Show JPopupMenu without passing an invoker component.

Hi, When I let popup a JPopupMenu without passing the "invoker component", the menu doesn't work: submenu's don't open and isn't getting repainted. But when I create a completely useless JFrame with a JLabel inside, and I pass the JLabal as invoker, it works correctly... Any suggestions, how to avoid creating a useless frame. And my ap...

How do I make a JPopupMenu appear when a JCheckBox is clicked?

I have a JCheckBox in a program (labeled "Use MiniTimer") that, when right-clicked, shows a JPopupMenu with options "Show on Close", "Show on Minimize", "Show on Close or Minimize", and "Do not use MiniTimer". How can I make this JPopupMnu appear below the JCheckBox when it is left-clicked, too? Note that I tried setting the actionPerf...

JPopupMenu bug/glitch(?) when showing submenu

Hi, I have this strange bug with my popup menu. It happens rarely and seemingly randomly. The problem is when I have a submenu in my JPopupMenu - when I select the submenu, main menu disappears and the submenu is painted incorrectly (it's like the buffer of main menu is painted over the submenu). I can still navigate it using keyboard. ...