How do i create a JFrame
window in eclipse on a Mac that has an icon that makes the window full screen like the double arrow icon on most windows at the top right??
Asked
Active
Viewed 360 times
0

MadProgrammer
- 343,457
- 22
- 230
- 366

bobjamin
- 265
- 1
- 2
- 11
1 Answers
4
Take a look at
- Fullscreen feature for Java Apps on OSX Lion
- And Java Runtime System Properties, which may be of interested
- or How can I do full screen in Java on OSX if those were the wrong feature you wanted
UPDATE
Lucky for you JFrame
extends Window
via Frame
...
public class TestMacFullScreen {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setLocationRelativeTo(null);
frame.setLayout(new BorderLayout());
JLabel label = new JLabel("Look ma, no hands");
frame.add(label);
enableOSXFullscreen(frame);
frame.setVisible(true);
}
});
}
public static void enableOSXFullscreen(Window window) {
try {
Class util = Class.forName("com.apple.eawt.FullScreenUtilities");
Class params[] = new Class[]{Window.class, Boolean.TYPE};
Method method = util.getMethod("setWindowCanFullScreen", params);
method.invoke(util, window, true);
} catch (ClassNotFoundException exp) {
exp.printStackTrace();
} catch (Exception exp) {
exp.printStackTrace();
}
}
}

Community
- 1
- 1

MadProgrammer
- 343,457
- 22
- 230
- 366
-
This seems like what im looking for (the first one) but im having a bit of trouble implementing it. Im fairly new at java. The function requires a window but how do I get a window from JFrame? – bobjamin Oct 05 '12 at 20:14
-
Thank you for this, My code wasn't working because i had setVisible before calling the fullscreen method. Apparently it needs the window to be hidden to do the operation. – bobjamin Oct 06 '12 at 08:42
-
Wasn't sure, but given my experience with of the other `Window` settings, I figured it would ;) – MadProgrammer Oct 06 '12 at 08:43