extended JTable... trying to add a row....

6

6e

Hi, im trying to add a row to my custom Table class

the class extends JTable, and based on its contents, I do not believe
that it can successfully use the defaultTableModel's addRow function
because DefaultTableModel causes my application to crash when trying to
insert a JComboBox into one of its cells.

However I am desperately trying to add a row to my JTable using
TableModel.... does anyone have any idea where I may be able to find
help...?


Thanks!
 
O

Oliver Wong

6e said:
Hi, im trying to add a row to my custom Table class

the class extends JTable, and based on its contents, I do not believe
that it can successfully use the defaultTableModel's addRow function
because DefaultTableModel causes my application to crash when trying to
insert a JComboBox into one of its cells.

However I am desperately trying to add a row to my JTable using
TableModel.... does anyone have any idea where I may be able to find
help...?

Here might be a good place, as long as you divulge enough information
that people can make educated guesses as to what the problem actually is.
Ways of providing that information include:

* Posting an SSCCE (http://www.physci.org/codes/sscce.jsp)
* Posting the exact error message (don't paraphrase), if appropriate.
* If the error message mentions a specific line in the source code, it
might help show that line, plus relevant surrounding code so that we can
make sense of the line.

- Oliver
 
R

Roedy Green

causes my application to crash when trying to
insert a JComboBox into one of its cells.

Seems to me you or someone else asked this exact same question. When
you get two threads going on the same question, you lose focus and
coherence.
 
Z

zero

Hi, im trying to add a row to my custom Table class

the class extends JTable, and based on its contents, I do not believe
that it can successfully use the defaultTableModel's addRow function
because DefaultTableModel causes my application to crash when trying to
insert a JComboBox into one of its cells.

However I am desperately trying to add a row to my JTable using
TableModel.... does anyone have any idea where I may be able to find
help...?


Thanks!

Adding a JComboBox to a JTable should be very simple. Something like this:


JTable table;
// ... create and populate the table

JComboBox comboBox;
// ... create and populate the JComboBox

TableColumn column = table.getColumnModel().getColumn(0);
column.setCellEditor(new DefaultCellEditor(comboBox));


This way the JComboBox will be used to edit the 1st column of your JTable -
every time the user clicks the cell to edit it, the combobox will be
displayed.
 
Z

zero

Adding a JComboBox to a JTable should be very simple. Something like
this:


JTable table;
// ... create and populate the table

JComboBox comboBox;
// ... create and populate the JComboBox

TableColumn column = table.getColumnModel().getColumn(0);
column.setCellEditor(new DefaultCellEditor(comboBox));


This way the JComboBox will be used to edit the 1st column of your
JTable - every time the user clicks the cell to edit it, the combobox
will be displayed.

btw if your application crashes when adding a row, there is something very
wrong. If the above doesn't solve your problem, try posting a code snippet
and the stack trace.
 
R

Roedy Green

btw if your application crashes when adding a row,

Dumps an exception with a stack trace is not the same as crashing. If
you get such a trace it gives you many more clues than you get in a
crash.
 
6

6e

my issue is not getting the jcombobox into the table...

my issue is creating a new row when the previous last row was filled
in...
 
Z

zero

my issue is not getting the jcombobox into the table...

my issue is creating a new row when the previous last row was filled
in...

Try posting a code snippet. Without code I can't see where you're going
wrong. Adding a row should be as simple as:

Object[] data;
// ... fill data
((DefaultTableModel)table.getModel()).addRow(data);

If the cell editor for the column is already correctly set (cfr my previous
post), it will be used automatically in the combobox column.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top