I’ve written a program which needs to work on both Macs and Windows. In terms of the GUI it looks fine on Windows but the JFrame is too small on Mac.
I’ve used GridBag layout and nothing is using absolute, which has been suggested in answers similar to this problem.
I’ve tried using pack() but it doesn’t work properly for this GUI. It doesn’t even resize the frame to fit in the menu bar. I’m using setSize(X, Y) but is there a way to check to see if the user is on a Mac and then change the size accordingly?
i’ve also tried using setMinimumSize() and then pack() but pack doesn’t do anything anyway.
Here is my frame code bit; just incase anything is wrong in there due to pack() not working.
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) { }
try {
timeCodeMask = new MaskFormatter(" ## : ## : ## : ## ");
} catch(ParseException e) {
errorMessage("Warning!", "Formatted text field hasn't worked, text fields will not be formatted.");
}
try {
activePanel = new JPanelSwapper("src/bg.png");
} catch(IOException e) {
errorMessage("Warning!", "Background image has not loaded, continuing without one.");
}
FPS = 24;
calculatorPanel = calculatorPanel();
converterPanel = converterPanel();
activePanel.setPanel(calculatorPanel());
previousTimes = new TimeStore();
resultTimes = new TimeStore();
previousConversions = new TimeStore();
frame = new JFrame("TimeCode Calculator & Converter");
ImageIcon frameIcon = new ImageIcon("src/frame icon.png");
frame.setIconImage(frameIcon.getImage());
frame.setExtendedState(JFrame.NORMAL);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame.setSize(WIDTH, HEIGHT);
//frame.pack();
frame.setMinimumSize(new Dimension(WIDTH, HEIGHT));
frame.pack();
frame.setResizable(false);
frame.setJMenuBar(menuBar());
frame.getContentPane().add(activePanel);
frame.setBackground(Color.WHITE);
frame.setVisible(true);
screen = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((screen.width - WIDTH) / 2, (screen.height - HEIGHT) / 2);
Thanks in advance!
You can find out which operating system is used with system properties.
For example:
Check it against conditions: