Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Validate input with JTable

Posted on 2003-11-23
3
Medium Priority
?
1,003 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 960 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

927 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