My Java application has multiple frames. Some of them are set to be always on top. However, when the user opens another program (let's say a web browser), I want the always-on-top frames to move to the background, making way for the other application to fully show on screen.
Create your own Window Manager.
Create a custom Window Manager that implements WindowListener
, WindowStateListener
, and WindowFocusListener
. Register all new frames with this manager and use it to bring your always-on-top frames back to the front whenever the user interacts with the frames.
It sounds like your application is using some pretty custom frame management code. My guess is that as you continue developing the application, this Window Manager will take on more functionality to manage the user interface. This will not only give you the design to solve your problem, but also a foundation for any changes or enhancements to this behavior.
Please bear in mind, though, that Java cannot control what the operating system does with other applications. It can't even reliably bring a frame to the foreground above other applications in all operating systems. You will need to work with the operating systems you will support to write this Window Manager to give you the behavior that you desire.
My Java application has multiple frames. Some of them are set to be always on top.
don't do that, use CardLayout instead, in the case that you really needed end_user action then to use
Modal JDialog (or
ModalityType
withAplicationModal
)re_use JDialog (getContentPane.removeAll()) for next usage of
However, when the user opens another program (let's say a web browser), I want the always-on-top frames to move to the background, making way for the other application to fully show on screen.
this could be very annoying for end_user, use FullScreen instead
notice most important rest is in the comment by @Andrew Thompson
© 2022 - 2024 — McMap. All rights reserved.