0

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)?

guest86
  • 2,894
  • 8
  • 49
  • 72
  • What is JTextBox? I know only J(Formatted)TextField, JTextArea, and JTextPane. – Sergiy Medvynskyy Oct 25 '16 at 12:49
  • How do you have this threaded? Is anything listening to the `JTextField`s? – bradimus Oct 25 '16 at 12:53
  • Sorry, you are right, it's "JTextField". Edited my question not now. – guest86 Oct 25 '16 at 12:57
  • No, it's not threaded. It only have some code to validate user input (so nobody can enter characters for example). – guest86 Oct 25 '16 at 12:58
  • 4
    _"Swing window that contains tabs with total of 1815 different JTextField controls"_ why don't you use a JTable for that? – Timothy Truckle Oct 25 '16 at 13:10
  • Well it's not bunch of table-like components. Those fields are grouped into separate frames in order to be more visual appealing and distinguishable. – guest86 Oct 25 '16 at 13:12
  • 1
    Try to fill the text fields in the tab only when user make the tab active. – Sergiy Medvynskyy Oct 25 '16 at 13:20
  • 2
    "1815 different JTextField controls..." Steve Jobs, if he were alive, would not approve – ControlAltDel Oct 25 '16 at 13:42
  • @Sergiy yes, that's one option. Would it be worth (just as another option) creating a custom JTextField that's not using AbstractDocument but plain String? What about that? – guest86 Oct 25 '16 at 13:49
  • 1
    @guest86 No it's not an option, because `JTextField` **is designed to use a Document** – Sergiy Medvynskyy Oct 25 '16 at 14:00
  • 1
    *"Those fields are grouped into separate frames in order to be more visual appealing and distinguishable."* It's likely the user would prefer a functional but plain app. to ..whatever this will result in. See also [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Oct 25 '16 at 14:52
  • Just out of curiosity: Could you show a screenshot? Because 1815 sounds like a lot to visually process for a user. – hamena314 Oct 26 '16 at 08:41

1 Answers1

2

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.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • Ok, i'll have to go with custom document and hope it will solve the problem. Also, i'll add loading per tab :) Thanks – guest86 Oct 28 '16 at 16:29