Solved

Validate input with JTable

Posted on 2003-11-23
3
976 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This video teaches viewers about errors in exception handling.

760 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

18 Experts available now in Live!

Get 1:1 Help Now