5

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

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Tyler
  • 486
  • 1
  • 6
  • 20
  • Have you tried to see if OS X makes use of [extended state](http://docs.oracle.com/javase/7/docs/api/java/awt/Frame.html#getExtendedState%28%29)? My experience has been clicking the 'expand' jewel does not so it would be worth it to see if they are setting the 'maximized' flag for this. – Radiodef Mar 23 '14 at 22:36
  • This is an Objective-C answer, but I'm curious if this is possible in Java as well: http://stackoverflow.com/questions/6815917/how-to-know-if-a-nswindow-is-fullscreen-in-mac-os-x-lion – JAL Mar 23 '14 at 22:36
  • @Radiodef, unfortunately, it does not – Tyler Mar 23 '14 at 22:41
  • Have you tried adding a `WindowStateListener` and checking the `getOldState()` and `getNewState()` of the fired `WindowEvent`? While it seems unlikely that this approach will work given that OS X doesn't make use of extended frame state, it's worth a shot. – FThompson Mar 23 '14 at 22:53

2 Answers2

3

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.

Community
  • 1
  • 1
BitNinja
  • 1,477
  • 1
  • 19
  • 25
0

Well, one thing, which might be the simplest of things to do would be to have making it full screen or not calling on a function that changes a global dynamic variable to true or false being names something like "fullscreen", and then to simply check if it is fullscreen you can return the response of what the variable is defined as.

tincopper2
  • 79
  • 10
  • 1
    I would do that, but I can't detect if the user clicks the full screen button, since it's part of the Mac GUI, not my java program. I also can't remove the button from my JFrame without disabling its fullscreen capability. – Tyler Mar 23 '14 at 22:39
  • You could change the window type to not have the outline of closing and resizing, and make your own button to set it to fullscreen using JFrame. – tincopper2 Mar 23 '14 at 23:21