File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Question about JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Question about JTable" Watch "Question about JTable" New topic
Author

Question about JTable

Adithya Rayaprolu
Ranch Hand

Joined: Jun 19, 2001
Posts: 137
Hi,
When booking flight operation is successful, I would like to change the number of available seats in the JTable. How can I do it? I am using a table model which extends from AbstractTableModel. If I use setValueAt method, it is not getting reflected in the table.
Thanks for any suggestion.
Adithya Rayaprolu
Ranch Hand

Joined: Jun 19, 2001
Posts: 137
I have another doubt regarding JTextField. I want user to input only digits in a text field. I wrote the following code in keyTyped event handler:
if ( char < '0' | | char > '9' )
event.consume();
when I press Backspace, the digits are not getting erased. can somebody help me?
Thanks in advance.
Ravikiran Choppalli
Ranch Hand

Joined: Nov 18, 2000
Posts: 49
For your First Question, I too had some difficulty, so I changed my implementation to Default Table Model. It was quite easy using that. Just needs to update the vector using setDataVector, and then call fireTableDataChanged() method.
For the second question, I feel that the BackSpace keyevent is also getting consumed since it does not fall between '0' and '9'. May be you should not let backspace event to get consumed.
Thanks,
Ravi.


Thanks,<BR>Ravikiran<BR>rkchoppalli@yahoo.com
Trevor Dunn
Ranch Hand

Joined: Jun 13, 2001
Posts: 84
I extended default table model and in the setValueAt(object, int, int) I change the appropiate cell and call fireTableCellUpdated(row, col). This is more effecient than updating the whole table for one column change.
For the Second problem why don't you create your own Document from PlainDocument and override the insertString method. Here you can test the character pressed to see if it is a number or not. I had problems doing the same as you with the KeyEvent listeners, but this solution worked fine for me
Trevor
Devu Shah
Ranch Hand

Joined: Jun 21, 2001
Posts: 50
Originally posted by Adithya Rayaprolu:
I have another doubt regarding JTextField. I want user to input only digits in a text field. I wrote the following code in keyTyped event handler:
if ( char < '0' | | char > '9' )
event.consume();
when I press Backspace, the digits are not getting erased. can somebody help me?
Thanks in advance.

I have employed the following strategy for the above.I have used the Integer.parseInt(txtfeild.getText()) method to get the no of seats. and if user inputs either characters or leaves it empty, then the above method throws the "NumberFormatException"
which i catch and there i give the user the message to enter only integer values.and then i have made the textfeild value
as textfeild.settext("");and then txtfeild.grabFocus so that
focus remains on txtfeild.
 
 
subject: Question about JTable