Search code examples
javaperformanceswingjtextcomponent

Improving performances of JTextField


Title itself sounds strange but i wanted to see if there's actual way of improving performances of "setText" method of regular Java JTextField.

I have app that's used for calculating some scientific data. Results of the calculation are being presented in Swing window that contains tabs with total of 1815 different JTextField controls. I do need JTextField because results should be editable. I noticed that a lot of "processing results" time goes to internal workings of "setText" method. Looking at JTextComponent source code i assume it's because of underlying "AbstractDocument".

As i would like to improve speed of presenting calculated results to my user, is there a way to make JTextField perform faster (most notably it's "setText" method)?


Solution

  • Those fields are grouped into separate frames in order to be more visual appealing and distinguishable.

    Seriously. A user will not be able to view 1815 components at a single time an observe there behaviour especially if the value of all of them are changing at once.

    Maybe a single table can't be used for all the text fields, but I'm sure you can structure some of the data into tables.

    I do need JTextField because results should be editable.

    I suspect some processing is related to the text field generating events whenever the text is changed. For example DocumentEvents and UndoableEditEvents.

    So, maybe use a JLabel to display the data and then to edit you double click and use a popup JTextField to enter the data into the label.

    creating a custom JTextField that's not using AbstractDocument but plain String?

    Instead of using a PlainDocument as the implemtation of the AbstractDocument you could create your own simpler Document implementation without the full overhead of the PlainDocument.