jpopupmenu

Find the JTable row on which a popup menu has been invoked

南笙酒味 提交于 2019-12-01 05:44:53
I have a JTable and a popup menu that is specific to each row. I want to calculate the row on which the user right-clicked his mouse (Windows L&F) to bring up the popup menu. I create a MouseListener for the table, so it gets the MouseEvent at the click, and shows the popup menu at the correct place. But when the user selects one item off the popup menu, I can't figure a way to determine what the row was where the user right-clicked in the first place. The event for the popup menu invocation doesn't have the x,y coordinates where the right-click took place any more. I've looked at getting the

Find the JTable row on which a popup menu has been invoked

▼魔方 西西 提交于 2019-12-01 02:44:13
问题 I have a JTable and a popup menu that is specific to each row. I want to calculate the row on which the user right-clicked his mouse (Windows L&F) to bring up the popup menu. I create a MouseListener for the table, so it gets the MouseEvent at the click, and shows the popup menu at the correct place. But when the user selects one item off the popup menu, I can't figure a way to determine what the row was where the user right-clicked in the first place. The event for the popup menu invocation

Adding JPopupMenu to the TrayIcon

醉酒当歌 提交于 2019-11-30 11:32:06
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, PopupMenu popup) Is there any way I can do this ? This is a known problem. There is a bug report , which contains the outline of a workaround. I've adapted that below: // Build your popup menu final JPopupMenu trayPopup = new JPopupMenu(); // I'm using actions, there are other ways of doing this. trayPopup.add(someFantaticAction); // Get your tray icon trayIcon = new

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

a 夏天 提交于 2019-11-30 11:27:55
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 setting of some properties in the UIManager (like PopupMenu.background ). So my only option was to create a subclass of JPopupMenu that overrides paintComponent(...) . I know, that's nasty, but at least it worked. However, if you add a JMenu to another menu, it embeds it's own instance of JPopupMenu and I could not figure out how to replace it with my

How to create a JButton with a menu?

萝らか妹 提交于 2019-11-30 07:54:18
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. This is way harder in Swing than it needs to be. So instead of pointing you to tutorials I've created a fully working example. import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public class ToolbarDemo { public static void main(String[] args) { final JFrame

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

喜夏-厌秋 提交于 2019-11-29 17:04:32
问题 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 setting of some properties in the UIManager (like PopupMenu.background ). So my only option was to create a subclass of JPopupMenu that overrides paintComponent(...) . I know, that's nasty, but at least it worked. However, if you add a JMenu to another

How to create a JButton with a menu?

血红的双手。 提交于 2019-11-29 11:16:37
问题 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. 回答1: This is way harder in Swing than it needs to be. So instead of pointing you to tutorials I've created a fully working example. import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.MouseAdapter; import

Adding vertical scroll to a JPopupMenu?

最后都变了- 提交于 2019-11-29 06:49:16
问题 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 scroll button at the bottom or top of the JPopupMenu to show the menu items that are not listed and hide the ones that I just saw. Is it possible? I am using JIDE Software's JideSplitButton , which displays a JPopupMenu when clicked. I am trying to

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

痴心易碎 提交于 2019-11-28 13:20:35
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 popup on left click... don't forget to place any image @ "src/img" folder with name "titleImg.jpg" Just run this... it is a working example but i have to show same popup using left click i have checked the Mouse Listener, it listen the left click on tray icon but how to show popup menu using that ??? package com.abc.dao; import java.awt.AWTException

JTable copy and paste using Clipboard and AbstractAction

我与影子孤独终老i 提交于 2019-11-28 12:42:00
When I try to paste into a JTable cell using table.setValueAt() , the cell I am pasting in remains blank, but setValueAt() seems to be working. Also, when I try to cut or copy from one cell, the Paste option on my JPopupMenu remains disabled when I want to paste into another cell. I'm not sure why. My code is below. class CopyAction extends AbstractAction { private JTable table; public CopyAction(JTable table) { this.table = table; } @Override public void actionPerformed(ActionEvent e) { int row = table.getSelectedRow(); int col = table.getSelectedColumn(); Clipboard cb = Toolkit