Delete multiple rows in jtable
here's what i want to do
let user select the rows themselves and then when they press delete button, the rows that they select are removed
however, I do not have any idea on how to go about doing that though, like how do I get the selection value (sometimes it may be one whole chunk, sometimes it might be at different places altogether)
but the problem comes in after sorting the row;Are we supposed to be mind readers? How where we supposed to guess that the problem was related to sorting based on your original question. Learn to ask a proper question so you don't waste our time.
Anyway you still haven't given us enough information to help you.
Are you using the sorting feature of JDK6, in which case the API has methods that allow you to convert the "view" row to the "model" row. So I suggest you read the API.
Similar Messages
-
How do i delete multiple rows in JTable
hello
how i delete multiple rows in JTable
when i selected multiple rows from the jtable and delete its give the error ArrayIndexOutOfBoundException
e.g.
int rows[]=jtable.getSelectedRows();
for(int i=0;i<rows.length;i++)
DefaultTableModel model=(DefaultTableModel)jtable.getModel();
model.removeRow(rows);
like this
please help me
merajYou are trying to remove the rows an equal times to the amount of rows selected.
You should remove one row at a time:
model.removeRow(rows);
Change your code into this.
for(int i=0;i<rows.length;i++)
DefaultTableModel model=(DefaultTableModel)jtable.getModel();
model.removeRow(rows[i]); -
Delete Multiple Rows of JTable by selecting JCheckboxes
Hi,
I want delete rows of JTable that i select through JCheckbox on clicking on JButton. The code that i am using is deleting one row at a time. I want to delete multiple rows at a time on clicking on Button.
This is the code i m using
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
public class TableTest extends JFrame implements ActionListener
JButton btnAdd;
BorderLayout layout;
DefaultTableModel model;
JTable table;JButton btexcluir;
public static void main(String[] args)
TableTest app = new TableTest();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
public TableTest()
super("Table Example");
btnAdd = new JButton("Add");
btnAdd.addActionListener(this);
model = new DefaultTableModel()
public Class getColumnClass(int col)
switch (col)
case 1 :
return Boolean.class;
default :
return Object.class;
table = new JTable(model);
table.setPreferredSize(new Dimension(250,200));
// Create a couple of columns
model.addColumn("Col1");
model.addColumn("Col2");
JCheckBox cbox = new JCheckBox();
// Append a row
JPanel painel = new JPanel();
model.addRow(new Object[] { "v1",new Boolean(false)});
model.addRow(new Object[] { "v3", new Boolean(false)});
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.createVerticalScrollBar();
btexcluir= new JButton("Excluir");
btexcluir.addActionListener(this);
painel.add(btexcluir);
painel.add(btnAdd);
getContentPane().add(scrollPane, BorderLayout.NORTH);
getContentPane().add(painel, BorderLayout.SOUTH);
setSize(600, 600);
setVisible(true);
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnAdd)
model.addRow(new Object[] { "Karl", new Boolean(false)});
if (e.getSource()==btexcluir){
for (int i=0; i <=model.getRowCount(); i++){
if (model.getValueAt(i,1)==Boolean.FALSE)
JOptionPane.showMessageDialog(null, "No lines to remove!!");
else if(model.getValueAt(i,1)==Boolean.TRUE)
model.removeRow(i);
}Please reply me with code help.
Thanks
NitinHi,
Thanks for ur support. My that problem is solved now. One more problem now . Initially i want that delete button disabled. When i select any checkbox that button should get enabled. how can i do that ?
Thanks
Nitin -
Delete multiple rows in a JTable ADF Swing.
hi guys,
Would anyone know tell me how do I delete multiple rows in a JTable ADF Swing?
JDeveloper.Hi,
I would configure the table for multi row selection. Then get the selected row index, access the iterator in the PageDef file (through the panelBinding reference you have in ADF Swing) and then iterate over the selected row indexes, make an index to become the current row and call remove() on it
Frank -
How to delete multiple rows from ADF table
How to delete multiple rows from ADF table
Hi,
best practices when deleting multiple rows is to do this on the business service, not the view layer for performance reasons. When you selected the rows to delete and press submit, then in a managed bean you access thetable instance (put a reference to a managed bean from the table "binding" property") and call getSeletedRowKeys. In JDeveloper 11g, ADF Faces returns the RowKeySet as a Set of List, where each list conatins the server side row key (e.g. oracle.jbo.Key) if you use ADF BC. Then you create a List (ArrayList) with this keys in it and call a method exposed on the business service (through a method activity in ADF) and pass the list as an argument. On the server side you then access the View Object that holds the data and find the row to delte by the keys in the list
Example 134 here: http://blogs.oracle.com/smuenchadf/examples/#134 provides you with the code
Frank -
Best practice for deleting multiple rows from a table , using creator
Hi
Thank you for reading my post.
what is best practive for deleting multiple rows from a table using rowSet ?
for example how i can execute something like
delete from table1 where field1= ? and field2 =?
Thank youHi,
Please go through the AppModel application which is available at: http://developers.sun.com/prodtech/javatools/jscreator/reference/codesamples/sampleapps.html
The OnePage Table Based example shows exactly how to use deleting multiple rows from a datatable...
Hope this helps.
Thanks,
RK. -
I followed following link: http://www.oracle.com/technetwork/developer-tools/adf/learnmore/99-checkbox-for-delete-in-table-1539659.pdf
but when i delete multiple rows i got following error.
Object duplicateRowSet of type View Row Set already exists.
Thanks for Advance
Edited by: 875688 on Apr 9, 2012 5:02 AMIt works always :
DCBindingContainer binding=(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding iterator=binding.findIteratorBinding(iteratorName);
ViewObjectImpl vo=(ViewObjectImpl)iterator.getViewObject();
Vector vector=new Vector();
for(int i=0;i<vo.getRowCount();i++)
Row row=vo.getRowAtRangeIndex(i);
if(row.getAttribute("IsSelect")!=null)
if((Boolean)row.getAttribute("IsSelect")==true)
vector.add(row);
Row[] rows=new Row[vector.size()];
for(int i=0;i<vector.size();i++)
rows=(Row)vector.get(i);
if(rows.length>0)
for(int i=0;i<rows.length;i++)
rows[i].remove(); -
Updating and deleting multiple rows
Hi!
I have a form on a table with report page where I can filter data through columns.
1. Is it possible to create a button that will delete all the filtered data?
2. Also, I would like to be able to update any column of the filtered dataset to a certain value (that needs to be input somehow). Is that possible?
So far I can only update or delete one row at a time, which isn't useful as I sometimes need to change 100 rows at a time with the same value or delete them.
When I use tabular form, I can't filter rows, but I can delete multiple rows...
Also if there are similar examples, could you please send me a link; I can't seem to find any.
I'm using Apex 4.2.2.
Best Regards,
IvanDeleting multiple rows - [url https://forums.oracle.com/forums/thread.jspa?threadID=2159983]common question
Best answered with Martin's example
http://www.talkapex.com/2009/01/apex-report-with-checkboxes-advanced.html
Depends how you filter your data. You could identify all your limiting variables, and reverse the where clause in a delete process.
As for point 2, you can define a button that redirects to the page, and you can defined all the item values you like using the Action link.
There is likely an example in the supplied package applications.
Scott -
Deleting Multiple Rows From Multiple Tables As an APEX Process
Hi There,
I'm interesting in hearing best practice approaches for deleting multiple rows from multiple tables from a single button click in an APEX application. I'm using 3.0.1.008
On my APEX page I have a Select list displaying all the Payments made and a user can view individual payments by selecting a Payment from the Select List (individual items are displayed below using Text Field (Disabled, saves state) items with a source of Database Column).
A Payment is to be deleted by selecting a custom image (Delete Payments Button) displayed in a Vertical Images List on the same page. The Target is set as the same page and I gave the Request a name of DELETEPAY.
What I tried to implement was creating a Conditional Process On Submit - After Computations and Validations that has a source of a PL/SQL anonymous block as follows:
BEGIN
UPDATE tblDebitNotes d
SET d.Paid = 0
WHERE 1=1
AND d.DebitNoteID = :P7_DEBITNOTEID;
INSERT INTO tblDeletedPayments
( PaymentID,
DebitNoteID,
Amount,
Date_A,
SupplierRef,
Description
VALUES
( :P7_PAYMENTID,
:P7_DEBITNOTEID,
:P7_PAID,
SYSDATE,
:P7_SUPPLIERREF,
:P7_DESCRIPTION
DELETE FROM tblPayments
WHERE 1=1
AND PaymentID = :P7_PAYMENTID;
END;
The Condition Type used was Request = Expression 1 where Expression 1 had a value of DELETEPAY
However this process is not doing anything!! Any insights greatly appreciated.
Many thanks,
Gary....the "button" is using a page level Target,...
I'm not sure what that means. If the target is specified in the definition of a list item, then clicking on the image will simply redirect to that URL. You must cause the page to be submitted instead, perhaps by making the URL a reference to the javaScript doSubmit function that is part of the standard library shipped with Application Express. Take a look at a Standard Tab on a sample application and see how it submits the page using doSubmit() and emulate that.
Scott -
Deleting multiple rows in a report ?
db11gxe , apex 4.0 , firefox 24 ,
how to delete multiple rows in a report at one time ?
thanksHi newbi_egy,
Here is a small demo with few steps that can be used in your scenario-
1) Below is the query of a report on emp table which has empno column with unique values-
SELECT APEX_ITEM.CHECKBOX(1,empno) " ", ename, job FROM emp ORDER by 1
2) A Delete button is created that submits the page.
3) An on-submit process is created with Process point On Submit - After Computation and Validations with condition that the below process runs when Delete button clicked.
BEGIN
FOR i in 1..APEX_APPLICATION.G_F01.count
LOOP
delete from emp where empno=APEX_APPLICATION.G_F01(i);
END LOOP;
END;
I hope this might help you.
Regards,
Das123 -
Adding and Deleting Multiple Rows or Columns
How do you add or delete more than one row or column at a time.
Robby! wrote:
That's a great finding!
I just wrote a feedback requesting a shortcut like this.
It is a pity though that they desing it to work only if you select the header of the row/column. It should be enabled to work from within any cell in the table.
Who wrote such an error ?
These interesting shortcuts behave flawlessly even if the cursor was in D18 for instance.
(a) I never saw them in the delivered resources.
(b) they aren't responding to the OP's question which was about "Adding and Deleting Multiple Rows and Columns"
Yvan KOENIG (from FRANCE vendredi 3 octobre 2008 18:39:01) -
DELETE MULTIPLE ROWS FROM MATRIX
Hi all,
I´M DESPERATED.
I am able to delete row by row in my matrix, but ¿Could anyone post a sample to delete multiple rows?
I´ve been trying several ways but it doesn´t work.
My code is:
========================
Dim i As Long = oMatrix.GetNextSelectedRow
If i > -1 Then
If oMatrix.IsRowSelected(i) = True Then
oMatrix.DeleteRow(i)
End If
========================
Thank you in advanced,
lorenzoDon´t worry, It was a problem with my loop.
Thanks anyway
lorenzo -
I am trying to delete a row from a JTable whenever the button on the last column is pressed. I know to do this, I can use the removeRow(int) method of the tableModel. But the odd thing is when I try to get a handle to the TableModel from the JTable to use that function, i.e. table.getModel().removeRow(int) it doesn't work. But if I explicitly pass in the tableModel into my class it does work. Here's the code below:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.UIManager;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableCellEditor;
import javax.swing.AbstractCellEditor;
import javax.swing.table.DefaultTableModel;
public class tester4 extends JFrame
protected final int BUTTON_COL = 2;
private TableCellRenderer defaultRenderer;
private TableCellEditor defaultEditor;
private JTable workingTable;
private String[] transactionCols = {"Qty", "Product", "Cancel"};
private Object[][] data = {{5, "prod1", "Cancel"},
{6, "prod2", "Cancel"},
{7, "prod3", "Cancel"}};
public tester4()
workingTable = new JTable(tableModel);
workingTable.setName("Working Table");
defaultRenderer = workingTable.getDefaultRenderer(JButton.class);
defaultEditor = workingTable.getDefaultEditor(Object.class);
StatusTableRenderer testRenderer = new StatusTableRenderer(defaultRenderer, defaultEditor, workingTable, tableModel);
workingTable.setDefaultRenderer(Object.class, testRenderer);
workingTable.setDefaultEditor(Object.class, testRenderer);
JScrollPane scrollPane = new JScrollPane( workingTable );
getContentPane().add( scrollPane );
private DefaultTableModel tableModel = new DefaultTableModel(data, transactionCols){
// Only allow button column to be editable, if there is an actual
// button in that row
public boolean isCellEditable(int row, int col){
return (col == BUTTON_COL && data[row][col] != "") ? true : false;
// Overriden getColumnClass method that will return the object
// class type of the first instance of the data type otherwise
// returns the Object.class
public Class getColumnClass(int column){
for (int row = 0; row < getRowCount(); row++){
Object o = getValueAt(row, column);
if (o != null){ return o.getClass(); }
return Object.class;
public static void main(String[] args)
tester4 frame = new tester4();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setVisible(true);
public class StatusTableRenderer extends AbstractCellEditor
implements TableCellRenderer,
TableCellEditor,
ActionListener{
private TableCellRenderer defaultRenderer;
private TableCellEditor defaultEditor;
private JButton cancelButton;
private JButton editButton;
private String text;
private int buttonColumn;
private int selectedRow;
private JTable table;
private DefaultTableModel tableModel;
public StatusTableRenderer(TableCellRenderer renderer,
TableCellEditor editor,
JTable table,
DefaultTableModel tableModel){
defaultRenderer = renderer;
defaultEditor = editor;
this.table = table;
this.tableModel = tableModel;
buttonColumn = table.getColumnCount() - 1;
cancelButton = new JButton();
editButton = new JButton();
editButton.setFocusPainted(true);
editButton.addActionListener(this);
public StatusTableRenderer(TableCellRenderer renderer,
TableCellEditor editor,
JTable table,
DefaultTableModel tableModel,
int _buttonColumn){
this(renderer, editor, table, tableModel);
buttonColumn = _buttonColumn;
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
if (column == buttonColumn){
if (hasFocus){
cancelButton.setForeground(table.getForeground());
cancelButton.setBackground(UIManager.getColor("Button.background"));
else if (isSelected){
cancelButton.setForeground(table.getSelectionForeground());
cancelButton.setBackground(table.getSelectionBackground());
else{
cancelButton.setForeground(table.getForeground());
cancelButton.setBackground(UIManager.getColor("Button.background"));
cancelButton.setText( (value == null) ? "" : value.toString() );
return cancelButton;
return defaultRenderer.getTableCellRendererComponent(
table, value, isSelected, hasFocus, row, column);
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int row, int column){
if (column == buttonColumn){
text = ((value == null) ? "": value.toString());
editButton.setText(text);
selectedRow = row;
return editButton;
return defaultEditor.getTableCellEditorComponent(
table, value, isSelected, row, column);
public Object getCellEditorValue()
return text;
public void actionPerformed(ActionEvent e)
fireEditingStopped();
// This works
tableModel.removeRow(selectedRow);
// This does not work
// table.getModel().removeRow(selectedRow);
}Take a look at the actionPerfformed method. One way of doing it works, one doesn't. Just trying to understand why me getting a handle to the tableModel through the table doesn't work.
Message was edited by:
deadseasquirrelsIt gives me a run-time error Well then your question should be "why do I get this run-time error" and then you would quote the error. Be more descriptive. "It doesn't work" is not descriptive.
table.getModel().removeRow(selectedRow);I don't use JDK1.5 either. But if you are saying that the above line compiles cleanly with JDK1.5 (because of the auto-boxing feature, or whatever its called), then I see no reason why the code wouldn't work since it recognizes the class as a DefaultTableModel.
Presumably you commented out the other line so you don't try to delete the row twice. Otherwise you might be getting a indexing error. -
Delete multiple rows from table/list control
Hi,
I want to have a table control in which a user can enter different entries, like this:
My program would read each entry at a time and do something.
However, I would like to give the user ability to delete multiple entries at once, like in an Excel spreadsheet - that is, the user selects multiple rows and presses "Delete" key and those entries get deleted. The Labview table does not allow this it seems - I can only delete one entry at a time - or I have to right-click and select Data Operations->Cut Data, which is awkward.
Is there a control better suited to what I want to do? I tried a Llist control, but it behaves in the same manner.
Thanks in advance!
Solved!
Go to Solution.You could write your own routine. Use an Event Structure with a Key Down event. If the delete key was pressed and the table has focus delete the elements that are selected.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines -
Problem of deletion of rows in jtable, table refreshing too
Hi,
I have a table with empty rows in the beginning with some custom properties( columns have fixed width...), later user would be adding to the rows to this table and can delete, I've a problem while deleting the rows from table,
When a selected row is deleted the model is also deleting the data but the table(view) is not refreshed.
Actually i'm selecting a cell of a row, then hitting the delete button.
So the model is deleting the information, but i'm not able to c the fresh data in table( especially when the last cell of last row is selectd and hit the delete button, i am getting lots of exception)
Kindly copy the below code and execute it, and let me know,
* AuditPanel.java
* Created on August 30, 2002, 3:05 AM
import javax.swing.*;
import java.awt.*;
import javax.swing.table.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.util.Vector;
* @author yaman
public class AuditPanel extends javax.swing.JPanel {
// These are the combobox values
private String[] acceptenceOptions;
private Vector colNames;
private Color rowSelectionBackground = Color.yellow;
private int rowHeight = 20;
private int column0Width =70;
private int column1Width =96;
private int column2Width =327;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
/** Creates new form AuditPanel */
public AuditPanel() {
public void renderPanel(){
initComponents();
public String[] getAcceptenceOptions(){
return acceptenceOptions;
public void setAcceptenceOptions(String[] acceptenceOptions){
this.acceptenceOptions = acceptenceOptions;
public Vector getColumnNames(){
return colNames;
public void setColumnNames(Vector colNames){
this.colNames = colNames;
public Vector getData(){
Vector dataVector = new Vector();
/*dataVector.add(null);
dataVector.add(null);
dataVector.add(null);
return dataVector;
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
jPanel2 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
jTable1 = new javax.swing.JTable();
setLayout(new java.awt.GridBagLayout());
setBorder(new javax.swing.border.EmptyBorder(0,0,0,0));
jPanel2.setLayout(new java.awt.GridBagLayout());
jPanel2.setBorder(new javax.swing.border.EmptyBorder(0,0,0,0));
jButton1.setText("Add");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.ipadx = 8;
gridBagConstraints.insets = new java.awt.Insets(0, 1, 5, 0);
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
jPanel2.add(jButton1, gridBagConstraints);
jButton2.setText("Delete");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
jPanel2.add(jButton2, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 0;
gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
add(jPanel2, gridBagConstraints);
jPanel1.setLayout(new java.awt.GridBagLayout());
jPanel1.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.LOWERED, Color.black, Color.gray) );
jTable1.setModel(new javax.swing.table.DefaultTableModel(getData(), getColumnNames()));
// get all the columns and set the column required properties
java.util.Enumeration enum = jTable1.getColumnModel().getColumns();
while (enum.hasMoreElements()) {
TableColumn column = (TableColumn)enum.nextElement();
if( column.getModelIndex() == 0 ) {
column.setPreferredWidth(column0Width);
column.setCellEditor( new ValidateCellDataEditor(true) );
if( column.getModelIndex() == 1) {
column.setPreferredWidth(column1Width);
column.setCellEditor(new AcceptenceComboBoxEditor(getAcceptenceOptions()));
// If the cell should appear like a combobox in its
// non-editing state, also set the combobox renderer
//column.setCellRenderer(new AcceptenceComboBoxRenderer(getAcceptenceOptions()));
if( column.getModelIndex() == 2 ) {
column.setPreferredWidth(column2Width); // width of column
column.setCellEditor( new ValidateCellDataEditor(false) );
jScrollPane1 = new javax.swing.JScrollPane(jTable1);
jScrollPane1.setPreferredSize(new java.awt.Dimension(480, 280));
jTable1.setMinimumSize(new java.awt.Dimension(60, 70));
//jTable1.setPreferredSize(new java.awt.Dimension(300, 70));
//jScrollPane1.setViewportView(jTable1);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
jPanel1.add(jScrollPane1, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
add(jPanel1, gridBagConstraints);
// set the row height
jTable1.setRowHeight(rowHeight);
// set selection color
jTable1.setSelectionBackground(rowSelectionBackground);
// set the single selection
jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// avoid table header to resize/ rearrange
jTable1.getTableHeader().setReorderingAllowed(false);
jTable1.getTableHeader().setResizingAllowed(false);
// Table header font
jTable1.getTableHeader().setFont( new Font( jTable1.getFont().getName(),Font.BOLD,jTable1.getFont().getSize() ) );
jButton1.setMnemonic(KeyEvent.VK_A);
// action of add button
jButton1.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent actionEvent){
// If a button press is the trigger to leave a JTable cell and save the data in model
if(jTable1.isEditing() ){
//System.out.println("table is edition ");
String text=((javax.swing.text.JTextComponent)jTable1.getEditorComponent()).getText();
jTable1.setValueAt(text,jTable1.getSelectedRow(),jTable1.getSelectedColumn()) ;
jTable1.getCellEditor().cancelCellEditing();
// find out total available rows
int totalRows = jTable1.getRowCount();
int cols = jTable1.getModel().getColumnCount();
if( jTable1.getModel() instanceof DefaultTableModel ) {
((DefaultTableModel)jTable1.getModel()).addRow(new Object[cols]);
int newRowCount = jTable1.getRowCount();
// select the first row
jTable1.getSelectionModel().setSelectionInterval(newRowCount-1,newRowCount-1);
jButton2.setMnemonic(KeyEvent.VK_D);
// action of Delete button
jButton2.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent actionEvent){
int totalRows = jTable1.getRowCount();
// If there are more than one row in table then delete it
if( totalRows > 0){
int selectedOption = JOptionPane.showConfirmDialog(null,"Are you sure you want to delete this audit row?","Coeus", JOptionPane.YES_NO_OPTION);
// if Yes then selectedOption is 0
// if No then selectedOption is 1
if(0 == selectedOption ){
// get the selected row
int selectedRow = jTable1.getSelectedRow();
System.out.println("Selected Row "+selectedRow);
if( selectedRow != -1 ){
DefaultTableModel dm= (DefaultTableModel)jTable1.getModel();
java.util.Vector v1=dm.getDataVector();
System.out.println("BEFOE "+v1);
v1.remove(selectedRow);
jTable1.removeRowSelectionInterval(selectedRow,selectedRow);
System.out.println("After "+v1);
}else{
// show the error message
JOptionPane.showMessageDialog(null, "Please Select an audit Row", "Coeus", JOptionPane.ERROR_MESSAGE);
} // end of initcomponents
class AcceptenceComboBoxRenderer extends JComboBox implements TableCellRenderer {
public AcceptenceComboBoxRenderer(String[] items) {
super(items);
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
if (isSelected) {
setForeground(table.getSelectionForeground());
super.setBackground(rowSelectionBackground);
} else {
setForeground(table.getForeground());
setBackground(table.getBackground());
// Select the current value
setSelectedItem(value);
return this;
class AcceptenceComboBoxEditor extends DefaultCellEditor {
public AcceptenceComboBoxEditor(String[] items) {
super(new JComboBox(items));
} // end editor class
public class ValidateCellDataEditor extends AbstractCellEditor implements TableCellEditor {
// This is the component that will handle the editing of the
// cell value
JComponent component = new JTextField();
boolean validate;
public ValidateCellDataEditor(boolean validate){
this.validate = validate;
// This method is called when a cell value is edited by the user.
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected, int rowIndex, int vColIndex) {
if (isSelected) {
component.setBackground(rowSelectionBackground);
// Configure the component with the specified value
JTextField tfield =(JTextField)component;
// if any vaidations to be done for this cell
if(validate){
//tfield.setDocument(new JTextFieldFilter(JTextFieldFilter.NUMERIC,4));
tfield.setText( ((String)value));
// Return the configured component
return component;
// This method is called when editing is completed.
// It must return the new value to be stored in the cell.
public Object getCellEditorValue() {
return ((JTextField)component).getText();
// This method is called just before the cell value
// is saved. If the value is not valid, false should be returned.
public boolean stopCellEditing() {
String s = (String)getCellEditorValue();
return super.stopCellEditing();
public void itemStateChanged(ItemEvent e) {
super.fireEditingStopped();
}//end of ValidateCellDataEditor class
public static void main(String args[]){
JFrame frame = new JFrame();
AuditPanel auditPanel = new AuditPanel();
frame.getContentPane().add(auditPanel);
auditPanel.setAcceptenceOptions(new String[]{"Accepted", "Rejected", "Requested"} );
java.util.Vector colVector = new java.util.Vector();
colVector.add("Fiscal Year");
colVector.add("Audit Accepted");
colVector.add("Comment" );
auditPanel.setColumnNames( colVector);
auditPanel.renderPanel();
frame.pack();
frame.show();Hi,
I've got the solution for it. As when the cursor is in cell of
a row and hit the delete button, the data in that cell is not saved,
So i'm trying to save the data first into the model then firing the action event by doing this ..
jButton2.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent actionEvent){
// If a button press is the trigger to leave a JTable cell and save the data in model
if(jTable1.isEditing() ){
String text=((javax.swing.text.JTextComponent)jTable1.getEditorComponent()).getText();
jTable1.setValueAt(text,jTable1.getSelectedRow(),jTable1.getSelectedColumn()) ;
jTable1.getCellEditor().cancelCellEditing();
// HERE DO THE DELETE ROW OPERATION
<yaman/>
Maybe you are looking for
-
How to get the current month value for a customer exit variable?
How to get the current month value for a customer exit variable? And also if we have an InfoObject with date value (including date, month, year), then how to derive the month value from this date type of Char.? Thanks!
-
How to get the result set in batches
I have a query which results into large data. This data i want to display in a group of 20. After every 20 records i want to add header and footer to it. Is it possible to get the result set data into batch of 20 ? means can i specify start and end i
-
Using JDeveloper 903, I receive the following error when attempting to run a container-managed EJB: SQL error: Io exception: The Network Adapter could not establish the connection However, the connection is fine according to the Connection wizard: cl
-
Hi again, Within the same project I have several clips in sequence A that I would like to edit in a new sequence B. When I copy a clip from sequence A and paste it in sequence B that I just created in the project, the size of the clip is changed . It
-
Hi, We want to add a new jsp page that should be displayed when it is accessed from the additional user details drop down list in user details page of the admin console. Things done so far 1.we have made an entry in the design console look up so we a