• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem clicking jbuttons in jtable

 
sohaib maroof
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all m unable to press jbutton in jtable which i have created through render and editor please have a look and tell me where i went wrong ......button in jtabe are not working .they are supposed to delete and update the particular row when they are pressed .here is my code






 
Rob Camick
Ranch Hand
Posts: 2534
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try using: Table Button Column
 
sohaib maroof
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried this but i didn't figured it out how to enable jbuttons in jtable to get clicked. when i click on them i got -1 as row no and -1 as column no . how can i set it right any one tell me please m stuck
 
Rob Camick
Ranch Hand
Posts: 2534
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried this but i didn't figured it out how to enable jbuttons in jtable to get clicked.


Use the DefaultTableModel. All cells are editable by default.

Otherwise you need to override the isCellEditable(...) method of the TableModel to return true.
 
sohaib maroof
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i m using defaultTableModel the problem is when i click on any row in jtable i get its column n row number but when i press on button i get -1-1 means its not getting pressed now postpartum another program i hope i get it from it what i want .
when the compiler comes to that point i get out of bound exception -1
 
Rob Camick
Ranch Hand
Posts: 2534
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I gave you working code that deletes a row.

If you need more help post your SSCCE.

 
sohaib maroof
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i do not know your site do not let me attach rar file .how should i attach my code?
 
Rob Camick
Ranch Hand
Posts: 2534
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We don't want a .rar file or your application. We want a SSCCE.

Your SSCCE will be about 20 lines of code.

It will take a couple of lines of code to built a JTable with a few rows of data in it.

It will take a couple of lines of code to create an Action that displays the data in the row clicked.

Its takes one line of code to add the button editor to the column. (if somebody wants to test it, they will need to download the ButtonColumn class from the link given above).

It will take a few more line of code to create the Jframe and add the table to it.


 
sohaib maroof
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi can you please run my program in your netbeans please download my code from this link i will be very thank full to you http://www.megaupload.com/?d=TB719I1D
 
sohaib maroof
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you look at my code you will see its not deleting the particular code where as it should
 
sohaib maroof
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i get this error when i press on delete button
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: -1
at java.util.Vector.removeElementAt(Vector.java:558)
at javax.swing.table.DefaultTableModel.removeRow(DefaultTableModel.java:463)
at com.company.librarySystem.bm.ui.NewJFrame.selectedCol(NewJFrame.java:59)
at com.company.librarySystem.bm.ui.ButtonEditor.buttonPressed(ButtonEditor.java:62)
at com.company.librarySystem.bm.ui.ButtonEditor.getTableCellEditorComponent(ButtonEditor.java:23)
at javax.swing.JTable.prepareEditor(JTable.java:5790)
at javax.swing.JTable.editCellAt(JTable.java:3515)
at javax.swing.plaf.basic.BasicTableUI$Handler.adjustSelection(BasicTableUI.java:1108)
at javax.swing.plaf.basic.BasicTableUI$Handler.mousePressed(BasicTableUI.java:1038)
at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:280)
at java.awt.Component.processMouseEvent(Component.java:6501)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6269)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4860)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4489)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2713)
at java.awt.Component.dispatchEvent(Component.java:4686)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:680)
at java.awt.EventQueue$4.run(EventQueue.java:678)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
BUILD SUCCESSFUL (total time: 35 seconds)
please help me for GOD sake
 
sohaib maroof
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any one here
 
Rob Camick
Ranch Hand
Posts: 2534
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please help me for GOD sake


You get what you give.

You haven't given us a SSCCE to work with!!!
 
sohaib maroof
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok here i have shorten the code .my code resembles this code



please now help me it should delete the row i created to type of methods in it ti delete row but not able to delete it
 
sohaib maroof
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
help
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PatienceIsAVirtue.
 
Rob Camick
Ranch Hand
Posts: 2534
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not going to debug your custom renderer and editor. It is not an easy task to create these classes.

I already gave you a link to my blog which has a working renderer/editor which took me days to get working by looking at various solutions posted around the web. The blog even gives code for deleting a row when using this class.

My patience has run out!
 
sohaib maroof
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i dont what i did that ran your patient out . anyways thanks for help
 
Rob Camick
Ranch Hand
Posts: 2534
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont what i did that ran your patient out


You ask for help.

I gave you working code.

You ignore working code!
 
sohaib maroof
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i told you i used this code and its not working for me why would i ignore it .i do not know how to use the code in given in this site . for you editing my code isn't a big issue yet you not doing it but its your call i cant force you to edit my code .thanks anyways
 
Rob Camick
Ranch Hand
Posts: 2534
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i told you i used this code and its not working for me


So why would I post code that isn't working? Do you think the problem might be your code? I suggested you post a SSCCE showing how you used this code. I even outlined the steps needed to produce the SSCCE.

You didn't post the SSCCE. Instead you added some more verbal description which didn't help. You then complained that nobody was helping.

I again asked for the SSCCE and you posted a SSCCE using your old code. I'm tired of making suggestion 2/3 times!!!

Good luck with your next question.
 
Paul Clapham
Sheriff
Pie
Posts: 20719
30
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is your problem?

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: Array index out of range: -1
at java.util.Vector.removeElementAt(Vector.java:558)
at javax.swing.table.DefaultTableModel.removeRow(DefaultTableModel.java:463)
at com.company.librarySystem.bm.ui.NewJFrame.selectedCol(NewJFrame.java:59)

Then renderers and editors have nothing to do with it. This just means that your code called the removeRow() method of DefaultTableModel and passed it a row number which wasn't in the table. The bottom line in that stack trace fragment indicates which line of your code was at fault. Start debugging there.
 
sohaib maroof
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you i am checking on it and tell you how it went
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic