I wrote a data plotter application a while ago, which has an autoreload feature. Both load and reload action cause a JDialog with a cancel button to pop up. In autoreload mode this happens every several seconds, with the JDialog window requesting focus every time.
I tried calling setFocusableWindowState(false) on the JDialog instance, but that did not make any difference. Could it be because it's a JDialog rather than some other subclass of Window?
UPDATE: setFocusableWindowState(false) does work, I was just stupidly running the wrong jar file. Long story. Anyway, I'm not deleting the question because when I did a little bit of research before posting it, I saw a few other people having trouble with similar issues. This is the solution :)
You have to put these two statements, in the constructor of your class extending JDialog
setFocusableWindowState(false);
setFocusable(false);
So when each time the JDialog appears, the parent container will still have focus on whatever it had.
setFocusableWindowstate() does work, after all. It was my own stupid mistake: I was running the wrong jar file, i.e. not the one with the fix. Thanks to everyone for their suggestions.
Related
I am facing a very strange issue: I have a non-modal JDialog in a very complex Swing application. There is a situation where another (modal) dialog opens above the non-modal one. After closing the modal dialog, it is no longer possible to click on anything in the non-modal dialog. After adding a FocusListener I realized that the focus cannot be gained. I am not able to click on any button or slider inside the dialog, nor does it react if I click on its title bar. Whenever I am trying to do so, an OS sound clip is being played which you would normally expect to hear when trying to click on a component while another modal component is still visible. But it's not.
Fun fact: the bevavior goes away when another modal window of any kind is being opened and closed again! After that, the non-modal dialog re-gains the focus.
I apologize for not being able to post the code here, as dozens of classes are involved to reproduce this. But if maybe anyone has ever come across a similar issue or behavior and knows where it comes from, it would be great if you shared your knowledge about how to overcome it.
Thanks in advance!
I have build an application using the Netbeans Wizard Framework as outlined here and here. I have my application working properly, but the problem I have is that the application does not show in the windows taskbar. I am pretty sure the problem is that the Wizard Framework uses a JDialog instead of a JFrame, but I can't figure out if that can be changed.
If anyone has experience with this framework, please let me know if it can be made to appear in the taskbar.
Changing is quite easy.
Open the form in NetBeans.
Change extends javax.swing.JDialog to extends javax.swing.JFrame.
Save the file and close it.
Reopen the file.
In designer mode, make a change. I usually just change the name of a component.
Save the file.
Undo the change and save the file again.
You should be all set.
Wizard Framework uses a JDialog instead of a JFrame, but I can't figure out if that can be changed.
don't use more than one JFrames, this's road to the hell, you cann't to setToFront, setOwner, iconify, etc ...
use JDialog or JWindow instead with parent to the one single JFrame
use undecorated JDialog, with setModal() or is possible to set various ModalityTypes too
If anyone has experience with this framework, please let me know if it can be made to appear in the taskbar.
this Swing Framework is long time depreciated
you can use SplashScreen repeatly instead of JDialog/JWindow
Setting: Java 5 - no upgrade possible.
I have a large application that has a number of modal dialog windows. I have heard that hidden modal dialogs can result in uninformed users going so far as to restart their computer. Even if a user knows how to ALT-TAB (in MS Windows, at least), it's a pain. From what I understand, this was in part fixed in later versions of Java, but that's not an option here, unfortunately.
So, is there any way to force a modal dialog to be shown if any part of the running application is clicked on? I was thinking it might have something to do with either MouseListeners, GlassPanes, or something else. However, I've got a bunch of other stuff I'm supposed to be working on, so I don't have a lot of time to devote to hashing this out right now. Can anybody point me in the right direction?
Thanks so much!
So, is there any way to force a modal dialog to be shown if any part of the running application is clicked on?
When you create the dialog you need to specify the parent frame as the owner of the dialog. Then whenever you click on the frame any dialog that is a child will also be shown.
I'm trying to make a swing gui but currently experiencing trouble with making JMenus "close" when clicking elsewhere.
If a JMenu is selected/open i want it to close when clicking somewhere else on the gui but instead it remains open (most of the time) and the only way for me to close it is to click on the selected JMenu again.
I've searched for a solution but only seem to find bug reports on this matter.
Any help is appreciated, thanks.
Ok i found the problem last night.
One of the ActionListeners for the JMenuItems had an initializer for a JDialog in the contructor, i found it when i was trying to recreate the problem.
Thanks for replying.
I have never seen this problem.
Read the section from the Swing tutorial on How to Use Menus for working examples.
Compare your code to the working code to see what is different.
If you still can't find the problem then post your SSCCE that demonstrates the problem because there is no way we can guess what you are doing different from the working examples.
I made a GUI in Eclipse using the Google WindowBuilder plugin. The problem is that when I right-click on the design representation of my code and click, "Test/Preview," my GUI works and looks perfectly (the picture on the right), but when I click the "run" button in Eclipse to actually run the code, the GUI looks all weird (the picture on the left).
Does anybody have a clue as to what the problem is?
Ok this could have multiple reasons, the most obvious one being, that you (accidentally?) set your JButtons' background Color to the same dark-gray as your Frame's background. Check This first! WindowBuilder's preview has a quirk of sometimes not showing recent design changes on some elements immediately.
If that Is not the case with you, it might be some weird formatting thing.
Have you manually changed your buttons' formatting within the code and not within the design tab? Then add (Say your button is called okButton) okButton.repaint(); after the changes you manually made.
If this still doesnt work,
Try adding okButton.setVisible(true); (Althought that is pretty far fetched, seeing that a button outline can be seen!)