Solved

Validate input with JTable

Posted on 2003-11-23
3
995 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Suggested Courses

623 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