I've noticed a problem with Java fullscreen on OSX. If I try to display any kind of popup during full screen mode, the whole screen just goes black. This work on windows, solaris and linux. Any tips for OSX please?
import java.awt.DisplayMode;
import java.awt.FlowLayout;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class FullScreenTest {
public FullScreenTest() {
}
public static void main(String[] args) {
// bug happens with both native and cross-plaform (Metal) look and feels.
// String laf = UIManager.getSystemLookAndFeelClassName();
String laf = UIManager.getCrossPlatformLookAndFeelClassName();
try {
UIManager.setLookAndFeel(laf);
} catch (Exception e) {
}
final JFrame frame = new JFrame("FullScreenTest");
frame.getContentPane().setLayout(new FlowLayout());
frame.getContentPane().add(new JComboBox(new String[]{"One", "Two", "Three"}));
JButton quit = new JButton("Quit");
quit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.dispose();
}});
frame.getContentPane().add(quit);
frame.setUndecorated(true);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
try {
gs.setFullScreenWindow( frame );
DisplayMode dm = gs.getDisplayMode();
frame.setVisible(true);
} catch (Exception e){
System.err.println("Exception: "+e);
gs.setFullScreenWindow(null);
}
while( frame.isVisible() ) {
try { Thread.currentThread().sleep(1000); } catch( InterruptedException e ) { }
}
gs.setFullScreenWindow(null);
}
}