Do Java GUIs display the same on all operating systems? [closed]

被刻印的时光 ゝ 提交于 2019-12-23 05:15:34

问题


Do programs written in Java that use components from Swing to build their GUI display exactly the same on all operating systems?

EDIT: let me ask the question this way: using Java is it possible to design a GUI that is guaranteed to display exactly the same on all platforms?


回答1:


Saying shortly it will look differently by default, because swing uses system look & feel, but you can override it (http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html), in this case application will look the same on all platforms with the same look & feel, or you may disable some look & feel features like -Dswing.noxp=true




回答2:


Used correctly, common Swing components are pleasantly stable across platforms and L&Fs, but there are no guarantees. One should avoid the temptation to violate UI defaults gratuitously. Example of this abound, but common pitfalls regarding size are discussed here and here. Testing is mandatory, but widely available virtual machines mitigate the effort.




回答3:


yes they will as long as you use swing and no platform specific code.

That said: They will not feel 'natural' then. SWT is a tad better there




回答4:


Pretty much so. But using the UIManager you can determine a theme based on an operating system's theme.
Example:

UIManager.LookAndFeelInfo looks[] = UIManager.getInstalledLookAndFeels();
    try{
        //0-Swing, 1-Mac, 2-?, 3-Windows, 4-Old Windows
        UIManager.setLookAndFeel(looks[3].getClassName());
    }catch(Exception e){
        System.out.println(e.getMessage());
    }


来源:https://stackoverflow.com/questions/13439595/do-java-guis-display-the-same-on-all-operating-systems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!