Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java on Mac OSX - Detect if the program is fullscreened

I wrote a java program and I let the user use the Mac fullscreen feature, and I want to be able to know if the program is fullscreen or not. The problem is that I don't know how to detect when the user makes the program fullscreen, because they do so by clicking a button that isn't part of my program. Is there any way to detect if my program is fullscreen?

If I wasn't clear enough, here is an example of the fullscreen button.

fullscreen button example

like image 692
Tyler Avatar asked Oct 20 '22 11:10

Tyler


1 Answers

Have your JFrame (I'm assuming that you're using one) implement com.apple.eawt.FullScreenListener. You will then have access to the following methods:

@Override
public void windowEnteringFullScreen(AppEvent.FullScreenEvent fse) {
}

@Override
public void windowEnteredFullScreen(AppEvent.FullScreenEvent fse) {
}

@Override
public void windowExitingFullScreen(AppEvent.FullScreenEvent fse) {
}

@Override
public void windowExitedFullScreen(AppEvent.FullScreenEvent fse) {
}

And you can then do something similar to what tincopper2 said; set a boolean to true/false depending on if the window is opening or closing.

Source: the comments on the correct answer to this question.

like image 130
BitNinja Avatar answered Oct 27 '22 18:10

BitNinja