Questions tagged [jpopupmenu]

JPopupMenu is the Java Swing implementation of a popup menu, a small window that pops up and displays a series of choices. A JPopupMenu is used for the menu that appears when the user selects an item on the menu bar. It is also used for "pull-right" menu that appears when the selects a menu item that activates it. Finally, a JPopupMenu can also be used anywhere else you want a menu to appear.

JPopupMenu is the Java Swing implementation of a popup menu, a small window that pops up and displays a series of choices. A JPopupMenu is used for the menu that appears when the user selects an item on the menu bar. It is also used for "pull-right" menu that appears when the selects a menu item that activates it. Finally, a JPopupMenu can also be used anywhere else you want a menu to appear.

For information and examples of using popup menus, see How to Use Menus in The Java Tutorial.

247 questions
114
votes
5 answers

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

I'm currently creating a right-click context menu by instantiating a new JMenu on right click and setting its location to that of the mouse's position... Is there a better way?
Wayne
  • 4,024
  • 4
  • 19
  • 11
35
votes
6 answers

How to create a JButton with a menu?

I want to create a Toolbar in my application. If you click a button on that toolbar, it will pop up a menu, just like in Eclipse's toolbar. I don't know how to do this in Swing. Can someone help me please? I've tried Google but found nothing.
Kien Truong
  • 10,686
  • 2
  • 26
  • 34
16
votes
7 answers

Adding vertical scroll to a JPopupMenu?

I would like to add a way to scroll through menu items in a JPopupMenu, much like scrolling through a list of items in a JComboBox. Let's say I have 10 menu items. I would like to display only 5 menu items at a time, and I would use a vertical…
BJ Dela Cruz
  • 4,826
  • 10
  • 42
  • 80
16
votes
3 answers

Swing and Nimbus: Replace background of JPopupMenu (attached to JMenu)

Nimbus often looks great, but for certain color combinations the result is non-optimal. In my case, the background of a JPopupMenu does not fit, which is why I want to set it manually. I'm on Java 7 and, interestingly, Nimbus fully ignores the…
aRestless
  • 1,685
  • 2
  • 16
  • 27
15
votes
4 answers

Adding JPopupMenu to the TrayIcon

I want to add JPopupMenu to the task bar as a TrayIcon (i.e systemTray.add(trayIcon)) but I haven't found a way to do so.From the docs the constructor of TrayIcon looks like : public TrayIcon(Image image, String tooltip, …
saplingPro
  • 18,513
  • 51
  • 134
  • 185
12
votes
5 answers

Open popup(Menu) on task tray icon with left click using java

I am working on task tray Icon in java, I like to open a popup Menu using left click same popup Menu as I open on right click, and please help me with a quick response. Thanks in advance... here is the code working for right click need to show same…
NoNaMe
  • 5,410
  • 30
  • 73
  • 98
11
votes
3 answers

Stopping JPopupMenu stealing the focus

I have a JTextField for which I'm hoping to suggest results to match the user's input. I'm displaying these suggestions in a JList contained within a JPopupMenu. However, when opening the popup menu programmatically via show(Component invoker, int…
Isaac
  • 1,547
  • 2
  • 13
  • 21
10
votes
2 answers

JTable with JPopupMenu

how can I prevent triggering and showing JPopupMenu only if is Mouse Cursor over selected JTable'Row my question: if is there another way as getBounds from selected row and determine/compare that with Mouse position... my simple sscce demonstrated…
mKorbel
  • 108,320
  • 17
  • 126
  • 296
10
votes
2 answers

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…
Joonas Pulakka
  • 34,943
  • 25
  • 103
  • 165
9
votes
1 answer

Why does a small JPopupMenu cause visual artifacts whereas a larger one doesn't?

I'm using a single row JTabel with a MouseAdapter attached to it. The table model is populated with some random values. Upon right-clicking the table a JPopupMenu with several JMenuItems will appear. Visual artifacts start showing if part of the…
Emiel
  • 195
  • 9
8
votes
3 answers

How To Create a Pop Up Menu with Sub Menu in Java

I would like to add right click menu for my program. I added basit menu with the following code: Pmenu = new JPopupMenu("Menu"); menuItem = new JMenuItem("Sections"); Pmenu.add(menuItem); menuItem =…
CanCeylan
  • 2,550
  • 8
  • 32
  • 48
8
votes
6 answers

Create an inspecting properties window, button driven as a JDialog

What I asked originally didn't clearly state my question/problem, so I will explain it better. I have a JButton that sets a JDialog to visible. The JDialog has a WindowListener that sets it to NOT visible on the windowDeactivated() event, which is…
Brian
  • 81
  • 3
8
votes
7 answers

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

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…
Joanis
  • 1,659
  • 3
  • 18
  • 32
7
votes
3 answers

How to get the component that invoked a JPopupMenu?

I have a JPopUpMenu that I added to multiple JTables and I would like to get the specific table that's right clicked so I can make changes to it. How can I get the component that triggers the JPopupMenu in the Action Listener? JPopupMenu popupMenu =…
Igor
  • 1,414
  • 4
  • 21
  • 43
6
votes
2 answers

JPopupMenu display under Canvas

I have a Canvas, some text fields and a context menu. When I start the application and right click on the canvas a popup menu shows. But when I write something inside the text field than I right click on the canvas, the popup will shows behind the…
Guillaume Massé
  • 7,057
  • 6
  • 37
  • 54
1
2 3
16 17