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


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

Inserting and Deleting Rows in a JTable

From Novice <novice@example..com>
Newsgroups comp.lang.java.gui
Subject Inserting and Deleting Rows in a JTable
Date 2011-12-10 00:51 +0000
Organization Your Company
Message-ID <Xns9FB6CA06BB23jpnasty@94.75.214.39> (permalink)

Show all headers | View raw


I have a basic understanding of JTables and have some practice with 
renderers and a bit with editors. Those are fine for displaying existing 
data and changing it. 

But one thing I've never seen discussed in any examples or tutorials I've 
come across is the best approach to inserting new rows and deleting 
existing rows in a JTable. 

I can think of two basic approaches to inserts: 
a) let the user click a button (or right click to get a popup menu that has 
an Insert option) - and let the user specify the new row in a dialog that 
has separate fields (textfields or whatever is more appropriate, like a 
spinner). The dialog would have insert and cancel options in case the user 
changed his mind about the insert.
b) create a new empty row in the JTable itself and let the user type in the 
values directly into the JTable. 

For deletes:
a) let the user click a button (or right click to get a popup menu that has 
a Delete option) - and show the user the row in a dialog with one item per 
field; the dialog would have a delete and a cancel key. Optionally, give 
the user a confirm screen asking if he's sure he wants to delete the data 
which he can abort if he decides against the delete.
b) provide a button on the JTable beside each row which he can click on to 
indicate that this particular row should be deleted. Optionally, display a 
confirm screen to be sure he wants to delete.

Are there any other approaches in use? Does anyone have any sense of which 
seems to be the "best practices" approach?

If 1b and 2b are the preferred solutions, can anyone point me to examples 
of those? I can probably figure them out but it would save time to have an 
example to imitate.....

I already have 1a and 2a working but I suspect 1b and 2b might be more 
elegant.
-- 
Novice

Back to comp.lang.java.gui | Previous | NextNext in thread | Find similar


Thread

Inserting and Deleting Rows in a JTable Novice <novice@example..com> - 2011-12-10 00:51 +0000
  Re: Inserting and Deleting Rows in a JTable Novice <novice@example..com> - 2011-12-10 05:07 +0000
  Re: Inserting and Deleting Rows in a JTable Roedy Green <see_website@mindprod.com.invalid> - 2011-12-10 23:43 -0800
    Re: Inserting and Deleting Rows in a JTable Novice <novice@example..com> - 2011-12-11 18:56 +0000
      Re: Inserting and Deleting Rows in a JTable Novice <novice@example..com> - 2011-12-11 19:09 +0000
      Re: Inserting and Deleting Rows in a JTable Roedy Green <see_website@mindprod.com.invalid> - 2011-12-12 10:13 -0800
        Re: Inserting and Deleting Rows in a JTable Roedy Green <see_website@mindprod.com.invalid> - 2011-12-12 10:27 -0800
          Re: Inserting and Deleting Rows in a JTable Roedy Green <see_website@mindprod.com.invalid> - 2011-12-12 10:45 -0800

csiph-web