Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Validate input with JTable

Posted on 2003-11-23
3
Medium Priority
?
999 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
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 step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

721 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