I'm developing a popup menu for cut, copy and paste in a JTextArea. The cut and copy menu items will be enabled only when some text in the JTextArea is selected. Similarly, the paste menuitem will be enabled only if there is something to paste from the clipboard.
To implement this functionality, I used a PopupMenuListener which will listen to whether the popupmenu has been invoked or not. If it has been invoked, I immediately need to ascertain the dot and mark position of the text caret so as to determine whether any text has been selected or not. Thus, I kind of need to use two listeners simultaneously. I tried nesting CaretListener within PopupMenuListener but to no avail.
How can one, at the same time, listen to Popupmenu invocation as well as the text caret positioning so as to eventually determine whether the cut or copy menuitem should be enabled or disabled? Thanks.