Problem in deleting Rows of JTable after sorting it

Hi all,
I'm getting problems in Removing Row(s) after sorting a JTable.
Please find the code snippets at this URL. Thanks for your time...
http://forum.java.sun.com/thread.jsp?forum=31&thread=459736&start=15&range=15&hilite=false&q=

Hi Abhijeet,
I tried it the way you said using
     wdContext.nodeBirhtday_List().nodeItab().moveFirst();
     //     loop backwards to avoid index troubles
     for (int i = n - 1; i >= 0; --i)
          current_date  = wdContext.nodeBirhtday_List().nodeItab().currentItabElement().getGbdat().getDate();
          current_month = wdContext.nodeBirhtday_List().nodeItab().currentItabElement().getGbdat().getMonth();
          if (( current_date != date_today ) && ( current_month != month_today ))
               wdContext.nodeBirhtday_List().nodeItab().removeElement(wdContext.nodeBirhtday_List().nodeItab().
                              getElementAt(i));                
          wdContext.nodeBirhtday_List().nodeItab().moveNext();     
It adds records...
According to Valerys Solution, the IPrivate<CustomController> doesnt show me the required nodes. and gives me 'Unable to resolve' error.
Can you please suggest where I am going wrong
Regards
Abdullah

Similar Messages

  • Problem in adding/deleting rows in JTable

    I am trying to add /remove rows from JTable whose first column is JButton and others are JComboBox's.If no rows are selected,new row is added at the end.If user selects some row & then presses insert button,new row is added below it.Rows can only be deleted if user has made some selection.Kindly help me,where i am making mistake.If any function is to be used.My code is as follows....
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.border.*;
    public class JButtonTableExample extends JFrame implements ActionListener{
    JComboBox mComboLHSType = new JComboBox();
    JComboBox mComboRHSType = new JComboBox();
    JLabel mLabelLHSType = new JLabel("LHS Type");
    JLabel mLabelRHSType = new JLabel("RHS Type");
    JButton mButtonDelete = new JButton("Delete");
    JButton mButtonInsert = new JButton("Insert");
    JPanel mPanelButton = new JPanel();
    JPanel mPanelScroll = new JPanel();
    JPanel mPanelCombo = new JPanel();
    DefaultTableModel dm ;
    JTable table;
    int currentRow = -1;
    static int mSelectedRow = -1;
    public JButtonTableExample()
    super( "JButtonTable Example" );
    makeForm();
    setSize( 410, 222 );
    setVisible(true);
    private void makeForm()
    this.getContentPane().setLayout(null);
    mPanelCombo.setLayout(null);
    mPanelCombo.setBorder(new LineBorder(Color.red));
    mPanelCombo.setBounds(new Rectangle(1,1,400,30));
    mLabelLHSType.setBounds(new Rectangle(26,5,71,22));
    mComboLHSType.setBounds(new Rectangle(83,5,100,22));
    mLabelRHSType.setBounds(new Rectangle(232,5,71,22));
    mComboRHSType.setBounds(new Rectangle(292,5,100,22));
    mPanelCombo.add(mLabelLHSType,null);
    mPanelCombo.add(mComboLHSType,null);
    mPanelCombo.add(mLabelRHSType,null);
    mPanelCombo.add(mComboRHSType,null);
    mPanelScroll.setLayout(null);
    mPanelScroll.setBorder(new LineBorder(Color.blue));
    mPanelScroll.setBounds(new Rectangle(1,28,400,135));
    mPanelButton.setLayout(null);
    mPanelButton.setBorder(new LineBorder(Color.green));
    mPanelButton.setBounds(new Rectangle(1,165,400,30));
    mButtonInsert.setBounds(new Rectangle(120,5,71,22));
    mButtonDelete.setBounds(new Rectangle(202,5,71,22));
    mButtonDelete.addActionListener(this);
    mButtonInsert.addActionListener(this);
    mPanelButton.add(mButtonDelete,null);
    mPanelButton.add(mButtonInsert,null);
    dm = new DefaultTableModel();
    //dm.setDataVector(null,
    //new Object[]{"Button","Join","LHS","Operator","RHS"});
    dm.setDataVector(new Object[][]{{"","","","",""}},
    new Object[]{"","Join","LHS","Operator","RHS"});
    table = new JTable(dm);
    table.getTableHeader().setReorderingAllowed(false);
    table.setRowHeight(25);
    int columnWidth[] = {20,45,95,95,95};
    TableColumnModel modelCol = table.getColumnModel();
    for (int i=0;i<5;i++)
    modelCol.getColumn(i).setPreferredWidth(columnWidth);
    //modelCol.getColumn(0).setCellRenderer(new ButtonRenderer());
    //modelCol.getColumn(0).setCellEditor(new ButtonEditor(new JCheckBox()));
    modelCol.getColumn(0).setCellRenderer(new ButtonCR());
    modelCol.getColumn(0).setCellEditor(new ButtonCE(new JCheckBox()));
    modelCol.getColumn(0).setResizable(false);
    setUpJoinColumn(modelCol.getColumn(1));
    setUpLHSColumn(modelCol.getColumn(2));
    setUpOperColumn(modelCol.getColumn(3));
    setUpRHSColumn(modelCol.getColumn(4));
    JScrollPane scroll = new JScrollPane(table);
    scroll.setBounds(new Rectangle(1,1,400,133));
    mPanelScroll.add(scroll,null);
    this.getContentPane().add(mPanelCombo,null);
    this.getContentPane().add(mPanelScroll,null);
    this.getContentPane().add(mPanelButton,null);
    }//end of makeForm()
    public void actionPerformed(ActionEvent ae)
    if (ae.getSource() == mButtonInsert)
    //int currentRow = table.getSelectedRow();
    currentRow = ButtonCE.selectedRow;
    System.out.println("Before Insert CURRENT ROW"+currentRow);
    if(currentRow == -1)
    int rowCount = dm.getRowCount();
    //mSelectedRow = rowCount-1;
    //table.clearSelection();
    dm.insertRow(rowCount,new Object[]{"","","","",""});
    currentRow = -1;
    ButtonCE.selectedRow = -1;
    else
    table.clearSelection();
    dm.insertRow(currentRow+1,new Object[]{"","","","",""});
    currentRow = -1;
    ButtonCE.selectedRow = -1;
    //System.out.println("After INSERT CURRENT ROW"+currentRow);
    if(ae.getSource() == mButtonDelete)
    //int currentRow = table.getSelectedRow();
    currentRow = ButtonCE.selectedRow;
    System.out.println("Before DELETE CURRENT ROW"+currentRow);
    if(currentRow != -1)
    dm.removeRow(currentRow);
    table.clearSelection();
    currentRow = -1;
    ButtonCE.selectedRow = -1;
    //System.out.println("Selected Row"+mSelectedRow);
    else
    JOptionPane.showMessageDialog(null, "Select row first", "alert", JOptionPane.ERROR_MESSAGE);
    //System.out.println("DELETE CURRENT ROW"+currentRow);
    public void setUpJoinColumn(TableColumn joinColumn)
    //Set up the editor for the sport cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("AND");
    comboBox.addItem("OR");
    comboBox.addItem("NOT");
    joinColumn.setCellEditor(new DefaultCellEditor(comboBox));
    //Set up tool tips for the sport cells.
    DefaultTableCellRenderer renderer =
    new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    joinColumn.setCellRenderer(renderer);
    //Set up tool tip for the sport column header.
    TableCellRenderer headerRenderer = joinColumn.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer) {
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the sport to see a list of choices");
    public void setUpLHSColumn(TableColumn LHSColumn)
    //Set up the editor for the sport cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("Participant1");
    comboBox.addItem("Participant2");
    comboBox.addItem("Variable1");
    LHSColumn.setCellEditor(new DefaultCellEditor(comboBox));
    //Set up tool tips for the sport cells.
    DefaultTableCellRenderer renderer =
    new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    LHSColumn.setCellRenderer(renderer);
    //Set up tool tip for the sport column header.
    TableCellRenderer headerRenderer = LHSColumn.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer) {
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the sport to see a list of choices");
    public void setUpOperColumn(TableColumn operColumn)
    //Set up the editor for the sport cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("=");
    comboBox.addItem("!=");
    comboBox.addItem("Contains");
    operColumn.setCellEditor(new DefaultCellEditor(comboBox));
    //Set up tool tips for the sport cells.
    DefaultTableCellRenderer renderer =
    new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    operColumn.setCellRenderer(renderer);
    //Set up tool tip for the sport column header.
    TableCellRenderer headerRenderer = operColumn.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer) {
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the sport to see a list of choices");
    public void setUpRHSColumn(TableColumn rhsColumn)
    //Set up the editor for the sport cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("Variable1");
    comboBox.addItem("Constant1");
    comboBox.addItem("Constant2");
    rhsColumn.setCellEditor(new DefaultCellEditor(comboBox));
    //Set up tool tips for the sport cells.
    DefaultTableCellRenderer renderer =
    new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    rhsColumn.setCellRenderer(renderer);
    //Set up tool tip for the sport column header.
    TableCellRenderer headerRenderer = rhsColumn.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer) {
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the sport to see a list of choices");
    public static void main(String[] args) {
    JButtonTableExample frame = new JButtonTableExample();
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    //Button as a renderer for the table cells
    class ButtonCR implements TableCellRenderer
    JButton btnSelect;
    public ButtonCR()
    btnSelect = new JButton();
    btnSelect.setMargin(new Insets(0,0,0,0));
    public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasFocus,int row,int column)
    if (column != 0) return null; //meany !!!
    //System.out.println("Inside renderer########################Selected row");
    //btnSelect.setText(value.toString());
    //btnSelect.setIcon(new ImageIcon("capsigma.gif"));
    return btnSelect;
    }//end fo ButtonCR
    //Default Editor for table
    class ButtonCE extends DefaultCellEditor implements ActionListener
    JButton btnSelect;
    JTable table;
    //Object val;
    static int selectedRow = -1;
    public ButtonCE(JCheckBox whoCares)
    super(whoCares);
    //this.row = row;
    btnSelect = new JButton();
    btnSelect.setMargin(new Insets(0,0,0,0));
    btnSelect.addActionListener(this);
    setClickCountToStart(1);
    public Component getTableCellEditorComponent(JTable table,Object value,boolean isSelected,int row,int column)
    if (column != 0) return null; //meany !!!
    this.selectedRow = row;
    this.table = table;
    table.clearSelection();
    System.out.println("Inside getTableCellEditorComponent");
    return btnSelect;
    //public Object getCellEditorValue()
    //return val;
    public void actionPerformed(ActionEvent e)
    // Your Code Here...
    System.out.println("Inside actionPerformed");
    System.out.println("Action performed Row selected "+selectedRow);
    btnSelect.setIcon(new ImageIcon("capsigma.gif"));
    }//end of ButtonCE

    Hi,
    All the thing you have to do is to return a boolean for the column. JTable will use a checkbox (as default) to show boolean values.

  • Delete row in JTable

    Hello I am new To JAVA SWING
    I have 2 questions related to JTable
    1) How do i remove selected row in JTable ...for instance, I click on the row to delete (It is selected) , later I press the delete button, and then row is removed .... any hints ?
    2) If I would like to save the rows in a JTable into a database , .... How can iterate through the rows in the JTable..each row .... the rows are saved in a List object...and a List Object is what I pass as a parameter in a class method in order to be saved into Database.
    Thanks,
    deibys

    1) use the removeRow(...) method of the DefaultTableModel
    20 use table.getModel().getValueAt(...) to get the data from the model and create your list Object.

  • Deleting a dataTable item after sorting

    Hello,
    I am using a "h:dataTable" which has a 'delete' commandLink on every row.
    If I sort the table and then delete an item, the wrong item is deleted.
    The deleted item is the item that was originaly in the same place (before sorting).
    What should I do to fix that?
    Thank you,
    Dana

    Should I call "sortDataList" before deleting the item the way it was sorted in the previous request?
    If so, the function should receive an "ActionEvent event".
    public void sortDataList(ActionEvent event) {
            String sortFieldAttribute = getAttribute(event, "sortField");
    }What should I send as the parameter to the sorting function?

  • Add/delete row in JTable

    I went through the tutorial of JDK about how to programming JTable, i can NOT find a way to add/delete row into/from JTable.
    I immagine it would be a difficult task because the data set it takes 'Object data[][]' is NOT dynamically grow/shrinkble.
    Can we make it take ArrayList[] as input dataset so that the dataset can dynamically grow/shrink?
    Any other way around to add/delete row?
    THANKS for your consideration.

    You have to write your own TableModel like extending AbstractTableModel. In that class add custom methods to add and remove rows. From those methods call fireTableRowsDeleted(..) and fireTableRowsInserted(..) to update UI.

  • Facing problem While deleting rows and adding rows

    Hi,
    In my form i have pass values to table rows by selecting values from Dropdown list.
    i have taken 3 hidden obj and passing the dropdown values to hidden objects and then from hidden objects to table rows.
    h1,h2,h2 are hidden obj
    EMPNO,EMPNAME, DESIGNATION are drop downlist
    i have add button with the following code
    if(form1.P1.ItemSet.EMPNO.rawValue != null){
    form1.P1.ItemSet.instanceManager.addInstance();
    form1.P1.execInitialize();
    var dynamicArray = form1.P1.resolveNode("ItemSet[" + arrayIncri + "]");
    dynamicArray .EMPNO.rawValue = form1.P1.hidden.h1.rawValue;
    dynamicArray .EMPNAME.rawValue = form1.P1.hidden.h2.rawValue;
    dynamicArray .DESIGNATION.rawValue = form1.P1.hidden.h3.rawValue;
    arrayIncri++;
    form1.P1.SF1.EmpID.rawValue = null;
    form1.P1.SF1.EmpName.rawValue = null;
    form1.P1.SF1.Designation.rawValue = null;
    My delete button code is
    _ItemSet.removeInstance(this.parent.index);
    form1.P1.execInitialize();
    My problem is adding is happening while click and deleting is happening to the perticular row but once i delete paricular row then again if i want to add new row then it is taking null values . and agian if i click add then the values are passing to the next row
    means i am getting null row if i do add funtionality after delete funtionality....
    Please help me out in this..
    Subba reddy

    Hi,
    I got the answer for this query, but when i do download and upload of the files from R/3 to GRC. Still it is not showing me the new transactions which were developed in R/3.
    it means when i try to add the transaction in a function, under search mode with respective of the r/3 system, it is not showing me the search results.
    What i did was, i run the reports /VIRSA/ZCC_DOWNLOAD_DESC & /VIRSA/ZCC_DOWNLOAD_SAPOBJ and uploaded them as below in GRC.
    Text Objects - /VIRSA/ZCC_DOWNLOAD_DESC
    permissions   -  /VIRSA/ZCC_DOWNLOAD_SAPOBJ
    For each of the download i get 2 files for each and i tried to upload both of them but no luck.
    Please suggest me, as am missing anything in this process
    SV

  • Problem in Delete Row

    Hai To All,
             Iam using PL 05 i have enable DeleteRow option. If i click the deleterow the row is deleted but after saving the entry there is null value in database. for example if i have 2 row in the matrix if i delete last row the content is deleted after that iam saving the matrix. In the database i have 2 rows one with content and other with null value..
    Whts the soultion of this....
    Does anyone have idea reply me....
    Regards,
    Anitha

    Hi Anitha,
    For the delete option, you need to right a small function if its going to be ur own form.
    Try using the following code...
    Private Sub DeleteRow()
            Dim oDBDSource As SAPbouiCOM.DBDataSource
            Dim Count As Integer
            Dim oMatrix As SAPbouiCOM.Matrix
            Try
                oDBDSource = objForm.DataSources.DBDataSources.Item("@TableName")
                oMatrix = objForm.Items.Item("3").Specific
                oMatrix.FlushToDataSource()
                oMatrix.DeleteRow(strRow)          
                objForm.Update()
                'objForm.DataSources.DBDataSources.Item("@TableName").RemoveRecord(strRow - 1)
                oDBDSource.Clear()
                oMatrix.FlushToDataSource()
                oMatrix.LoadFromDataSource()
                For Count = 1 To oDBDSource.Size - 1
                    oDBDSource.SetValue("Code", Count - 1, Count)
                Next        
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Sub
    Hope this helps.
    Satish.

  • Problem in adding row in JTable

    Hi,
    I was trying to add a row in a table when the add button is clicked. But i am missing something that's why i am getting some exceptions.
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.DefaultTableColumnModel;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableColumn;
    import javax.swing.JButton;
    import java.util.Vector;
    import java.awt.event.*;
    public class TableDemo extends JFrame implements ActionListener {
            int rows = 1;
            int cols = 4;
            JTable table = new JTable();
            TModel model = new TModel();
            JButton button = new JButton("Add");
            Object[][] values = {
                                          {"Java","Linux","Hello","World"}
            class TModel extends DefaultTableModel {
                    public boolean isCellEditable(int parm1, int parm2){
                            return true;
                    public int getRowCount(){
                            return rows;
                    public int getColumnCount(){
                            return cols;
                    public void setValueAt(Object aValue, int aRow, int aColumn) {
                            values[aRow][aColumn] = aValue;
                    public Object getValueAt(int aRow, int aColumn) {
                            return values[aRow][aColumn];
                    public String getColumnName(int column) {
                            return "Error " + column;
            public TableDemo(String title){
                    super(title);
                    JPanel panel = new JPanel();
                    panel.setLayout(new BorderLayout());
                    table.setModel(model);
                    // Make the columns with gradually increasing width:
                    String columnName[] = {"Column", "Operator", "Values", "Logical"};
                    for (int i = 0; i < columnName.length; i++) {
                            TableColumn column = new TableColumn(i);
                            int width = 100+20*i;
                            column.setPreferredWidth(width);
                            column.setHeaderValue(columnName);
    model.addColumn(column);
    // Create the table, place it into scroll pane and place
    // the pane into this frame.
    JScrollPane scroll = new JScrollPane();
    // The horizontal scroll bar is never needed.
    scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scroll.getViewport().add(table);
    button.addActionListener(this);
    panel.add(scroll, BorderLayout.CENTER);
    panel.add(button, BorderLayout.SOUTH);
    getContentPane().add(panel, BorderLayout.CENTER);
    public void actionPerformed(ActionEvent ae) {
    if(ae.getSource() == button) {
    Vector tempRow = new Vector();
    model.setRowCount(rows++);
    tempRow.addElement("One");//new JComboBox());
    tempRow.addElement("Two");
    tempRow.addElement("Three");
    tempRow.addElement("Four");
    model.addRow(tempRow);
    model.fireTableDataChanged();
    System.out.println("Hi");
    public static void main(String[] args) {
    TableDemo frame = new TableDemo("Table double click on the cell to edit.");
    frame.setSize(new Dimension(640, 400));
    frame.validate();
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    The code is generating the follwoing exception when add button is clicked :
    java.lang.ArrayIndexOutOfBoundsException: 2 > 1
    at java.util.Vector.insertElementAt(Vector.java:557)
    at javax.swing.table.DefaultTableModel.insertRow(DefaultTableModel.java:343)
    at javax.swing.table.DefaultTableModel.addRow(DefaultTableModel.java:319)
    at com.saijava.TableDemo.actionPerformed(TableDemo.java:96)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
    at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
    at java.awt.Component.processMouseEvent(Component.java:5100)
    at java.awt.Component.processEvent(Component.java:4897)
    at java.awt.Container.processEvent(Container.java:1569)
    at java.awt.Component.dispatchEventImpl(Component.java:3615)
    at java.awt.Container.dispatchEventImpl(Container.java:1627)
    at java.awt.Component.dispatchEvent(Component.java:3477)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
    at java.awt.Container.dispatchEventImpl(Container.java:1613)
    at java.awt.Window.dispatchEventImpl(Window.java:1606)
    at java.awt.Component.dispatchEvent(Component.java:3477)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:480)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
    java.lang.ArrayIndexOutOfBoundsException: 1
    at com.saijava.TableDemo$TModel.getValueAt(TableDemo.java:55)
    at javax.swing.JTable.getValueAt(JTable.java:1771)
    at javax.swing.JTable.prepareRenderer(JTable.java:3724)
    at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:1149)
    at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1051)
    at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:974)
    at javax.swing.plaf.ComponentUI.update(ComponentUI.java:142)
    at javax.swing.JComponent.paintComponent(JComponent.java:541)
    at javax.swing.JComponent.paint(JComponent.java:808)
    at javax.swing.JComponent.paintChildren(JComponent.java:647)
    at javax.swing.JComponent.paint(JComponent.java:817)
    at javax.swing.JViewport.paint(JViewport.java:722)
    at javax.swing.JComponent.paintChildren(JComponent.java:647)
    at javax.swing.JComponent.paint(JComponent.java:817)
    at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4787)
    at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4740)
    at javax.swing.JComponent._paintImmediately(JComponent.java:4685)
    at javax.swing.JComponent.paintImmediately(JComponent.java:4488)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:410)
    at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:117)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:189)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:478)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

    Umm. A few tips:
    1) You should NOT instantiate objects / initialize variables outside the constructor. And please use access-modifiers.
    2) Do not make your main-class extend JFrame or implement ActionListener. Instead create a JFrame in main and use an anonymous inner class as an ActionListener
    3) Why are you extending DefaultTableModel? To set the the column names as Error1, etc.? You can set the column names by using an appropriate constructor for JTable or by using setColumnIdentifiers(...). See the API.
    4) The actual problem most likely lies here:
    int rows = 1;
    int cols = 4;Why are you defining these outside the TableModel?

  • Problems to delete Rows

    Hi,
    i want to delete all rows in a table which will be automaticlly updatet in a thread. the problem is that i get somtimes the message 9>=9 or 8>=3. did somebody know what that means ?!?

    it means the row index that you are trying to remove doesnt exist.
    9>=9 means that you are trying to remove row index 9 in a table that has only 9 itmes (remember its zero based)
    there's probably something dodgy with you remove code.
    off the top of my head try looping through with (rowcount - 1)

  • Delete rows from JTable

    Hello
    I use a JTable with a custom table model that extends javax.swing.table.DefaultTableModel.
    I haven't overwrote the method
    public void removeRow(int row)Now when i use this method the rows always get removed from the end. It doesn't matter which value the parameter row has.
    Even when i call
    myTableModel.removeRow( 0 );it removes the rows at the end of the table.
    It would be nice if someone could help me with this.
    Regards, Michelle

    It's not so easy to do this because it's a big project, but here is the code of the table model.
    import javax.swing.table.*;
    import javax.swing.event.TableModelEvent;
    import javax.swing.event.TableModelListener;
    import java.util.*;
    public class AssignmentsTableModel2 extends DefaultTableModel implements TableModelListener
         static final long serialVersionUID = 41L;
         public AssignmentsTableModel2(String[][] arg1, String[] arg2)
              super(arg1, arg2);
         public Vector getColumnIdentifiers()
              return columnIdentifiers;
         @Override
         public int getColumnCount()
              return this.columnIdentifiers.size();
         @Override
         public int getRowCount()
              return this.dataVector.size();
         @Override
         public String getColumnName(int col)
            return (String)this.columnIdentifiers.elementAt( col );
         @Override
         public Object getValueAt(int rowIndex, int columnIndex)
              return ((Vector)this.dataVector.elementAt( rowIndex )).elementAt( columnIndex );
         @Override
         public void setValueAt( Object val, int rowIndex, int columnIndex )
              ((Vector)this.dataVector.elementAt( rowIndex )).set( columnIndex, val);
              fireTableCellUpdated( rowIndex, columnIndex );
         @Override
         public void tableChanged(TableModelEvent e)
         @Override
         public void setColumnIdentifiers(Vector columnIdentifiers)
              super.setColumnIdentifiers(columnIdentifiers);
         @Override
         public void removeRow(int row)
              this.dataVector.remove(row);
              System.out.println(row + " to remove");
              this.fireTableStructureChanged();
              //super.removeRow(row);
    }I need the model to change the background color of the cells at runtime and I now overwrote the removeRow() method, but it's still the same problem.
    Also I have a custom JTable class that colours the TableHeader of the selected column.
    class PaintedTable extends JTable {
        private static final long serialVersionUID = 1L;
        PaintedTable(AssignmentsTableModel2 atm)
            super(atm);
            setOpaque(false);
            ((JComponent) getDefaultRenderer(Object.class)).setOpaque(false);
        @Override
        public void paintComponent(Graphics g)
             //System.out.println("paint table");
            Color background = new Color(168, 210, 241);
            Color controlColor = new Color(230, 240, 230);
            int width = getWidth();
            int height = getHeight();
            Graphics2D g2 = (Graphics2D) g;
            Paint oldPaint = g2.getPaint();
            g2.setPaint(new GradientPaint(0, 0, background, width, 0, controlColor));
            g2.fillRect(0, 0, width, height);
            g2.setPaint(oldPaint);
            for (int row : getSelectedRows())
                Rectangle start = getCellRect(row, 0, true);
                Rectangle end = getCellRect(row, getColumnCount() - 1, true);
                g2.setPaint(new GradientPaint(start.x, 0, Color.orange, (int) ((end.x + end.width - start.x) * 1.25), 0, controlColor));
                g2.fillRect(start.x, start.y, end.x + end.width - start.x, start.height);
                //System.out.println("rect: (" + start.x + ", " + start.y + ") + (" + (end.x + end.width - start.x) + ", " + start.height +")");
            super.paintComponent(g);
        public boolean isCellEditable(int rowIndex, int colIndex)
            return false;  
    AssignmentsTableModel2 atm = new AssignmentsTableModel2(this.columnValues, this.columnHeaders);     
    PaintedTable table = new PaintedTable( this.atm );

  • Problems on deleting rows in UIX pages

    Hi,
    I am new on using BC4J, Struts and uiXML and I am having some problems on it. I have tried to make a simple create/update/delete web application.
    First, I have created a DataAction which PageForward displays a table with data from a view object. This page allows the user to select a row and request its deletion by clicking on a submit button.
    The event triggered by the submit button calls a DataAction that displays another PageForward, composed by a read-only form, that asks for confirmation. If the user confirms, a DataAction that performs the Delete method from the view is called and the deletion is successful.
    A problem occurs when I change the readonly property of the fields of the confirmation form: the row deleted is not the selected, but a random one.
    I would like to know why the readonly property of the fields change the Delete method behavior. Also, an example of a simple create/update/delete struts page flow would be appreciated.
    Thanks in advance.
    Verner.

    Verner,
    Are you using JDeveloper 10g Preview or JDeveloper 9i v9.0.3?
    I'm not sure what problem you are having, but I just tried to reproduce your application by doing the following in JDeveloper 10g Preview:
    1) Created new business components.
    2) Created a new struts-config.xml.
    3) Added to the Struts config (using the page flow modeler):
    3.a) Browse data action and page forward to browse.uix
    3.b) Confirm data action and page forward to confirm.uix
    3.c) Delete data action.
    3.d) Link from browse action to confirm action for outcome "delete".
    3.e) Link from confirm action to delete action for outcome "delete".
    3.f) Link from confirm action to browse action for outcome "cancel".
    3.g) Link from delete action to browse action for outcome "success".
    4) Then I made the delete action do the deletion by dragging the Delete operation from my data control onto the Delete data action in the page flow.
    5) Then I created my UI pages.
    browse.uix just has a read-only table created via the Data Control palette and then a delete button that fires the "delete" event when clicked. The delete handler returns the delete outcome.
    confirm.uix has a read-only form also dragged from the Data Control palette for the same data control. There's a delete and a cancel button, each of which fire an event of the same name that returns an outcome of the same name.
    When I run browseDataAction, I see my table. When I click "Delete", I see the read-only form with the details for the selected row. Clicking "Delete" from the confirmation page removes the same row I saw in the confirmation page, then goes back to the browse page showing the same range but with the given row removed.
    If you continue to see a problem, what exactly is wrong? It should be the case that (A) the row selected in the table, (B) the row whose details are shown in the confirmation page, and (C) the row that gets deleted are the same row. If it's not the case that A = B = C, please give more details about what values of these three rows you are seeing. Is A=B but not =C? Or is B=C but not =A?
    Hope this helps,
    -brian
    UIX Team

  • Problem in deleting row from database in table component

    Hi,
    I have a table component that its content change by diffrent links.
    in this table i have a hyperlink in each row to deleting that row from dataBase.
    so i must get the current row .
    i do it like this:
    define a rowset in the page that have a delete query :
    delete from response where responseID=?
    in action of delete hyperlink ,i have:
    Integer responseId=(Integer)responseDataProvider.
    getValue("#{currentRow.value['responseID']}") ;
    getSessionBean1().getResponseRowSet().setObject(1,responseId);
    getSessionBean1().getResponseRowSet().execute();
    but in first line occure a exception:
    illigalArgument #{currentRow.value['responseID']}
    thanks.

    by using data table
    first you should get current record (row that recived action)
    then delete it by using data provider.
    I do not think that you could execute delete statement using rowSets because they just can provide Select statements.
    btw , following code will retrive clicked row from data table and
    delete that row
    try {
    RowKey rk = getTableRowGroup1().getRowKey();
    if (rk != null) {
    testDataProvider.removeRow(rk);
    testDataProvider.commitChanges();
    } catch (Exception ex) {
    log("ErrorDescription", ex);
    error(ex.getMessage());
    hth
    masoud

  • Problem in deleting rows

    Hi experts,
    in the following method. I am deleting the records from the BAPI output table where the date and month do not correspond to todays date and current month.
    When I execute the BAPI for one employee it gives me the correct output. ie one record. But when I execute it for all the employees and when I use the following code. It gives me a blank output.
      public void wdDoInit()
        //@@begin wdDoInit()
        int date_today, current_date;
        int month_today, current_month;
        char date_satisfied, month_satisfied;
        Date date = new Date(System.currentTimeMillis());
        date_today = date.getDate();
        month_today = date.getMonth();
         int n = wdContext.nodeBirhtday_List().nodeItab().size();
         int leadSelected = wdContext.nodeBirhtday_List().nodeItab().getLeadSelection();
         //     loop backwards to avoid index troubles
         for (int i = n - 1; i >= 0; --i) {
              current_date  = wdContext.nodeBirhtday_List().nodeItab().currentItabElement().getGbdat().getDate();
              current_month = wdContext.nodeBirhtday_List().nodeItab().currentItabElement().getGbdat().getMonth();
              if (( current_date != date_today ) && ( current_month != month_today ))
                   wdContext.nodeBirhtday_List().nodeItab().removeElement(wdContext.nodeBirhtday_List().nodeItab().
                                  getElementAt(i));
        //@@end
    can anybody please suggest me the solution
    Regards
    Abdullah

    Hi Abhijeet,
    I tried it the way you said using
         wdContext.nodeBirhtday_List().nodeItab().moveFirst();
         //     loop backwards to avoid index troubles
         for (int i = n - 1; i >= 0; --i)
              current_date  = wdContext.nodeBirhtday_List().nodeItab().currentItabElement().getGbdat().getDate();
              current_month = wdContext.nodeBirhtday_List().nodeItab().currentItabElement().getGbdat().getMonth();
              if (( current_date != date_today ) && ( current_month != month_today ))
                   wdContext.nodeBirhtday_List().nodeItab().removeElement(wdContext.nodeBirhtday_List().nodeItab().
                                  getElementAt(i));                
              wdContext.nodeBirhtday_List().nodeItab().moveNext();     
    It adds records...
    According to Valerys Solution, the IPrivate<CustomController> doesnt show me the required nodes. and gives me 'Unable to resolve' error.
    Can you please suggest where I am going wrong
    Regards
    Abdullah

  • Row doesn't get selected after sorting

    I have a table bond to a javabean data control. I have enabled multi row selection. I get some rows on the table and then I select one of those rows, after that I use the value of the selected row for some operations.
    I have 3 columns, first name, lastname , email. The first 2 are sortable. If I click on the header of firstname, the information gets sorted ok (asc / desc). The problem is that after sorting, I can NOT select any rows. When I click on the row, it doesn't get highlighted, and If I try to use the value of the selected row I get a null pointer exception.
    Again this is happening only after sorting. If I don't sort, it works ok.
    I'm using JDEV + ADF 11.1.1.5.
    This is my code
    <af:table value="#{bindings.User1.collectionModel}" var="row" partialTriggers="::cb1"
    rows="#{bindings.User1.rangeSize}"
    emptyText="#{bindings.User1.viewable ? identityBundle.no_data_to_display : identityBundle.access_denied}"
    fetchSize="#{bindings.User1.rangeSize}" rowBandingInterval="0"
    id="t1" rowSelection="multiple"
    selectionListener="#{AssignRolesBean.onTableSelect}"
    binding="#{AssignRolesBean.searchResultsTable}"
    columnStretching="last">
    <af:column sortProperty="firstname" sortable="#{AssignRolesBean.columnSortable}"
    headerText="#{bindings.User1.hints.firstname.label}" id="c1"
    width="136">
    <af:outputText value="#{row.firstname}" id="ot4"/>
    </af:column>
    <af:column sortProperty="lastname" sortable="#{AssignRolesBean.columnSortable}"
    headerText="#{bindings.User1.hints.lastname.label}" id="c2"
    width="182">
    <af:outputText value="#{row.lastname}" id="ot2"/>
    </af:column>
    <af:column sortProperty="mail" sortable="#{AssignRolesBean.columnSortable}"
    headerText="#{bindings.User1.hints.mail.label}" id="c4"
    width="361">
    <af:outputText value="#{row.mail}" id="ot5"/>
    </af:column>
    <af:column sortProperty="uid" sortable="false"
    headerText="#{bindings.User1.hints.uid.label}" id="c3"
    visible="false">
    <af:outputText value="#{row.uid}" id="ot3"/>
    </af:column>
    </af:table>
    I have a selection listener only, I don't have a sort listener.
    My bean;
    AssignRolesBean
    public void onTableSelect(SelectionEvent selectionEvent) {
    GenericTableSelectionHandler.makeCurrent(selectionEvent);
    My makeCurrent method
    public static void makeCurrent( SelectionEvent selectionEvent){
    RichTable _table = (RichTable) selectionEvent.getSource();
    CollectionModel tableModel = (CollectionModel) table.getValue();
    JUCtrlHierBinding adfTableBinding = (JUCtrlHierBinding) tableModel.getWrappedData();
    DCIteratorBinding tableIteratorBinding = adfTableBinding.getDCIteratorBinding();
    Object selectedRowData = table.getSelectedRowData();
    JUCtrlHierNodeBinding nodeBinding = (JUCtrlHierNodeBinding) selectedRowData;
    Key rwKey = nodeBinding.getRowKey();
    tableIteratorBinding.setCurrentRowWithKey( rwKey.toStringFormat(true));
    SHOULD I IMPLEMENT A SORT LISTENER FOR THIS TABLE IN ORDER TO HANDLE ROW SELECTION PROPERLY AFTER SORTING?
    Is there a guideline for handling row selection after sorting?
    Thanks

    I have a table bond to a javabean data control. I have enabled multi row selection. I get some rows on the table and then I select one of those rows, after that I use the value of the selected row for some operations.
    I have 3 columns, first name, lastname , email. The first 2 are sortable. If I click on the header of firstname, the information gets sorted ok (asc / desc). The problem is that after sorting, I can NOT select any rows. When I click on the row, it doesn't get highlighted, and If I try to use the value of the selected row I get a null pointer exception.
    Again this is happening only after sorting. If I don't sort, it works ok.
    I'm using JDEV + ADF 11.1.1.5.
    This is my code
    <af:table value="#{bindings.User1.collectionModel}" var="row" partialTriggers="::cb1"
    rows="#{bindings.User1.rangeSize}"
    emptyText="#{bindings.User1.viewable ? identityBundle.no_data_to_display : identityBundle.access_denied}"
    fetchSize="#{bindings.User1.rangeSize}" rowBandingInterval="0"
    id="t1" rowSelection="multiple"
    selectionListener="#{AssignRolesBean.onTableSelect}"
    binding="#{AssignRolesBean.searchResultsTable}"
    columnStretching="last">
    <af:column sortProperty="firstname" sortable="#{AssignRolesBean.columnSortable}"
    headerText="#{bindings.User1.hints.firstname.label}" id="c1"
    width="136">
    <af:outputText value="#{row.firstname}" id="ot4"/>
    </af:column>
    <af:column sortProperty="lastname" sortable="#{AssignRolesBean.columnSortable}"
    headerText="#{bindings.User1.hints.lastname.label}" id="c2"
    width="182">
    <af:outputText value="#{row.lastname}" id="ot2"/>
    </af:column>
    <af:column sortProperty="mail" sortable="#{AssignRolesBean.columnSortable}"
    headerText="#{bindings.User1.hints.mail.label}" id="c4"
    width="361">
    <af:outputText value="#{row.mail}" id="ot5"/>
    </af:column>
    <af:column sortProperty="uid" sortable="false"
    headerText="#{bindings.User1.hints.uid.label}" id="c3"
    visible="false">
    <af:outputText value="#{row.uid}" id="ot3"/>
    </af:column>
    </af:table>
    I have a selection listener only, I don't have a sort listener.
    My bean;
    AssignRolesBean
    public void onTableSelect(SelectionEvent selectionEvent) {
    GenericTableSelectionHandler.makeCurrent(selectionEvent);
    My makeCurrent method
    public static void makeCurrent( SelectionEvent selectionEvent){
    RichTable _table = (RichTable) selectionEvent.getSource();
    CollectionModel tableModel = (CollectionModel) table.getValue();
    JUCtrlHierBinding adfTableBinding = (JUCtrlHierBinding) tableModel.getWrappedData();
    DCIteratorBinding tableIteratorBinding = adfTableBinding.getDCIteratorBinding();
    Object selectedRowData = table.getSelectedRowData();
    JUCtrlHierNodeBinding nodeBinding = (JUCtrlHierNodeBinding) selectedRowData;
    Key rwKey = nodeBinding.getRowKey();
    tableIteratorBinding.setCurrentRowWithKey( rwKey.toStringFormat(true));
    SHOULD I IMPLEMENT A SORT LISTENER FOR THIS TABLE IN ORDER TO HANDLE ROW SELECTION PROPERLY AFTER SORTING?
    Is there a guideline for handling row selection after sorting?
    Thanks

  • 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
    Nitin

    Hi,
    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

Maybe you are looking for

  • How to open VLC wit JAVA and later play a file with it..?

    Hi, I do it if I want to Play a file with VLC: Runtime rt = Runtime.getRuntime();           try {                rt.exec("C:\\Program Files\\VideoLAN\\VLC\\vlc " + "C:\\songs\\llarala.mp3");           } catch (IOException e) {                // TODO

  • URGENT : Really need Nokia's help on this one... A...

    Good day! I am using my Nokia N70-1 for both of my personal and business matters. This morning, I saw a warning on my phone regarding an operation it couldn't process: It goes like this: "Telephone: Not enough memory to perform operation. Delete some

  • Question about ACE show Conn command (tcp duration)

    Hello, I was checking connections and noticed that I would see the initial connection, but after a short time the connection quits showing up in the counters and the "show conn" command. However the user is still up and working. This is the command I

  • Download Failures continue to oppress loyal customer

    Photoshop CC is once again failing to install updates. Desktop component failed - new install. So much time wasted!

  • Converting a number into years, months and days...

    Hi everyone, I have a number say 399. I need to know how many years and months constitute that number. For eg 399 would be 1yr, 1 month and 4 days. So I need the answer as 1 yr and 1 month. Is there any inbuilt funtion to say this? Thanks Kishore