Can you show us some snippets of (relevant) code please?
kind regards,
Jos
// Copyright (c) 2007 Ericsson AB. All rights reserved.
package testpackage;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.List;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JTextArea;
public class CTestClass implements ActionListener
{
private JFrame frame;
private JTextArea area;
private JLabel label;
private List wordList;
public static JPopupMenu popup;
public CTestClass()
{
frame = new JFrame("popup menu");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.getContentPane().setLayout(new GridLayout(3, 1));
area = new JTextArea();
label = new JLabel("Sample");
wordList = new List();
popup = new JPopupMenu();
JMenuItem menuItem = new JMenuItem("A popup menu item");
menuItem.addActionListener(this);
popup.add(menuItem);
menuItem = new JMenuItem("Another popup menu item");
menuItem.addActionListener(this);
popup.add(menuItem);
// Add listener to components that can bring up popup menus.
MouseListener popupListener = new PopupListener();
area.addMouseListener(popupListener);
wordList.addMouseListener(popupListener);
frame.getContentPane().add(area);
frame.getContentPane().add(label);
System.out.print(popup.getForeground());
frame.getContentPane().add(wordList);
frame.setSize(400, 300);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
}
public static void main(String[] args)
{
new CTestClass();
}
}
class PopupListener extends MouseAdapter
{
public void mousePressed(MouseEvent e)
{
maybeShowPopup(e);
}
public void mouseReleased(MouseEvent e)
{
maybeShowPopup(e);
}
private void maybeShowPopup(MouseEvent e)
{
if (e.isPopupTrigger())
{
CTestClass.popup.show(e.getComponent(), e.getX(), e.getY());
}
}
}
If you run this program in any editor like eclipse
It will create frame in which there are 3 rows and 1 column
0,0 -> TEXTAREA
1,0 -> LABEL
2,0 -> List
I have attached popuplistener to TEXTAREA and LIST
Now when you right click at any plcae within TEXTAREA it is working fine
but try the same in LIST you will know the problem
Thanks