JButton: getLocationOnScreen() throws Exception
i'd like to show a context menu below an "Add" button in a JFrame when that "Add" button is clicked. To determine the location for the context menu I thought calling the getLocationOnScreen() method on "Add" button would give me its location so I can calculate the position to display the context menu.
However, although the Button (the whole JFrame it is placed in) is visible, the call throws an IllegalComponentStateException. isVisible() returns true. Debugging shows that the JButtons "peer" is null and this is the reason why the exception is thrown.
What is the "peer" and why is it NULL? How can I get the coords of a button in another way?
Thanks in advance,