25 November 2005
Why I Hate Java Swing API ?
I have been developing Java applications professionally since 2000, if you add collage days, it becomes 1998(the old java 1.0 days with strange event model, remember the handleEvent() method? )
I believe Java is a very successful programming language,it has fulfilled all it promised.WORA(Write Once Run Anywhere), garbage collection (no dangling pointers), build-in threading support in the language,several APIs(servlet,jdbc,javamail,jsp,rmi,) making life easier and standadized...It is a perfect fit for building robust, scallable, enterprise level server side applications.
But when it comes to client side, unfortunately things are not the same
Whenever I have to build some GUI using swing, a sudden pain starts in my stomach.
I do totaly understand that swing is an extemely flexible development API with is MVC based architecture, and I agree with this but that's all.In today's world where buzz words like 'abstraction', 'resusability' have great importance, swing is a failure.
What makes swing diffucult to develop is, if you have to develop something more complex that adding a button on a canvas or setting a label's text you need to do lots of lots of tricks.
Suppose you want to make some rows of your table uneditable, suprise! there is no such functionaly, neither JTable not DefaultTableModel has it.Solution?, of course with swing you can do anything.Now you 'just' have to subclass DefaultTableModel, then code your own table model's isCellEditable() function
The same applies if you want to make some columns invisible, you should again introduce a brand new table model class , and aggange getColumnCount() accordingly.
The same story applies for most classes in the API.
The question is: where is abtraction,where is reuseablity? where is rapid application development using the API model. I can not reuse DefaultTableModel even for such simple and basic invisible column/uneditable row needs.
As a concusion java is the superior language for server side development, but for client side development I still miss the Delphi days..