[Logo]
Forums Register Login
setDefaultClosingOperation
I have a very simple application that I have a problem with the basi code is
package really.trying;
import javax.swing.*;

public class swingStuff() {
public swingStuff() {
JFrame frame = new JFrame("Tester");
JButton but1 = new JButton("Test");
frame.getContentPane().add(but1);
frame.setVisible(true);
frame.setSize(300,300);
frame.setDefaultClosingOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
swingStuff new1 = new swingStuff();
}
}
I know its very very basic, I don't even have a Layout Manager but I wanted to start very simple. Any advice or help will be very appreciated.
Hi,

Welcome to JavaRanch!

It's "setDefaultCloseOperation". Use the Javadocs to look these things up.

It's a good idea to call setVisible() last, after everything else about a window is already set up.
Thanks I just looked right over that. Appreciate it
There's a way to do it better - find it. -Edison. A better tiny ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature


This thread has been viewed 551 times.

All times above are in ranch (not your local) time.
The current ranch time is
Apr 22, 2018 19:56:51.