I have a JFrame (mainframe) and JButton put in. When i click on JButton, this open another JFrame. I want to close mainframe only if the second frame is closed and i want obtain the same effect of when you have a open JChooser and try to close the JFrame. (JChooser flashing if you try to click on the X's frame). How can i do this?
What you want to achieve can be easily done with JDialog. Read the below mentioned link.
https://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html
Related
I have 3 Jframe, when I click on first Jframe, it closes it and opens new, is there any way to call second jframe on this window?
I have a small game in which one window opening the other when the game over.
I want to close only the game over window.
this.dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
But this closes the both windows.
How to close only the second window?
It can be closed from the game over window itself by
this.dispose();
or hidden by
this.setVisible(false);
You can also change the closing behavior with (assuming a JDialog where the default is HIDE_ON_CLOSE)
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
If you need to close it from the parent JFrame, dont use this, but instead target the object
gameOverDialog.dispose();
I'm developing an application using java swing. When I click a button, I want another window to be opened. This works fine. But it is possible to alt+tab to the original window and then interact with it even after the new window is open. Is there any way not to let the user focus the original window after the new window appears? By window I'm referring to Jframe/Jdialog.
Assuming the instance of your main JFrame window is called mainWindow:, the following code will prevent switching the focus.
// the second parameter makes the dialog modal and will prevent
// switching the focus to the mainWindow
JDialog dialog = new JDialog(mainWindow, true);
...
dialog.setVisible(true);
Documentation on JDialog: http://docs.oracle.com/javase/6/docs/api/javax/swing/JDialog.html
You may try to use a JDialog instead of JFrame and pass the instance of JFrame to JDialog constructor
You may also try to check
frame.setAlwaysOnTop(true);
or may be like this:-
frame.toFront();
frame.setState(Frame.NORMAL);
I want to make a JFrame with the drawn shadow.
I made a undecorated window and made a background with shadow(grey) and empty part(green),and it can be dragged.
The problem is,when I try to drag the shadow or the empty part,the frame can also be dragged!
I want to bring the window under the window(Another application) that was under it,just like I click on the window.
I tried setBack(),but it just put it under every window,not the back one.
How to click through the window?
I am unable to understand your question clearly.
In case want a frame within a frame, then opt for JInternalFrame class.
I have one frame that opens up another frame (editor). Most of the menu accelerators don't work when opened this way, but when I run the editor frame standalone, they do work. Should it work?
It turns out that when you open one frame from another in java you have to start another thread or the keybindings don't work right - they all get caught by the first frame. This makes sense.