Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #4823

JTable Issues re Insert

From Novice <novice@example..com>
Newsgroups comp.lang.java.gui
Subject JTable Issues re Insert
Date 2011-12-11 14:48 +0000
Organization Your Company
Message-ID <Xns9FB863C60863Cjpnasty@94.75.214.39> (permalink)

Show all headers | View raw


I have a couple of questions about the best approach to use when inserting 
a row to a JTable.

I'm trying to add Insert functionality on a JTable that is displaying a 
very simple table that consists of just two columns, both of which are 
Strings. When I right-click on an existing row, the user gets a popup menu 
that lets him choose "Insert row before current row" and "Insert row after 
current row"; if he chooses the first, a new empty row is inserted before 
the current row and he chooses the other insert, the new row is added after 
the current row. So far, so good.

But I'm struggling with two related issues.
1. How can I make sure that the values in the new row conform to some 
simple rules?
2. How can I make sure that the new row isn't entirely blank in either 
column?

The first column has two follow two rules: it's not allowed to contain any 
tildes (~) and the cell itself can't be completely blank in the sense of 
only having one or more spaces in it. The second column is only prohibited 
from being completely blank. 

I thought I'd solve the first issue by creating two separate editors, one 
on each column. In the first column, keyTyped() and keyPressed() methods 
would be used to make sure no tildes were accepted and another method, 
stopCellEditing(), would make sure the whole field was't blank. Is that 
even close to a reasonable approach? I'd do the same thing in the second 
column's cell editor and just omit the testing for tildes.

Is there any way I can force the user to ensure that there is something 
other than blank in each column before I let him click on any other row? Or 
is it possible for the user to create a new row with empty cells and then 
just move on to another row? 

I'm not sure if I can FORCE the editor to verify that the cells are non-
blank before moving on to another row or if I have to allow for the 
possibility that the row contains non-blank values; in the latter case, 
I'll have to have some kind of logic go through the table before I save it 
to ensure that the user is advised that there are rows containing blank 
cells and asking if he wants to edit them or delete them. 

I'd also like the user to be able to abort an insert. If he gets the popup 
menu, chooses Insert, gets his new all-blank row and then realizes he 
didn't mean to create a row, I want him to have a way to back out of the 
insert and return the table to what it was before the insert. What's the 
best way to do that?
-- 
Novice

Back to comp.lang.java.gui | Previous | Next | Find similar


Thread

JTable Issues re Insert Novice <novice@example..com> - 2011-12-11 14:48 +0000

csiph-web