Problems with focussing JFrame
Hello fellow Java programmers,
I have a problem with focusing a JFrame on top. I'll be really gald if anyone can help me out.
I created a JButton on a JPanel(which inturn is a part of another JPanel). I would like to have a window pop up when this button is clicked. Unfortunately the window I created(JFrame) pops, but stays behind this JPanel and I can only see it after I close this JPanel. I used the setAlwaysOnTop(true), but to no use. Infact, doing so is causing the JPanel to stay always on top. Here is the code for action performed event of the button
Code :
mButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
startMetadataEdit();
}
});
}
private void startMetadataEdit() {
MarkerMetadata mmd = getMetadata();
MetadataEditPanel mMep = new MetadataEditPanel(mmd);
mMep.setVisible(true);
}
The constructor of MetadataEditPanel contains a function initComponents(), which declares and defines the components of the pop-up window. I tried putting all sorts of function calls in initCompnents(), like setAlwaysonTop(true), setFocusable(true), but nothing worked out. I created this UI on netbeans and i'm using this code in Eclipse(Yes, I'm a bit lazy to write GUI code).
So, does anyone have any suggestions/solutions? Thanks in advance
Re: Problems with focussing JFrame
You wouldn't have the other JFrame to always be on top too would you?
EDIT:
Also what version of Java are you using?
Re: Problems with focussing JFrame
No, I need to JFrame to stay behind while the poped up window stays. Infact, I want that users can't use JFrame until they finish using the poped up window.
I'm using java 6. Are there any known problems with Java 6 Swing?
Thanks,
Re: Problems with focussing JFrame
Quote:
Originally Posted by
ozymann
No, I need to JFrame to stay behind while the poped up window stays. Infact, I want that users can't use JFrame until they finish using the poped up window.
I'm using java 6. Are there any known problems with Java 6 Swing?
Thanks,
If this is the behavior you would like, then you may want to create a JDialog, calling setModal(true) to make the dialog modal. From what you posted, its hard to say why your current implementation is behaving this way. I'd suggest you create a short, runnable code which reproduces the problem so others can offer up advice.