Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set my JFrame's setDefaultCloseOperation() value in NetBeans?

I'm trying to learn Java so sorry if this is a stupid question, but I seem to be unable to change the default close operation on my JFrame in NetBeans.

In NetBeans I created a JFrame and implemented some controls on it using the NetBeans GUI designer. However, I noticed that after I close the JFrame, my application would close even though I have another form that is supposed to appear afterwards.

After digging through the JFrame generated code I found:

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

From research it appears that this causes the application to close when the frame is closed. I would prefer to not have this happen. From looking around, it appears I either need to use DISPOSE_ON_CLOSE or DO_NOTHING_ON_CLOSE in order to get the window to close but still have additional code to run.

However, I can't figure out how to get NetBeans to change this value through the designer. I found the defaultCloseOperation in the Properties -> Bindings window, but every time I enter something into the text area and press enter my text disappears. The binding has an elipsis but I can't figure out what the binding window actually does.

How can I change my setDefaultCloseOperation() to a new value?

like image 618
KallDrexx Avatar asked Jan 28 '26 06:01

KallDrexx


2 Answers

Netbeans

It is right there in the properties panel. Just make sure that the whole JFrame is selected. You can select your JFrame from Inspector panel.

like image 174
Funky coder Avatar answered Jan 30 '26 20:01

Funky coder


Try to update defaultCloseOperation value from Properties -> Properties tab, not binding tab

Netbean properties window

like image 43
Yusuf K. Avatar answered Jan 30 '26 19:01

Yusuf K.