• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S: Booking Contractor / Swing Qs

 
Jack Gold
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
My server is nearly finished and I've decided to move on to the client development. I am a Swing novice and was wondering if it would meet the requirements to use an editable field in the JTable to allow user to input a customer ID?

This seems almost too simple; the UI would consist of a JTable with editable cutomerID field and a TextBox/Button for search.

Any advice on best way to meet booking requirements?
 
David Sham
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Making the JTable editable with editable text fields may be more challenging than it seems. If you do it that way (which is possible), then you get into dealing with table cell editing and rendering in the JTable. That can get confusing. You have to know when to stop editing the table cell, and how to handle cases such as the user hitting the escape key while editing the table. You have to know when to accept or reject values being edited. Value validation (which should be done regardless) would become part of this approach as well. It can get messy.

An easier alternative to having an editable table is to make the table non-editable and update it with values the user provides via a separate JTextFfield in the UI. When the user specifies a value in a text field (outside the table), take that value and update the table's model with it and call JTable.repaint(). You can also add a button to click which would add the value from the text field. This is how I designed my GUI.
 
Jack Gold
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David, thanks for your insight.

If I am to use the strategy you outlined, I assume there is some way to get the currently selected row from the JTable?

Edit: I'll figure it out. Thanks.
[ May 20, 2005: Message edited by: Jack Gold ]
 
David Sham
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just check the javax.swing.JTable API doc for JTable. Also look at TableModel.java in the API doc.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic