Hello, is there an acceptable way to do the following?

public CriarEquipamentoGUI (boolean showWindow) {
	if !(showWindow)
		dosomething();
		return;
	else
		initComponents();
}

Currently the return statement completly screws up the window.

I am not sure to understand what you really want to do with that code, or what do you mean with 'abort construction a window'.

First of all, your code has a few of errors:

1. CriarEquipamentoGUI is defined like the constructor of a class of the same name, but it is not enclosed in any class. I guess you decided to paste only the part of your interests.

2. The reason why the 'return' screws the problem is because you forgot to add brackets.

You have something like this:

if( do not show ) { 
    doSomething();
}
return; // The rest of code is unreachable.
else {  
  initComponents();
}

When you should have something like this:

if( do not show ) {
    doSomething();
    return;
} else {
    initComponents();
}

3. I am not sure if this is what you want, but after all the components are ready, you can still decide not to have the window shown.

jframeInstance.setVisible(false); // although false is its default value.

That is all I can tell by now, if you need any more help then please expand your ideas a bit more.

~ Xhamolk_

The example I gave is just pseudocode and it represents what I want to do.

Basicaly:
If the list of products is empty, immediately close the jdialog, warning the user that he can't place orders because he doesn't hasn't created any products.

And my problems are:
1. this.setVisible(false) is overriden by initComponents() and the window is shown anyway. (the warning appears and so does the "Create order" dialog)
2. Using return instead of this.setVisible(false) leaves behind a 1 pixel wide windown.


EDIT: OUCH, I HADN'T REALIZED initComponents() is an autogenerated netbeans method and not something inherited from Jdialog. Consider this solved.

EDIT2: Scratch that, I haven't been able to find a way to solve this.

(I hate the edit timer)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.