为什么 Java Swing 在不同的系统上表现不同? [英] Why Java Swing behaves different on different systems?

查看:23
本文介绍了为什么 Java Swing 在不同的系统上表现不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在计算机中编写的一些 Swing 代码在我同事的计算机、PC 和笔记本电脑中的表现有所不同.

我想知道,我可以对我的 Swing 应用程序在每台计算机上的行为做些什么吗?

我想确保我在我的计算机上测试过的算法在我的客户端计算机上也能以同样的方式工作.

例如聚焦 JTextField 的问题 在我的 Windows XP 笔记本上运行良好,但在我同事的电脑是 Windows XP,在我的工作电脑里也没有 Ubuntu.

观察.具体的 JTextField 问题不是这个问题的主题.

解决方案

Swing 应用程序在不同平台上的问题很常见,原因很简单,即无论 Java 提供什么级别的抽象,它都必须在某些情况下发挥作用指向底层操作系统的本机组件.事件虽然 Swing 仅使用窗口(框架)并自行绘制所有内容 - 差异非常普遍.

我开发了一个多平台 Swing 应用程序 - Windows 上的用户报告了 Linux 用户没有的各种问题,反之亦然.遗憾的是,此类问题没有灵丹妙药——广泛的测试和令人讨厌的修复是镇上唯一的游戏.

在可插拔的外观和感觉方面,一切都变得异常糟糕和肮脏.例如 - 使用 metal 或 nimbus 调整 JSplitPane 的大小非常快(正如预期的那样),但是如果您使用 GTK+ plaf,一切都会变得糟糕.这是一个更严重的(性能)问题 - 视觉问题(缺少边框、组件不适合容器等)没有尽头……尽管如此,Swing 仍然是多平台桌面应用程序的最佳选择之一.

Some swing code I write in my computer behave different on my colleague's computer, and in my PC, and in my notebook.

I wonder, is there something I can do to my Swing applications behave the same in every computer?

I want to have sure a algorithm I've tested in my computer will work the same way in my clients computers.

E.g. Problem to focus JTextField works fine in my notebook with Windows XP, but not in my collague's computer with Windows XP, nither in my work computer with Ubuntu.

obs. the specific JTextField problem is not the subject of this question.

解决方案

Problems with Swing apps on different platforms are common and they are caused by the simple fact that no matter what level of abstraction Java offers it has to play ball at some point with the native components of the underlying operating system. Event though Swing only uses the windows(frame) and draw everything by itself - discrepancies are very very common.

I develop a mutliplatform Swing application - and users on Windows are reporting all sorts of issues that Linux users don't have and vice versa. Sadly there is no silver bullet for such problems - extensive testing and nasty fixes are the only game in town.

And everything come exceptionally buggy and dirty in the area of pluggable look and feels. For example - resizing a JSplitPane with metal or nimbus is super fast(as expected), but if you use GTK+ plaf, everything goes to hell. This is a more serious(performance) problem - visual problems(missing borders, components not fitting properly containers, etc) have no end... Despite all of this Swing continues to be one of the best bet for multiplatform desktop applications.

这篇关于为什么 Java Swing 在不同的系统上表现不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆