• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Jtable CellEditor

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi i have a table t, i fill the table with database query ( 5 column )

textfieldcelleditor = new JTextField();
celleditor = new DefaultCellEditor(textfieldcelleditor);
t.getColumnModel().getColumn(1).setCellEditor(celleditor);

i should have the first column editable if i understood how it works, why it doesnt?


this is the table, but then i fill with a database query
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Editing is controlled by the isCellEditable() method of the TableModel or the JTable. By default when using a DefaultTableModel all cells are editable so I don't know what your problem is.

Post your SSCCE showing the problem.
 
Antony Amicone
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my classes are really big to get easily a SSCCE cause i used netbeans to make dialogs

on the upper post i posted the code related to table.
is it possibile to find the error there??

i think my problem is in CellEditor, dunnow good how to use it

 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Antony Amicone wrote:my classes are really big to get easily a SSCCE cause i used netbeans to make dialogs


Which is hampering your ability to learn Swing. I strongly urge you to do your Swing coding by hand and to study the Swing tutorials, and you won't be having this and your other problems (i.e., in your Dialogs thread).

Just my 2 cents worth.
 
Antony Amicone
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh i know, i usually write dialog by hand, but this time i wanted to try
can you help me with that?
 
Antony Amicone
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


can be here my problem? i tried to change rs. not just to readonly and not insensitive, but is the same
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your table cell is not editable, and you don't know why, the problem is in how you configured the table. Database code could
have absolutely nothing to do with that.
 
Antony Amicone
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:If your table cell is not editable, and you don't know why, the problem is in how you configured the table. Database code could
have absolutely nothing to do with that.


and what is wrong in the table??? i put upside the code but i think is all ok
 
Antony Amicone
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
helpppppppp
 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You've been given plenty of help, but refuse to post a SSCCE so we can't give you anymore help.
 
Antony Amicone
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it takes a lot but hope all is ok now for you to check, heeeeeeeeeeeeeelp me




 
Antony Amicone
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and this is the main class

 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unfortunately that code requires us to be running Netbeans and it requires us to have a MS Access database of a
certain form at a certain place in the root directory of our C drive on our computer which is required to be running
Windows.

There's a lot more stuff in that code which isn't relevant to your question, too.

So if you remove the database access and replace it by hard-coded data, and get rid of all of the Netbeans-related
classes (that's org.desktop.whatever), that would be a good start. All you need to study this problem is a simple class
which has a JTable and nothing else.
 
Antony Amicone
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Unfortunately that code requires us to be running Netbeans and it requires us to have a MS Access database of a
certain form at a certain place in the root directory of our C drive on our computer which is required to be running
Windows.

There's a lot more stuff in that code which isn't relevant to your question, too.

So if you remove the database access and replace it by hard-coded data, and get rid of all of the Netbeans-related
classes (that's org.desktop.whatever), that would be a good start. All you need to study this problem is a simple class
which has a JTable and nothing else.


cant you help me with this code? dont consider the db if is not needed, or i can attach the file
 
Antony Amicone
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i changed the database value with this, and the table allow me editing so the problem is probably in the database... WHERE?!?!?!?!

I changed my Datab class extension, instead of an AbstractTableModel i put DefaultTableModel... and works
is there another way?
 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The database has nothing to do with editing. All the database does is provide data.

Editing is controlled by the isCellEditable() method of the TableModel. When using a DefaultTableModel this method allows all columns to be edited. When extending the AbstractTableModel the default is to not allow editing. So if you want editing you need to implement the method in your custom model.
 
Antony Amicone
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Camick wrote:The database has nothing to do with editing. All the database does is provide data.

Editing is controlled by the isCellEditable() method of the TableModel. When using a DefaultTableModel this method allows all columns to be edited. When extending the AbstractTableModel the default is to not allow editing. So if you want editing you need to implement the method in your custom model.



ok so i just change
public class Datab extends AbstractTableModel {
in
public class Datab extends DefaultTableModel {

and it let me edit, but when i click on one cell it show this error

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 2 >= 0
at java.util.Vector.elementAt(Vector.java:427)
at javax.swing.table.DefaultTableModel.setValueAt(DefaultTableModel.java:648)
at javax.swing.JTable.setValueAt(JTable.java:2719)
at javax.swing.JTable.editingStopped(JTable.java:4721)
at javax.swing.AbstractCellEditor.fireEditingStopped(AbstractCellEditor.java:125)
at javax.swing.DefaultCellEditor$EditorDelegate.stopCellEditing(DefaultCellEditor.java:350)
at javax.swing.DefaultCellEditor.stopCellEditing(DefaultCellEditor.java:215)
at javax.swing.JTable$GenericEditor.stopCellEditing(JTable.java:5475)
at javax.swing.plaf.basic.BasicTableUI$Handler.mousePressed(BasicTableUI.java:986)
at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:263)
at java.awt.Component.processMouseEvent(Component.java:6260)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4235)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)



then when i edit a cell, it continue to be on "edit" till i press ESC, why?

which method should i care bout?
 
Rob Camick
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You haven't posted a proper SSCCE so I don't know the answer and will not bother to answer again until I see a SSCCE.
reply
    Bookmark Topic Watch Topic
  • New Topic