Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Java Swing behaves different on different systems?

Tags:

java

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.

like image 584
The Student Avatar asked Feb 27 '23 04:02

The Student


1 Answers

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.

like image 73
Bozhidar Batsov Avatar answered Mar 05 '23 18:03

Bozhidar Batsov