Can someone tell me how to set my X button in main application window visible to false and how to set Alt + F4 function not available or just disable it?
For setting X button to invisible is very much described by @trashgod and For disabling your ALT + F4 thing, you can simply write frameObject.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
or you can addWindowListener(...) to your JFrame like this :
Code snippet to show what i am saying :
import java.awt.event.*;
import javax.swing.*;
public class FrameTest
{
private WindowAdapter windowAction;
private JFrame frame;
public FrameTest()
{
frame = new JFrame("FRAME TEST");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationByPlatform(true);
windowAction = new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
}
};
frame.addWindowListener(windowAction);
frame.setSize(100, 100);
frame.setVisible(true);
}
public static void main(String... args)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
new FrameTest();
}
});
}
}
"A frame may have its native decorations (i.e. Frame and Titlebar) turned off with setUndecorated
."—Frame
Addendum: You can send a WINDOW_CLOSING
event and bind that Action
to your desired Keystroke
, as shown here.