Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Java: GUI и Java FX приложения > JDialog работает до вызова setVisible()


Автор: bara 21.8.2010, 12:21
Создаю простой класс JDialog с таким кодом:
Код

public class test extends JDialog {
    static JFrame jf;
    
    public static void main(String[] args){
        new test();
    }
    
    public test(){
        super(jf,"Тест",true);
        initGUI();
    }
    
    void initGUI(){
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        JPanel panel = new JPanel();
            
        JLabel label = new JLabel("Текст");
        panel.add(label);
        
        add(panel);
        setLocationByPlatform(true);
        setResizable(false);
        pack();
        System.out.println("Before setVisible");    // выводится сразу 
        setVisible(true);
        System.out.println("After setVisible");        // выводиться после закрытия 
    }
}


Текс "Before setVisible" выводиться сразу, а все, что после метода setVisible(true), выполняется только после закрытия окна. Что не так? Или так и должно быть?

Автор: Sleepy_PIP 21.8.2010, 12:39
вот что говорит документация:

JDialog->awt.Dialog

setVisible
public void setVisible(boolean b)
Shows or hides this Dialog depending on the value of parameter b.

Overrides:
setVisible in class Window
Parameters:
b - if true, makes the Dialog visible, otherwise hides the Dialog. If the dialog and/or its owner are not yet displayable, both are made displayable. The dialog will be validated prior to being made visible. If false, hides the Dialog and then causes setVisible(true) to return if it is currently blocked.
Notes for modal dialogs.
setVisible(true): If the dialog is not already visible, this call will not return until the dialog is hidden by calling setVisible(false) or dispose.
setVisible(false): Hides the dialog and then returns on setVisible(true) if it is currently blocked.
It is OK to call this method from the event dispatching thread because the toolkit ensures that other events are not blocked while this method is blocked.
See Also:


акцент:
setVisible(true): If the dialog is not already visible, this call will not return until the dialog is hidden by calling setVisible(false) or dispose.
setVisible(false): Hides the dialog and then returns on setVisible(true) if it is currently blocked.
It is OK to call this method from the event dispatching thread because the toolkit ensures that other events are not blocked while this method is blocked.


так что вроде бы все правильно, нет?

Автор: bara 21.8.2010, 13:53
все ясно, спасибо

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)