Let me give you a suggestion, and then I'll explain why.
Put a single JPanel in the JFrame, and put everything else in the JPanel. You can set the JFrame layout manager to GridLayout with no parameters, and the JPanel will fill the JFrame. This is one of my "always do" practices.
The reason is this: JFrame cannot hold components directly. It actually has a JRootPane, which in turn has several other panes. JFrame has "convenience methods" to add components and what not, which means that you can use the JFrame methods to work on the pane that actually holds the components, but that can lead to confusion.
Adding a JPanel to the JFrame means that you have a component you defined that contains everything else, so you can see exactly what is going on.
You can add a mouse listener to the JPanel. Keep in mind that if you add components to the JPanel, they may intercept the mouse events. I haven't experimented with that, so this is just something to keep in mind if things don't happen the way you expect.
|