Modal de JDialog Singleton

5 respostas
andre_guitar7

Pessoal, como poderia setar o modal do meu JDialog? Eu tenho um JFrame que chama esse JDialog mas náo sei como posso setar o modal no meu instance...

public class FormNewUser extends JDialog {
	
	private static final FormNewUser instance = new FormNewUser();
	
	public static JDialog getInstance(){
		return instance;
	}
	
}

vlw

5 Respostas

Mantu

Não sei se isso é deselegante, mas tenta mudar um pouco a cara do seu singleton:

class FormNewUser extends JDialog {
	private static FormNewUser instance = null;
	private FormNewUser() {
		/*...*/
		setModal(true);
		/*...*/
	}
	public static FormNewUser getInstance(){
		return instance == null ? new FormNewUser() : instance;
	}
	
}

Espero ter ajudado

andre_guitar7

Bom… elagante ou não, tá funcionando, hehe…

vlew!

andre_guitar7

Mantu:
Não sei se isso é deselegante, mas tenta mudar um pouco a cara do seu singleton:

class FormNewUser extends JDialog {
	private static FormNewUser instance = null;
	private FormNewUser() {
		/*...*/
		setModal(true);
		/*...*/
	}
	public static FormNewUser getInstance(){
		return instance == null ? new FormNewUser() : instance;
	}
	
}

Espero ter ajudado

Só tive que mudar essa linha:

return instance == null ? new FormNewUser() : instance; pra essa:

return instance == null ? instance = new FormNewUser() : instance;

…senão ele não fica singleton… mas era o q eu estava precisando, vlw…

Mantu

Ah! Verdade! Comi bola! hehehehe… Valeu a correção! :thumbup:

Mantu

Sorry… Pau no meu micro…

Criado 5 de junho de 2006
Ultima resposta 5 de jun. de 2006
Respostas 5
Participantes 2