views:

135

answers:

2

I'm going to make an application (in Swing) that uses a tree to visualize a data structure (JTree). A tree will be on the left side of a window. The user will be able to browse a tree. The parameters of every tree node will be displayed on the right side of the window. The example windows will be looking like this

===========================
| tree panel | data panel |
|            |            |
|            |            |
|            |            |
---------------------------

The problem arises when a user wants to change that data. when should I validate them ? The easy approach is to open a new modal dialog (JDialog) and let the user to change this data in it. Validation of data would take place in an "ok" button listener method but this is a little clunky. I would like to allow the user to edit those data right in the data panel. In that case when should I validate them?

Is there a pattern of such solution in Swing?

Or any online tutorial how to do it?

Thanks in advance.

A: 

I'm not totally sure what you're after, but..

You could maybe add this "ok" button (or "commit changes" or whatever) to data panel and when the button would be pressed, you would validate the data and save the changes if the changes are valid?

(So you'd have editable components at the data panel)

Edit: if this wasn't good, could you clarify me a bit:

  • Is the data panel showing data for one item of the tree at time?
  • What kind of data is there to change (and to validate)

Anyway, if you want to validate straight the changes made to an edit component (for example JTextField), you can use for example

Touko
+1  A: 

Dialogs are bad.

Immediately discard any complete nonsense input immediately. For instance, typing a letter in the numerical field (use Document filters). Don't beep. Don't require any particular commit step. You may have retain partially entered data.

Tom Hawtin - tackline