Solved

Validate input with JTable

Posted on 2003-11-23
3
977 Views
Last Modified: 2007-12-19
Hi,

I would like to see an example on how to implement code (with Java version 1.3.1 ) to validate inputs with Table (instance of  defaultTableModel) and store afterward.  My JTable consists of the following columns - TextField, integer, ComboBox.  I can edit table cells.   I have two separated dialogs - (1) to add data to an empty JTable (2) to edit existing data in the JTable and to add new row(s).  

When working with the 1st and 2nd dialogs, adding new table entry-I want to validate my cells - ensure the text field can not excess 200 characters, integer(between 1 to 100), and comboBox(true, false).  

When working with 2nd dialog, I want to be able to detect changes to cells. All columns require to sort.

I will be fetching data from database.  Is defaultTableModel right approch?


Thanks!!
0
Comment
Question by:fcwEx
3 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 240 total points
ID: 9809249
> ensure the text field can not excess 200 characters,

  Just get the size of the string using the length() method.

> integer(between 1 to 100)

  Simply do:

  if (number >= 1 && number <= 100)

> and comboBox(true, false)

  Likewise above. Read the balue and check for true or false.

  if value read equals(true)...

> I want to be able to detect changes to cells.

http://javaalmanac.com/egs/javax.swing.table/AnchorEdit.html

> Is defaultTableModel right approch?

  Depends on your needs. You might need to extend it and write your own table model but for most cases the default table model is sufficient.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now