How could I create a window which is modal and has a maximize button?
So is it possible to create a modal JFrame
or create a JDialog
with maximize button?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Here is an alternate / slightly more detailed answer.
Try Are You Missing Maximize Button? (formerly here). This is a github archive of blog articles and code by Santhosh Kumar Tekturi from the now defunct JRoller site.
It is a complete utility class that makes a Frame mimic a Dialog, similar to the other answers. It involves adding a
WindowListener
to the Frame to keep the frame on top of its owner and keep its owner frame disabled (warning: in thewindowClosed
method it should probably beframe.removeWindowListener(this);
, and aWindowListener
to the owner to keep the frame on top of it and to remove the listener. It also uses its ownEventQueue
to process events. Note this is an old post, so as mentioned in the code there may be newer APIs to deal with this code better.Here is the core function. See the link for the rest. Note: the code in the repository differs from the article; I believe the repository is more developed.
On most look and feels, modal windows (such as
JDialog
) do not have a maximise button simply because they're not supposed to be maximised (or minimised) at all.It's possible with some tricks to add a
maximise
button, but it would be completly against the wayJDialog
is supposed to work. If you need a maximise button, the best solution would be using aJWindow
or aJFrame
instead of aJDialog
. Those windows support maximisation and minimisation.WARNING: You shouldn't do that, no matter what.
A trick to do this in
JDialog
:Solution 1: Tested on Windows
I used a JFrame for the modal window
Solution 2: Tested on Ubuntu
I added a WindowFocusListener