Basically I want to control the size of the content pane even when the application is in full-screen exclusive mode. I want the content to be square, with black bars taking up unused space. Is there a way to do this? Setting the preferred size doesn't work, it just fills the screen anyway. Here's the gist of my code:
setDefaultCloseOperation(EXIT_ON_CLOSE);
setBackground(Color.BLACK);
setPreferredSize(Toolkit.getDefaultToolkit().getScreenSize());
setUndecorated(true);
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(this);
getContentPane().setPreferredSize(new Dimension(getHeight(), getHeight()));
getContentPane().setBackground(Color.WHITE);
pack();
This results in the entire screen being white. On my widescreen monitor, I want the middle of the screen to be white, with black bars on the sides. Is there a clean way to do this? I guess I could add a secondary JPanel, size it correctly, and use that for everything, but that seems sloppy. I'd rather use the JFrame's built-in content pane.