To add new row with the checkbox selected ....

Hi All,
In my project I have to create a table with 2 columns, 1 column is checkbox and other column is String type. In the same JFrame one textarea and one add button should be there. When we type text in the textarea and click add button, it should add a new row in the table with the checkbox selected and the 2nd column containing the text.
I want to use AbstractTableModel.
Please help me to solve this issue. If you have sample code that will be more helpful.
Thank you,
Regards,
mkumar

It would be better if you extend from DefaultTableModel rather than from Abstract Table Model. That is because DefaultTableModel provides functionality to add a row. In fact, you can directly use DefaultTableModel .
In the button's action performed,
public void actionPerformed(ActionEvent e)
  if(e.getSource() == bAdd)
    Vector newRow = new Vector(2);
    newRow.add(new Boolean(Boolean.TRUE));
    newRow.add(" ");
    DefaultTableModel dm = (DefaultTableModel)yourTable.getModel();
    dm.addRow(newRow);
}Note : For the above code, Initialize the JTable with a DefaultTableModel parameter than directly with Vectors/ Arrays.
This is because when we try to cast from TableModel to DefaultTableModel as in the above code, there is a possibility of an
Exception if the Table is not initialized without a model.
For the CheckBox in the first column, you need to set an editor and a renderer so that you can manipulate and see your boolean values as the state of the check boxes.
  JCheckBox b = new JCheckBox();
  DefaultTableCellRenderer dr = new DefaultTableCellRenderer(b);
  DefaultTableCellEditor de = new DefaultTableCellEditor(b);
  yourTable.getColumnModel().getColumn(0).setCellEditor(de);
  yourTable.getColumnModel().getColumn(0).setCellRenderer(dr);That should do it !
Cheers

Similar Messages

  • Alv add new row with counter

    Hello.
    I would like to add a new row to an ALV GRID CONTROL in which one of the fields is a counter. Which methods, codes have I to change/write?
    For example:
    ALV
    COUNTER FLIGHT DESTINATION
    1     1234  CDG
    2     3443  SVQ
    On adding a new row :
    COUNTER FLIGHT DESTINATION
    1     1234  CDG
    2     3443  SVQ
    3
    Thanks in advance!!!

    There are two options.
    1.  Use the data_changed event to put in the values.
    - Enable edit mode for the grid, so the row create/insert/copy icons appear on the toolbar. 
    - Create an event handler for the DATA_CHANGED event
    - In this method, use attribute table er_data_changed->MT_INSERTED_ROWS to check for new rows, and then er_data_changed->modify_cell to put in the line number.
    The problem is that if your counter field is set as non-editable, then you cannot put a value in...
    2.  implement your own add function.
    - Add a button to the toolbar (implement methiod for event handle_toolbar)
    - Create an event handler for event handle_user_command.
    - In the handler method, add a row to the outtab table used by the grid (with the correct line number).
    - CALL METHOD gr_grid->refresh_table_display to update the display with the additional line.
    Regards
    Michael

  • Add new row in the same page

    Can anyone give me the code for adding the new row in the same page itself.If we click on add button a new row should come in the table.
    Thanks in advance

    Hi,
    invoke a method in AM on button click
    public void addrows()
    AddressesVOImpl vo1 = getAAddressesVO1();
    AddressesVORowImpl row1 = (AddressesVORowImpl)vo1.createRow();
    vo1.insertRowAtRangeIndex(0,row1);
    vo1.setCurrentRow(row1);
    Thanks,
    Gaurav

  • How to add new row at the top of the advance table.

    Hi,
    I have one advanced table.
    I want to add new rows in advanced table. I can able to add rows using the AddMoreRows button in the footer of the advanced table.
    This adds the row at the end. But I want to add the row at the top.
    How to achive this? Please suggest.
    Thanks & Regards,
    Raja

    Hi,
    Yes you can do it...
    Just set the add Rows automatically property to False of Add Row Button
    and then in processForm Request capture the addRows event
    and invoke a method in AM and then create a new Row in VO.
    Use this code...it will insert row at the top...
    if("addRows".equals(event))
    am.invokeMethod("addrows");
    public void addrows()
    AddressesVOImpl vo1 = getAddressesVO1();
    AddressesVORowImpl row1 = (AddressesVORowImpl)vo1.createRow();
    vo1.insertRowAtRangeIndex(0,row1);
    vo1.setCurrentRow(row1);
    Thanks,
    Gaurav

  • Add new Row at the bottom of the advance table

    Hi,
    I have an advance table which is displaying 50 rows per page. I have a button at the bottom of the table to add a new row in the table.
    Requirement is whenever user clicks on the button to add a new row and if he is viewing the 50-100 rows, new row should be added at the bottom of the same page giving 101st row as new row.
    Is this functionality possible. Please let me know the code for the same.
    Thanks in advance,
    Kaushik

    Hi,
    If the records displayed is set to 50 then at one time only 50 records will be visible.
    101st row will be inserted at seperate navigation 100-150.
    Instead you can insert the row at the top so that 100th row gets shifted to 101 and new row becomes on the same page
    for this use
    vo.insertRowatRangeIndex(row,0);
    Thanks,
    Gaurav

  • Add new report with a checkbox form

    I’m trying to create a list with check boxes to add “contacts to a event”.
    I have my table contacts and events, when I create a event I should invite my contacts. I want to create a list with all my contacts with a checkbox option and populate a new table with all the assistance.
    I’m searching but I can’t find info.
    I hope you have some time thank you
    Rodrigo

    You can create a checkbox in your list with APEX_ITEM.CHECKBOX. There are quite a few examples to be found when you google, e.g.
    http://www.apex-blog.com/oracle-apex/adding-a-checkbox-to-your-report-apex_item-tutorial-30.html
    One time I just created a default tabular form with DELETE functionality, so the checkboxes were already in place. I just created another process instead of the normal MRU process. Went pretty well actually.

  • How to add new row in KL02 trx - Activity type control data

    Hi guys.
    I am not a FI-CO consultant, but I want to add a row since KL02 transaction within a cost center, with a new fiscal year. When you access KL02 (change activity type), you set the activity type, then press Master Data and the basic screen appears. If you press the Display planning control button, you will see the "Display Activity Type Control Data" List. I wanna add a row for a specific cost center here, because the cost center I refer has not 2011 as fiscal year. I tried to use, since basic screen of KL02, use the Change planning control button, but when I set my cost center and 2011 as fiscal year, the Save button is inactive. Furthermore, I tried to press the Period screen and a message appeared "No data has been entered yet". So I dont know how to add one row for a cost center in the Planning control (Activity type control data) list of the KL02 transaction, specifically for an activity type. Do you know? Thanks in advance

    Hi,
    The list of cost centers in which the activity type is planned is given in KL02 under planning data.  In order to add a new cost center to this, you need to enter the activity type in transaction KP26 for a particular year. 
    Goto transaction KP26
    Give version - 0
    from period 1 to 12
    year - 2011
    cost center - mention the cost center
    Activity type - mention activity type
    goto overview screen F5 and add the plan price for the activity in the cost center.  This step will automatically add new row in the activity type control data.
    Hope this helps.
    Thanks,
    Ram

  • Editable ALV (CL_GUI_ALV_GRID) Pasting add new rows

    Hi all,
    I have a problem with OO ALV.
    I'm using class CL_GUI_ALV_GRID as I need to have a couple of editable columns.
    Let's say that we have columns Material and Quantity. And Quantity is editable.
    Toolbar buttons for adding new rows, paste, copy, are all disabled.
    Suppose I have 2 rows in the ALV.
    If I copy to clipboard from, for example, Excel, more than 2 rows, and paste them in Quantity column of the ALV, the result is that new rows are inserted till all the information in the clipboard is pasted. The new rows have all blank values except for the column I'm pasting.
    I do not want this rows inserted. I supposed that this wounldn't happened, as there are no buttons for inserting rows.
    Anybody knows how to change this behaviour?
    Thanks a lot.
    Alejandro Galliano.

    Hi Alejandro,
      You can implement your own functionality to create new row.You can add your own button in ALV   for New row creation. In another simple way is you place the button in the screen which display the ALV and implement the logic in PAI of the screen.
    the logic is simple add new row in the internal table which you are using to display ALV and refresh the ALV.Then your new row will appear in the Grid.
    Regards,
    Mike

  • Insert new rows based on user selection on a table display on the screen

    Hi..
    In my requirement i need to display the line items of a PO# to the user on the screen for specific fields. Each row should also include an additonal checkbox when displayed for the user. When the user checks this check box or clicks on it a new row should be inserted below to that row with the existing data of that row being copied to newly inserted row and allowing the user to make any changes.
    The newly inserted row should also include a check box , so that when the user checks it again a new row should get inserted. Finally what ever data user enters on the screen, i should be able to update my internal table with those new values and records.
    Appreciate if anyone can guide me on how to proceed on this or any alternative approaches.
    Will reward helpful answers.
    Thanks.

    Hi ..
    Can you please be more detailed. First I need to know how to create the initial table display for the existing line items and then the techniques for inserting the new rows based on the check marks and finally add those news rows to my existing internal table..
    Appreciate ur help.
    Thanks.

  • Add a new row at the top of a table in GUI

    Hi,
    I am using JDev 11.1.1.1.0. I need to be able to let users add a new row at the top of a table and not anywhere else in the middle of table rows. I cannot seem to find a way to do it. note that it does not matter where a new row gets inserted in the db, i am only concerned about restricting the insert in the GUI to the topmost line/row.
    Thanks,
    AJ

    Hi
    Can you try with writing your custom create method in application module and calling same from UI on command button action like
    public void createNewRow()
    ViewObjectImpl vo = getVO1();
    Row newRow= vo.createRow()
    vo.insertRowAtRangeIndex(0, newRow);
    Vikram

  • How to add a new row at the top of manual tabular form

    I have a manual tablular form. I'm trying to add a row at the top of the form, instead of new row of being displayed at the bottom. any ideas are appreciated.
    thanks,
    Surya

    This will depend on two things:
    1. sorting of the columns - needs to be a some kind of a descending sorting on a hidden column, enabled within the Report Attributes and not in the SQL Query
    2. Report Attributes => Layout and Pagination => Sort Nulls First
    You will need to play with those settings a bit. One thing to consider is that you should sort your report on a hidden column and you shuldn't enable the sorting on visible columns, because it will mess up your row positioning.
    See this example:
    http://apex.oracle.com/pls/otn/f?p=31517:215
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • To add new row to record the stability sample.

    dear all
                    There is new requirement to add new row to record the stabilty sample in the inspection lot stock tabpage of  QA11 usage decision. As we have configured sample usage row to record the sample which we take for testing purpose 
    and we use to reserves row to record the control samples of the batches which we sell in the domestic and export market.
    I require the solution in this context.
    thanks
    with regards
    Harish Ramachandran

    Thanks for all your help. My problem was that I was using 2 lists to update the table. The problem solve!!!!
    int modelIndex = listWhenScrollStop.size () - 1 - aRow;
    if (modelIndex >= 0) {
    return listWhenScrollStop.get (listWhenScrollStop.size () - 1 - aRow);

  • Can I make the table in Numbers automatically add new rows as I go?

    I am working on a list of expenses with a total at the bottom but when I run out of rows, it doesn't add them in like Excel would. I am missing something?

    If I understand what your problem is, you have something like
    =SUM(A1:A5) for the sum, and when you add a new row to the bottom row (before the SUM), the formula doesn't change. It's still =SUM(A1:A5) even though now you have A6. So now you have a row which is "orphaned." This happens even when you have a footer row.
    Use this instead:
    =SUM(A)
    That way when you add rows, the new rows will always be included in the sum. The footer row will not be included.
    You can also use names. Like
    =SUM(Sales) instead of the Column letter, if you have "Use header cell names as references" checked in preferences.
    A new row will automatically be added above the footer row if you hit Return or Enter twice.
    Hope this answers your question.

  • HT5621 I changed my Apple ID but on my iPhone when I go into settings iCloud it still shows the old Apple ID. How do I change this? I was going to delete the iCloud account from my phone then add it back with the new Apple ID, but I'm not sure...help!

    I changed my Apple ID but on my iPhone 4S w/ iOS 7.0.4, when I go into settings > iCloud it still shows the old Apple ID. How do I change this? I was going to delete the iCloud account from my phone then add it back with the new Apple ID, but I'm not sure...help!

    http://support.apple.com/kb/TS5223?viewlocale=en_US
    Peace, Clyde

  • Need to add a new row at the end of the table

    Experts,
    working jdev 11.1.1.3.0
    i am adding row programetically, my requirement need to add the row at after last row.
    i tried different ways.
    Row newLastRow = getPWBBidLaneVO().last();
    int lastRowIndex = getPWBBidLaneVO().getRangeIndexOf(newLastRow);
    getPWBBidLaneVO().insertRowAtRangeIndex(lastRowIndex - 1,
    laneRow);
    this is giving --- java.lang.ArrayIndexOutOfBoundsException: 0
    and
    http://kohlivikram.blogspot.com/2008/10/add-new-row-in-adf-table-on-button.html --- its giving index out of bound because vo.getRangeSize() is 25. We set this value at vo for performance improment suggestions.
    is there a way to add a new row at the end of the table?

    Add this to the view row impl class
           public void insertRow(Row row) {
               //go to the end of Rowset if it has rows
               Row lastRow = this.last();
               if (lastRow !=null){
                    //insert new row at the end and make it current
                   int indx = this.getRangeIndexOf(lastRow)+1;
                   this.insertRowAtRangeIndex(indx,row);
                   this.setCurrentRow(row);
               }else { // empty Rowset
               super.insertRow(row);
               }

Maybe you are looking for

  • Do we need to have workflow in place to send payslip by email?

    Do we need to have workflow in place to send employee monthly payslip by email? And if we can send it without workflow, then, is there is any involvement of ABAP? Can system use the email address maintained in the infotype for an employee?

  • Losing all my recordings due to an upgrade

    I've just been informed that I will lose all my recordings due to an upgrade in 30 days time. Unfortunately the 2 weeks prior to this I am on holiday and wanted to record things whilst I'm away. Frankly, I am appalled that any upgrade should make us

  • Diff between for & while

    what is the difference between exception & error

  • Need to set a user to administrator account

    Just bought a new MacBook Pro, but cannot add applications and am getting the "...installation requires administrator priveleges" message. Just need to know how to set the lone account (mine) to administrator privileges. Thanks in advance.

  • How to re-set rownumber on a group

    Ex: Select rownum, clientID, amt from clients group by clientID Results should be Row Client ID 1 9899 $25 2 9889 $68 1 2535 $25 1 2535 $124