Note that there are some explanatory texts on larger screens.

plurals
  1. POcell with a button is not treated as a selected cell in java
    primarykey
    data
    text
    <p>i have a column(7),there is a button and the action is just to delete the row.and i have also mouseclick event to the table.i want when user click the delete button it will delete the row and some other stuff getting the selected cell value.my delete action works fine but when i clicked the button a exception is thrown but when i click on the other cell in the same row it gives me proper row and column data.i don't understand the actual problem.does the button is not treated as a cell clicked like the other cells in the same row...? here is my main constructor</p> <pre><code> public SellWindow() { //dafault constructor String title[]={"Qty","Code","Name","vat","Discount","Unit Value","Line Total","Delete"}; table.setColumnIdentifiers(title); this.entry.setModel(table); //entry is the jtable //entry.getColumn("Delete"); ButtonColumn buttonColumn = new ButtonColumn(entry, delete,7); buttonColumn.setMnemonic(KeyEvent.VK_D); } </code></pre> <p>here is my button class</p> <pre><code> public ButtonColumn(JTable table, Action action, int column) { this.table = table; this.action = action; renderButton = new JButton(); editButton = new JButton(); editButton.setFocusPainted( false ); editButton.addActionListener( this ); originalBorder = editButton.getBorder(); setFocusBorder( new LineBorder(Color.BLUE) ); TableColumnModel columnModel = table.getColumnModel(); columnModel.getColumn(column).setCellRenderer( this ); columnModel.getColumn(column).setCellEditor( this ); table.addMouseListener( this ); } </code></pre> <p>here is my code for delete action</p> <pre><code> Action delete = new AbstractAction(){ public void actionPerformed(ActionEvent e){ JTable table = (JTable)e.getSource(); int modelRow = Integer.valueOf( e.getActionCommand() ); ((DefaultTableModel)table.getModel()).removeRow(modelRow); getIndexRow(); // i add this here just to check but same exception } }; </code></pre> <p>here is my code for table clicked</p> <pre><code> private void entryMouseClicked(java.awt.event.MouseEvent evt) { getIndexRow(); } </code></pre> <p>here is my code for getting table data</p> <pre><code> private void getIndexRow(){ //this works fine for other cells but not for the cell holding the delete button int row=entry.getSelectedRow(); Object o=entry.getModel().getValueAt(row,6); System.out.println(row); System.out.println((String)o); } </code></pre> <p>and here is the code for inserting row(product info by clicking aenter button)</p> <pre><code> private void addItemActionPerformed(java.awt.event.ActionEvent evt) { // this is the action performed by pressing the add item button result=p.getInfo(this.addItemField.getText()); for(String s:result){ data[i]=s; i+=1; } data[0]="1"; quantity=Integer.parseInt(data[0]); price=Integer.parseInt(data[5]); int tPrice=price*quantity; total=tPrice+total; ItemTotal +=1; Itotal.setText(Integer.toString(ItemTotal)); showTotal.setText(Integer.toString(total)); data[6]=Integer.toString(tPrice); table.addRow(data); this.addItemField.grabFocus(); addItemField.setText(""); } </code></pre> <p>exceptions </p> <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1 at java.util.Vector.elementData(Vector.java:730) at java.util.Vector.elementAt(Vector.java:473) at javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:649) at SellWindow.getIndexRow(SellWindow.java:581) at SellWindow.access$000(SellWindow.java:26) at SellWindow$2.actionPerformed(SellWindow.java:49) at ButtonColumn.actionPerformed(ButtonColumn.java:190) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) at java.awt.Component.processMouseEvent(Component.java:6505) at javax.swing.JComponent.processMouseEvent(JComponent.java:3321) at java.awt.Component.processEvent(Component.java:6270) at java.awt.Container.processEvent(Container.java:2229) at java.awt.Component.dispatchEventImpl(Component.java:4861) at java.awt.Container.dispatchEventImpl(Container.java:2287) at java.awt.Component.dispatchEvent(Component.java:4687) at javax.swing.plaf.basic.BasicTableUI$Handler.repostEvent(BasicTableUI.java:948) at javax.swing.plaf.basic.BasicTableUI$Handler.mouseReleased(BasicTableUI.java:1164) at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:290) at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289) at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289) at java.awt.Component.processMouseEvent(Component.java:6505) at javax.swing.JComponent.processMouseEvent(JComponent.java:3321) at java.awt.Component.processEvent(Component.java:6270) at java.awt.Container.processEvent(Container.java:2229) at java.awt.Component.dispatchEventImpl(Component.java:4861) at java.awt.Container.dispatchEventImpl(Container.java:2287) at java.awt.Component.dispatchEvent(Component.java:4687) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422) at java.awt.Container.dispatchEventImpl(Container.java:2273) at java.awt.Window.dispatchEventImpl(Window.java:2719) at java.awt.Component.dispatchEvent(Component.java:4687) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:703) at java.awt.EventQueue.access$000(EventQueue.java:102) at java.awt.EventQueue$3.run(EventQueue.java:662) at java.awt.EventQueue$3.run(EventQueue.java:660) 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:676) at java.awt.EventQueue$4.run(EventQueue.java:674) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:673) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139) at java.awt.EventDispatchThread.run(EventDispatchThread.java:97) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload