Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
316 views
in Technique[技术] by (71.8m points)

java - How to disable (or hide) the close (x) button on a JFrame?

I have a window (derived from JFrame) and I want to disable the close button during certain operations which are not interruptible. I know I can make the button not do anything (or call a handler in a WindowListener) by calling

setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

but I would like to make it clear visually that it is pointless to click it.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is probably the best you are going to get:

setUndecorated(true);
getRootPane().setWindowDecorationStyle(JRootPane.NONE);

This will remove the entire titlebar, java doesn't really specify a way to remove individual components of the titlebar

edit:

There may be a way, check out these threads:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...