PDA

View Full Version : Fullscreen Java




whitehexagon
Nov 11, 2007, 10:41 AM
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?



duncanj
Mar 4, 2009, 09:22 AM
I have exactly the same problem. Whenever I click on a JComboBox (dropdown) the screen goes completely black and the window ceases to respond to mouse or keyboard events.

I see this problem with OSX 10.4.11 and java 1.5.0_16. It happens whether I choose the Aqua (native) look and feel or the cross-platform (Metal) look and feel.


SSCE:


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);
}
}