微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何检查你是否在Mac或Windows上调整Java的GUI?

我写了一个程序,需要在Mac和Windows上工作。 在GUI方面,在Windows上看起来不错,但是Mac上的JFrame太小了。 我已经使用GridBag布局,没有什么是绝对的,这个问题的答案类似于这个问题。 我已经尝试使用pack(),但是对于这个GUI它不能正常工作。 它甚至不调整框架以适应菜单栏。 我正在使用setSize(X,Y),但有没有办法检查用户是否在Mac上,然后相应地改变大小? 我也尝试过使用setMinimumSize(),然后打包(),但包装无论如何不做任何事情。

这是我的帧代码位; 只是因为pack()不能正常工作而导致出现任何问题。

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

提前致谢!

Watin采取黑色RDP断开时的屏幕截图

在IE9中使用JavaScript错误debugging网站 – 打开debugging控制台修复错误

从Windows任务计划程序运行Java GUI应用程序不起作用

用户select应用程序来打开文件

Java – Swing GUI在Windows 7中呈现不正确

使用IE9embeddedWebbrowser控件时覆盖IE设置

在Linux上使用modal dialog时,显示繁忙游标的Swing渲染问题

在Windows上使用Java Swing SystemLookAndFeel maschines会导致CachedPainter中的MemoryLeak与JTextPanes

IE9简单的点击/滚动问题

在Linux中可以使用9位串行通信吗?

您可以找出哪个操作系统与系统属性一起使用。

例如:

System.getProperty("os.name"); //returns name of os as string System.getProperty("os.version"); //returns version of os as string System.getProperty("os.arch"); //returns architecture of os as string

根据情况检查:

public String getoS() { String os = System.getProperty("os.name").toLowerCase(); if(os.indexOf("mac") >= 0){ return "MAC"; } else if(os.indexOf("win") >= 0){ return "WIN"; } else if(os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0){ return "LINUX/UNIX"; } else if(os.indexOf("sunos") >= 0){ return "SOLARIS"; }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐