I have written an application that has one main window and multiple dialogs, however one of these dialogs does not close when the user clicks the 'X' button at the top right corner. There is an OK button in the dialog which closes it correctly, so it's not a huge issue. Can anyone suggest why it's not working?
Maybe you are missing such a line: setDefaultCloseOperation(HIDE_ON_CLOSE); in the dialog class?
Related
hi guys my question is about closing a child window in top right corner without exiting the system any idea
i want it to do something like despose(); with a pushbutton
thanx in advance
im not sure if this is what you mean but if you mean to move the x button then you have to make the frame that you have a jpanel rather than a jframe or anything and then when your done with that make a jbutton and place it on the top and when your done doning that design it and then add a action listener to the button when that action listener knows that the button was clicked then do f.dispose(); and that will close it :D
I am trying to use a JDialog at the right of the screen, everything is almost perfect, but, if someone press the button on ther right end of the TaskBar, click on "Show Desktop area" my JDialog disappears I have to use ALT + TAB to get it back in in front. I can't set it AlwaysOnTop because I use other 3rd party programs that are fullscreen.
I tried:
jdigCentral.setAutoRequestFocus(true);
jdigCentral.setAlwaysOnTop(true);
and others, but without success
How can I have my JDialog to stay over just the Desktop Area?
Is jdigCentral your dialog box? If so then try this:
jdigCentral.setModal(true);
That will keep the dialog box on top of the parent JFrame. But I'm confused about the use of the word Desktop Area. Do you mean you want to keep the dialog box on top of the parent frame, or do you want it to always show on top of all other programs running on your desktop?
I have two jbutton in a jpanel and when you click the first button you see a msg box saying "good morning" and when you click the second you see a "good night" msg box . But when i click on the first button and not closing the msg box first i can not click the second button to see the message.
Can anyone help me?
thanks.
This would suggest two basic things, you are using either a JOptionPane or modal JDialog to display your messages.
In either case, a modal dialog blocks the parent window until it is dismissed. You need to make the dialog modeless instead.
Take a look at How to Make Dialogs
I want to create a hidden button in netbeans. Suppose if I click a Next button then a new "Exit" button will be appear in the same jFrame. Until I click the Next button the Exit button will not be shown. So how to make it? I mean how to make a button which is by-default in .setVisible(false) in netbeans?
Please help me out about this problem.
Since you already seem to know the proper method I assume you doubt is about Netbeans operation.
Right click in the method and select "Customize Code".
Then you'll have the chance to add the proper code after the button creation.
Use JButton.setVisible(false); right after you create the button.
Does exist in the JDialog class a way to prevent that a child window (JDialog) would be displayed more than once when the button from the main window (JFrame) used to open it, is pressed several times? Many thanks in advance!
Yes, and you don't need to make the box modal to do it (although making it modal would be the easiest way).
Simply do something like the following
In your member delcarations:
private final MyDialog dialog = new MyDialog();
In your code:
private void showDialog() {
dialog.setVisible(true);
dialog.requestFocus(); // May be needed to bring window to front
}
This will ensure that you only instantiate the box once. Simply call showDialog() whenever the button is pressed.
Another way that I've done in the past with Swing is that when the button is pressed the first thing I do is disable the button. Then I use the observable pattern to look at the child window and re-enable the button when the child window is closed. That way if it takes a while to display the child window for some reason the user can't click on it multiple times and mess things up.
You could make the JDialog modal, then the parent window would not react until it is closed.
Or you could initialize the JDialog before, and just make it visible when your button is pressed. Making it visible twice will not display it twice.