This week's book giveaways are in the iOS and Features new in Java 8 forums. We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line! See this thread and this one for details.
I am trying to implement a message dialog to be shown when a JMenuItem is selected. I want the dialog window to appear centered in the Application's window. So I need acess to the ParentFrame so I can do this:
The question is how can I get access to that parent component/frame from the ActionEvent? The ActionEvent's source (e.getSource()) is a JMenuItem. It does not have a RootPane (i.e. getRoot() returns null). When I call menuItem.getParent() I get a JPopupMenu. That JPopupMenu does not have a parent (it's null) nor a root pane. So how can get a referene to the Application's frame so my dialog is centered on it?
Something I generally do in my applications is keep an instance of my main window in a static instance class. I usually just call this Application so that I can do things like:
I use it for all sorts of application wide data that I need so that I don't have to pass objects around as much. It also is clearer (to me) than obscure API methods that have no meaning at face value, even though they do work.