java - JDialog lets main application lose focus -
I wonder why pushing my main app in my JDialog background. This means that if JDialog will be shown and the user clicks on "OK" or "Canal" then the main app will focus and push it into the background.
After my investigation, I came to know that this behavior occurs only when I disable my main frame for that time when I show JDIOL.
This behavior can be reproduced with the following code:
import java.awt.Component; Import java.awt.event.ActionEvent; Import java.awt.event.ActionListener; import javax.swing.JButton; Import javax.swing.JDialog; Import javax.swing.JFrame; Import javax.swing.JOptionPane;
Public Class Focus Test {
Private JFrame Frame; Public Focus () {frames = new jeframs}; Frame.setSize (200,200); Jebton BTN = new pocket ("Open Dialog"); Btn.addActionListener {New Public Notice Action (Action Avent E) {Call Dialogue (blank, "title", "message");}}); Frame.add (btn); Frame.setVisible (true); } Private Zero Call Delog (component parent, string title, string message) {frame.setEnabled (false); Thread t1 = new thread (new runnable (run) {publicpayment optionpane = new hopspane ("", joppenpan.QUESTION_MESSAGE, JOSEPHEN.YES_NO_OPTION); JDialog dialog = OPTIONPAN.CRETEDIY (blank, ""); dialog Set visible (true); frame.Setting enabled (true);}}); T1.start (); } Public static zero main (string [] args) {new FocusTest (); }
How can I stop the main application to lose its focus? (Without enabling the main frame)
You can set the following options for a JDialog class < / P>
// setUndecorated (true); SetFocusableWindowState (wrong); SetFocusable (false); For this you can close your own JDIOL class. You only have to expand from JDialog and put the code in Constructor Call.
Comments
Post a Comment