Updating table cell

Hi,
I have a requirement for my application. I need to display a timer inside the cell of JTable. The table will be displaying records of multiple users visiting the site. The column should display the total time spent on the page. I am using a customized Table Model. How can I go about it?
Thanks,
Ajit

Hi,
See the following coding.
In short,
&lt b &rt tableModel.fireTableCellUpdated(row,column); &lt /b &rt
raises the event. So that JTable will listen that event, and updates
that particular cell only.
You can create a thread, that keeps track of website visiting
log of all persons. If the time change, you can invoke that method.
import javax.swing.*;
import javax.swing.border.DefaultTableModel;
public class MyModel extends DefaultTableModel
Object [] items;
          public MyModel(Object [] items) {
               this.items=items;
          public int getColumnCount() {
               return 2;
          public int getRowCount() {
               return 4;
          public Object getValueAt(int row,int column) {
               // The first column is fixed Item 1, Item 2, Item 3 etc.
               if(column==0)
                    return "Person "+(row+1);
               // The second column varies with "items".
               else
                    return items[row]+" seconds";
public static void main(String []args) {
          JFrame f=new JFrame("Testing single cell editor");
          final Object items[]=new Object[]{"1","2","3","4"};
          final MyModel model=new MyModel(items);
          // A table with 2 rows and 2 columns
          JTable table=new JTable(model);//new OurTableModel());
          // Set our editor as table's editor
          //table.setDefaultEditor(Object.class,new SingleCellEditor());
          // Add to a scroll pane
          JScrollPane pane=new JScrollPane(table);
          pane.setBounds(50,50,200,200);
          f.getContentPane().setLayout(null);
          f.getContentPane().add(pane);
          // Close on exit
          f.setDefaultCloseOperation(3);
          // Show the frame
          f.show();
          Thread t=new Thread() {
               public void run() {
                    while(true) {
                              try {
                                   Thread.sleep(1000);
                                   items[2]=""+(Integer.parseInt(""+items[2])+1);
                                   model.fireTableCellUpdated(2,1);
                              catch (InterruptedException ignored)     {
          t.start();
See that there my be compilation errors. But the logic is same. The same
I applied and got it.
Bye.. Bye..

Similar Messages

  • Problem updating table Cell display

    Hi, any ideas about this problem would be very much appreciated Ive had it for 6 months but have been unable to get to the bottom of it.
    I have an application which contains a JSplitPane with two tables , when the application starts both tables contain the same data. The 1st table is a read view, the bottom display is an edit view. When I make a change to a table cell in the bottom view it changes colour and the corresponding cell in the top view also changes it colour (bit not value) to indicate that the cell has been edited.
    The problem is that the top cell only changes colour if the top cell as displayed is large enough to show the complete value. If i then click on the cell in the top view it will correctly change colour. If I move the columns in the top pane about a bit, all subsequent modifications in the bottom pane will correctly change the cell colour in the top pane !
    (My renderer extends JPanel rather than JLabel.)

    Make sure you fire the appropriate fireTableCellUpdated() method from both TableModel's so that the view knows to redraw that cell. Ideally, both of your tables would share the same table model, but only one would allow editing. You could accomplish that by putting a facade table model over top the real table model that just overrode the isEditable method to reutrn false always, and all other methods would pass through to the real model. That way as changes were made to the table model (no matter who made the change), the views would stay in sync because they were based on the same model, getting all the same events, etc.

  • Updating table

    hi friends,
    i have one table in my application. i will update cells by enetering data into it. here the problem is after i typed digits i need to press
    ENTER or i need to press TAB to update the entered value into table cell. is there any way that without pressing ENTER or TAB to update table cell. and also i need to restrict max number of digits to 2. how can i do that. please help me in this proble. due to this a lot of bugs are coming for me.
    thanks and regard
    sriram

    hi sriram,
    Hope u might have implemented the key listener while typing if the in put key value of that cell is >2 put ,e.consume() will work out and further ur second query to update automatic is little bit odd any way u can do by fiering tableChangedListener in key pressed event .
    if u want brief help contact [email protected]

  • DYNP_VALUES_UPDATE to update table control cell

    How can I update a cell (e.g. in line n) value in a table control using the function DYNP_VALUES_UPDATE? Can someone give me an example?
    Thanks in advance.
    Adhimas S.

    Hi,
    Check this sample code
    REPORT ZVV.
    tables tcurt.
    DATA   DYFIELDS LIKE DYNPREAD OCCURS 1 WITH HEADER LINE.
    PARAMETERS: P_WAERS LIKE TCURT-WAERS,        "Currency
                P_LTEXT LIKE TCURT-LTEXT,        "Long Text
                P_KTEXT LIKE TCURT-KTEXT.        "Short Text
    *--- Example of updating value of another field on the screen -
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_WAERS.
      CLEAR: DYFIELDS[], DYFIELDS.
    *--- select currency
      CALL FUNCTION 'HELP_VALUES_GET'
           EXPORTING
                fieldname        =  'WAERS'
                tabname          =  'TCURT'
           IMPORTING
                SELECT_VALUE     =   P_WAERS.
    *--- get long text for the selected currency
      SELECT SINGLE LTEXT FROM TCURT
        INTO DYFIELDS-FIELDVALUE
        WHERE SPRAS = SY-LANGU
        AND   WAERS = P_WAERS.
      IF SY-SUBRC <> 0.
        CLEAR DYFIELDS-FIELDVALUE.
      ENDIF.
    *--- update another field
      DYFIELDS-FIELDNAME = 'P_LTEXT'.
      APPEND DYFIELDS.
      CALL FUNCTION 'DYNP_VALUES_UPDATE'
           EXPORTING
                DYNAME               = SY-CPROG
                DYNUMB               = SY-DYNNR
           tables
                dynpfields           = DYFIELDS .
    *--- Example of reading value of another field -
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_KTEXT.
    *--- read another field
      CLEAR: DYFIELDS[], DYFIELDS.
      DYFIELDS-FIELDNAME = 'P_WAERS'.
      APPEND DYFIELDS.
      CALL FUNCTION 'DYNP_VALUES_READ'
           EXPORTING
                DYNAME                   = SY-CPROG
                DYNUMB                   = SY-DYNNR
           TABLES
                DYNPFIELDS               = DYFIELDS .
      READ TABLE DYFIELDS INDEX 1.
    *--- get short text and update current field
      SELECT SINGLE KTEXT FROM TCURT
        INTO P_KTEXT
        WHERE SPRAS EQ SY-LANGU
        AND   WAERS EQ DYFIELDS-FIELDVALUE.
    Thanks & Regards,
    Judith.

  • Problem trying to update a table cell

    Hello all,
    I'm trying to implement a setValueAt method using an arrayList.....no success. Could anyone help?
    When trying to change the a value in the table I get these errors:
    "Exception occurred during event dispatching:
    java.lang.ClassCastException: java.lang.String
    at CachingResultSetTableModel.getValueAt(CachingResultSetTableModel.java:37)
    at javax.swing.JTable.getValueAt(JTable.java:1711)
    at javax.swing.JTable.prepareRenderer(JTable.java:3530)"
    public void setValueAt(Object avalue, int r, int c){
    if(r < cache.size()){
    row[c] = (Object[])cache.set(r, avalue);
    fireTableCellUpdated(r, c);
    }//setValueAt
    *********For reference here's the getValueAt method*************************
    public Object getValueAt(int r, int c){
    if(r < cache.size()){
    row = (Object[])cache.get(r);
    return row[c];
    else
    return null;
    }//getValueAt

    Hello,
    I am new at implementing this a table model and JTable, so all I am working with is the mainApp, the model, and the JTable. I am not too sure if and what listeners I should setup.
    I can compile the program. After the data is presented in the table, I try to change a value in one of the cells. Once I have clicked out of the cell I get the ClassCastException: java.lang.String error. I believe the exception is being created by the data I am entering. Do you know of any links that could help me figure how to properly update a cell.
    Determen

  • Just update to Pages 5.1 - its dropped the pictures from my Pages files - 'Some features aren't supported - objects in table cells were removed' - how do I get pictures back?

    Just update to Pages 5.1 - its dropped the pictures from my old Pages files - 'Some features aren't supported - objects in table cells were removed' - how do I get the pictures back?

    Thanks Peter
    Can you just walk me through dumping Pages 5 and getting to the Applications/iWork folder - and does this mean that when I see future Pages Upgrades I should block them?
    I'm new to Apple so need a step by step
    Many thanks
    Glyptic

  • Update pivot table cell then refresh

     I want to update my pivot table that connects to my SQL2008R2 AS. The requirement is to update the ship date with cuurent date then refresh
    all Tabs with WorkBook. Here is my code that doesn't allow me to update the cell. The xcel version is 2003.
    $year=(Get-Date).Year
    $month="{0:dd-MMM}" -f (Get-Date)
    $sdate="{0:yyyy-MM-dd}" -f (Get-Date)
    # Create base object
    $xl = new-object -comobject Excel.Application
    # make Excel visible
    #$xl.visible = $true
    $xl.DisplayAlerts = $False
    # open a workbook
    $wb = $xl.workbooks.open("C:\archive\ShipmentDetailEur.v4.xls")
    # Get sheet1
    $ws = $wb.worksheets | where {$_.name -eq "CustShipmentDetail"}
    $sdate=[char]39 + "{0:yyyy-MM-dd}" -f (Get-Date) # '2012-08-30
    $ws.Cells.Item(11,2) = $sdate
    $wb.Save()
    #logging stuff
    Write-Host $wb.Name
    write-host $wb.Path
    $xl.Quit()
      Error:
    Exception setting "Item": "You cannot select an item in this field
     Thanks.
        

    Hi Hart60,
    I could not reproduce the error you posted, however, To update the item in the Excel cell, please refer to the script:
    $ExcelPath = 'd:\merge3.xlsx'
    $Excel = New-Object -ComObject Excel.Application
    $Excel.Visible = $true
    $ExcelWordBook = $Excel.Workbooks.Open($ExcelPath)
    $ExcelWorkSheet = $Excel.WorkSheets.item("CustShipmentDetail")
    $ExcelWorkSheet.Cells.Item(2,1).Value2 = "teststring"
    $ExcelWorkSheet.SaveAs("d:\merge3.xlsx")
    ## quit the workbook
    $Excel.Quit()
    For more detailed information, please go through this article:
    Modifying Excel Documents with PowerShell
    If there is anything else regarding this matter, please feel free to let me know.
    Best Regards,
    Anna Wang

  • Auto update of time/date in a table cell in pages

    I used to be able to do this in older versions.
    In pages when I have a table cell with time/date I would like to have the current date show up every time I open the document. Not on every date in the document, but just in a set cell in a  table.

    Hi Brian,
    Use the NOW function.
    Menu > Insert > Formula > Edit Formula
    Regards,
    Ian.

  • How to create a context menu in ALV table cell editor(Webdynpro abap )

    Hello Experts,
    I am having a problem in creating a context menu in a table cell editor in the ALV table output.I have assigned a 'lta' as the cell editor.But befor assigning the lta as cell editor I have assigned the menu to the lta.But when the view is rendered I can see the lta with the actioned assigned to it.But I cannot see the context menu.
    The code snippet below:
      "Create menu for each coloumn
      create OBJECT lo_menu_actions type CL_SALV_WD_VE_MENU EXPORTING
          id = 'MITM_ACTIONS'.
      lo_menu_actions->set_visible( value = abap_true ). 
      lo_menu_actions->set_visible_fieldname( value = 'ACTIONS' ).
      "ADd menu items
      CREATE OBJECT lo_menu_item_create type CL_SALV_WD_VE_MENU
      exporting
        id = 'MITM_CREATE_EXPRESSION'.
      lo_menu_item_create->set_visible( value = abap_true ).
      lo_menu_item_create->set_visible_fieldname( value = 'Create' ).
      "Add item 1
      lo_menu_actions->ADD_ITEM( VALUE = lo_menu_item_create ). 
      "  Set the cell editor for each column cell(link to an action)
      LOOP AT lt_node_dec_tab_cols INTO ls_node_dec_tab_cols .
        lv_column_name = ls_node_dec_tab_cols-object_name.
        lr_column = lr_column_settings->get_column( lv_column_name ).
       "Create 'lta' Ui item
        CREATE OBJECT lo_lta TYPE cl_salv_wd_uie_link_to_action.
        lo_lta->set_menu( value = lo_menu_actions ).
        lo_lta->set_text_fieldname( lv_column_name ).
        lr_column->set_cell_editor( lo_lta ).
        IF ls_node_dec_tab_cols-is_result EQ abap_true.
          lr_column->set_cell_design( value =
                      cl_wd_table_column=>e_cell_design-key_medium ).
        ENDIF.
      ENDLOOP.

    Hi Prakash,
    I have not come across this requirement till now to have context menu in a cell editor of alv.
    Unfortunately  the implementation of method SET_MENU of alv ui elements ( ex: cl_salv_wd_uie_text_view ) is not updating alv configurable table, instead it just stores in a global attribute as string. Hence has no effect on context menu.
    If your user is very particular about this requirement of having context menu in cell editor, you can go for a normal table. Because, normal table's cell editor has the property to set the menuID as we do it for other ui elements.
    Regards,
    Rama

  • Help with UPDATE table and database RELATIONSHIPS

    HI there, I have been trying to create an update table for
    weeks now and keep getting error messages.
    The database has a table named:
    "books" in the table cells are "idbook" and "book".
    "suppliers" in the table cells are "idsupplier" and
    "supplierName".
    "category" in the table cells are "idcategory" and
    categoryName"
    They all have a relationships with this table:
    "results" in the cells are "idbook", "idsupplier" and
    "idcategory".
    This "results" table brings all of the above tables together.
    When I try to do an update, i am doing one to the results
    table. Is this correct?
    The updates have problems because when drawing the text to
    the update table to view it comes in text form.
    When trying to update, it wont becuase all of the cells in
    the results table are numeric. This is because of the
    relationships.
    Can anyone suggest where i may be going wrong.
    Ask anything you need to.
    TA

    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close
    If (MM_editRedirectUrl <> "") Then
    Response.Redirect(MM_editRedirectUrl)
    End If
    End If
    End If
    %>
    <%
    Dim Recordset1__MMColParam
    Recordset1__MMColParam = "1"
    If (Session("MM_UserName") <> "") Then
    Recordset1__MMColParam = Session("MM_UserName")
    End If
    %>
    <%
    Dim Recordset1
    Dim Recordset1_numRows
    Set Recordset1 = Server.CreateObject("ADODB.Recordset")
    Recordset1.ActiveConnection = MM_connSeek_STRING
    Recordset1.Source = "SELECT * FROM Query1 WHERE UserName = '"
    + Replace(Recordset1__MMColParam, "'", "''") + "'"
    Recordset1.CursorType = 0
    Recordset1.CursorLocation = 2
    Recordset1.LockType = 1
    Recordset1.Open()
    Recordset1_numRows = 0
    %>
    <%
    Dim rsUpdate
    Dim rsUpdate_numRows
    Set rsUpdate = Server.CreateObject("ADODB.Recordset")
    rsUpdate.ActiveConnection = MM_connSeek_STRING
    rsUpdate.Source = "SELECT * FROM tblSpecies"
    rsUpdate.CursorType = 0
    rsUpdate.CursorLocation = 2
    rsUpdate.LockType = 1
    rsUpdate.Open()
    rsUpdate_numRows = 0
    %>
    <%
    Dim Repeat1__numRows
    Dim Repeat1__index
    Repeat1__numRows = -1
    Repeat1__index = 0
    Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
    %>
    <html>
    <head>
    <link href="css%20files/paragraph.css" rel="stylesheet"
    type="text/css">
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new
    Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0;
    i<a.length; i++)
    if (a
    .indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a;}}
    //-->
    </script>
    </head>
    <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0"
    marginwidth="0" marginheight="0"
    onLoad="MM_preloadImages('images/Publicationb.gif','images/Factsheetsb.gif')">
    <table width="100%" height="100%" border="1"
    cellpadding="0" cellspacing="0" bordercolor="#5D5D5D">
    <tr>
    <td colspan="2">
    <div align="right"></div>
    <div align="left"></div>
    </td>
    </tr>
    <tr>
    <td colspan="2"><table width="100%" height="100%"
    border="0" cellpadding="0" cellspacing="0"
    bordercolor="#5D5D5D">
    <tr>
    <td valign="top"><form
    ACTION="<%=MM_editAction%>" METHOD="POST" name="form1">
    <table width="90%" border="0" align="center"
    cellpadding="0" cellspacing="0">
    <tr>
    <td valign="top"><div
    align="center"></div> <table border="1" align="center"
    cellpadding="2" cellspacing="0" bordercolor="#FFFFFF">
    <tr bgcolor="ECECD7">
    <td colspan="2"><div align="center">
    <p><strong><font size="3">Update Key Word
    &amp; Category</font></strong></p>
    </div>
    </td>
    </tr>
    <tr>
    <td><div align="center">
    <p><font size="1">Enter Up to 10 Species /
    Product
    Name</font></p>
    </div>
    </td>
    <td><div align="center">
    <p><font size="1">Select a
    Category</font></p>
    </div>
    </td>
    </tr>
    <tr>
    <td colspan="2" bordercolor="#D0D09D">
    <%
    While ((Repeat1__numRows <> 0) AND (NOT
    Recordset1.EOF))
    %>
    <table width="100%" border="0" cellspacing="0"
    cellpadding="0">
    <tr><td width="50%"><div align="center">
    <input name="f1" type="text" id="f13"
    value="<%=(Recordset1.Fields.Item("TimberSpecies").Value)%>"
    size="33">
    </div></td>
    <td width="45%"><div
    align="center"></div></td></tr></table>
    <%
    Repeat1__index=Repeat1__index+1
    Repeat1__numRows=Repeat1__numRows-1
    Recordset1.MoveNext()
    Wend %>
    <div align="center"> </div> <div
    align="center">
    </div></td></tr><tr>td
    colspan="2"> </td></tr><tr><td
    colspan="2"><div align="right"><p><font
    size="1">To Finalise Your Changes Please Press the Update
    Button      
    <input name="update2" type="submit" id="update"
    value="Update">
    <input type="hidden" name="MM_update" value="form1">
    <input type="hidden" name="MM_recordId" value="<%=
    rsUpdate.Fields.Item("TimberSpecies").Value %>">

  • How to populate change from one Table cell to more Tables??

    Dear Friends:
    I have following successfully running code, each can populate 1 table cell updating in ChangeTableSelectionMain1 change to another table in ChangeTableSelectionMain1 also, or populate 1 table cell in ChangeTableSelectionSub1 change to another table in ChangeTableSelectionSub1 also, But cannot populate table cell updating in ChangeTableSelectionMain1 to ChangeTableSelectionSub1, Please advice how to make populating table cell updating in ChangeTableSelectionMain1 to ChangeTableSelectionSub1 successful??
    Thanks.
    [1]. main code:
    package com.com;
    import java.awt.BorderLayout;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JSplitPane;
    import java.awt.GridLayout;
    public class ChangeTableControl1 implements java.io.Serializable{
         private JFrame                frame;
         public static void main(String args[]) {
              try {
                   ChangeTableControl1 window = new ChangeTableControl1();
                   window.frame.setVisible(true);
              } catch (Exception e) {
                   e.printStackTrace();
          * Create the application
         public ChangeTableControl1() {
              initialize();
          * Initialize the contents of the frame
         private void initialize() {
              frame = new JFrame();
              frame.setBounds(0, 0, 1500, 675);
              final ChangeTableSelectionMain1      c1      = new ChangeTableSelectionMain1();
              final ChangeTableSelectionSub1           c2      = new ChangeTableSelectionSub1();
              JSplitPane sp = new JSplitPane();          
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              final JPanel panel = new JPanel();
              panel.setLayout(new GridLayout(1, 2));
              frame.getContentPane().add(panel, BorderLayout.CENTER);
              sp.setLeftComponent(c1);
              sp.setRightComponent(c2);
              sp.setResizeWeight(0.5);
              panel.add(sp);// add right part
                frame.addWindowListener(new WindowAdapter() {
                     public void windowClosing(WindowEvent e) {
                         System.exit(0);
                 frame.pack();
                 frame.setVisible(true);
    }[2]. ChangeTableSelectionSub1
    package com.com;
    import javax.swing.JTable;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.event.TableModelEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import java.awt.FlowLayout;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;
    import java.text.SimpleDateFormat;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    import java.awt.BorderLayout;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTable;
    public class ChangeTableSelectionSub1 extends JPanel{
           protected         JButton                bt11 = new JButton("Insert before");
           protected         JButton                bt22 = new JButton("Insert after");
           protected         JButton                bt33 = new JButton("Delete");
           protected      ChangeTableSelectionMain1 lm = new ChangeTableSelectionMain1();
    public ChangeTableSelectionSub1() {
         JPanel pnl = new JPanel();
         pnl.setMinimumSize(new Dimension(200,600));
              //pnl.setPreferredSize(new Dimension(800,600));
              final JTable tbl1 = new JTable(lm.data,lm.columnNames);
              final JTable tbl2 = new JTable(lm.data,lm.columnNames);
              JScrollPane scr1 = new JScrollPane(tbl1);
              JScrollPane scr2 = new JScrollPane(tbl2);
              lm.tbl1.getSelectionModel().addListSelectionListener(new ListSelectionListener()
              public void valueChanged(ListSelectionEvent lse)
                   if (lm.tbl1.getSelectedRow()!=-1)
                        tbl2.clearSelection();
                        System.out.print("[1]. LongguChangeTableSelectionSub get msg from LongguChangeTableSelectionMain");
                        tbl1.clearSelection();
                        revalidate();
              lm.tbl2.getSelectionModel().addListSelectionListener(new ListSelectionListener()
         public void valueChanged(ListSelectionEvent lse)
              if (tbl2.getSelectedRow()!=-1)
                   tbl1.clearSelection();
              System.out.print("[2]. LongguChangeTableSelectionSub get msg from LongguChangeTableSelectionMain");
              revalidate();
         pnl.setLayout(new FlowLayout());
         pnl.add(scr1);
         pnl.add(scr2);
         this.add(pnl);
    public static void main(String []args)
         ChangeTableSelectionSub1 c = new ChangeTableSelectionSub1();
         JFrame frm = new JFrame();
         frm.setSize(920,400);
         frm.getContentPane().add(c);
         frm.setVisible(true);
    }[3]. ChangeTableSelectionMain1
    package com.com;
    import javax.swing.JTable;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.JScrollPane;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import java.awt.FlowLayout;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.*;
    import javax.swing.*;
    public class ChangeTableSelectionMain1 extends JPanel{
           protected         JButton                bt11 = new JButton("Insert before");
           protected         JButton                bt22 = new JButton("Insert after");
           protected         JButton                bt33 = new JButton("Delete");
           protected String[] columnNames = {"First Name",
                        "Last Name",
                        "Sport",
                        "# of Years",
                        "Vegetarian"};
           protected Object[][] data = {
              {"Mary", "Campione","Snowboarding", new Integer(5), new Boolean(false)},
              {"Alison", "Huml","Rowing", new Integer(3), new Boolean(true)},
              {"Kathy", "Walrath","Knitting", new Integer(2), new Boolean(false)},
              {"Sharon", "Zakhour","Speed reading", new Integer(20), new Boolean(true)},
              {"Philip", "Milne","Pool", new Integer(10), new Boolean(false)} };
           protected JTable tbl1 = new JTable(data,columnNames);
           protected JTable tbl2 = new JTable(data,columnNames);
    public ChangeTableSelectionMain1() {
         JPanel pnl = new JPanel();
         pnl.setMinimumSize(new Dimension(200,600));
              //pnl.setPreferredSize(new Dimension(800,600));
              JScrollPane scr1 = new JScrollPane(tbl1);
              JScrollPane scr2 = new JScrollPane(tbl2);
              tbl1.getSelectionModel().addListSelectionListener(new ListSelectionListener()
              public void valueChanged(ListSelectionEvent lse)
                   if (tbl1.getSelectedRow()!=-1)
                        tbl2.clearSelection();
                   if (lse.getValueIsAdjusting())
                       System.out.println("Selected from " + lse.getFirstIndex() + " to " + lse.getLastIndex());
                   revalidate();             
              tbl2.getSelectionModel().addListSelectionListener(new ListSelectionListener()
         public void valueChanged(ListSelectionEvent lse)
              if (tbl2.getSelectedRow()!=-1)
                   tbl1.clearSelection();
                   revalidate();
         pnl.setLayout(new FlowLayout());
         pnl.add(scr1);
         pnl.add(scr2);
         this.add(pnl);
    public static void main(String []args)
         ChangeTableSelectionMain1 c = new ChangeTableSelectionMain1();
         JFrame frm = new JFrame();
         frm.setSize(920,400);
         frm.getContentPane().add(c);
         frm.setVisible(true);
    }Message was edited by:
    sunnymanman

    I have following successfully running code, each can populate 1 table cell updating in ChangeTableSelectionMain1 change to another table in ChangeTableSelectionMain1 also, or populate 1 table cell in ChangeTableSelectionSub1 change to another table in ChangeTableSelectionSub1 also, But cannot populate table cell updating in ChangeTableSelectionMain1 to ChangeTableSelectionSub1, Please advice how to make populating table cell updating in ChangeTableSelectionMain1 to ChangeTableSelectionSub1 successful??
    My brain hurts, does yours?

  • How can I write into a table cell (row, column are given) in a databae?

    How can I write into a table cell (row, column are given) in a database using LabVIEW Database Toolkit? I am using Ms Access. Suppose I have three columns in a table, I write 1st row of 1st column, then 1st row of 3rd column. The problem I am having is after writing the 1st row 1st column, the reference goes to second row and if I write into 3rd column, it goes to 2nd row 3rd column. Any suggestion? 
    Solved!
    Go to Solution.

    When you do a SQL INSERT command, you create a new row. If you want to change an existing row, you have to use the UPDATE command (i.e. UPDATE tablename SET column = value WHERE some_column=some_value). The some_column could be the unique ID of each row, a date/time, etc.
    I have no idea what function to use in the toolkit to execute a SQL command since I don't use the toolkit. I also don't understand why you just don't do a single INSERT. It would be much faster.

  • InDesign CS6 Font doesn't work in table cells

    Hi all!
    I'm working in InDesign CS6 on Mac OS 10.6 Leopard.  I have character and paragraph styles defined using a certain font, and they work just fine except when using them in table cells.  I have the character style nested in the paragraph style, which is then used in the cell style.  But it doesn't work.  It inherits everything correctly except for the font.  If I select the text, the font menu tells me it is the correct font, but it displays in a different font.  I've tried exporting to IDML and resaving, but that didn't work.  I'm stumped

    Hi Jeffrey-
    Indeed it should, and I see why using a formatted table would cause conflicts, but I am importing it as an unformatted table already.  Built all styles in InDesign first, then imported as unformatted table.  A few times it did work as expected, but most of the time it steadfastly refused to apply the correct font.
    But in any case, that wasn't my only issue with the tables.  My understanding of importing Excel spreadsheets is that applied table and cell styles will be maintained when the linked file is updated, but local formatting/overrides will be wiped out, which is why I was trying to get the styles working in the first place.  However, after testing, I found that even when I didn't use local formatting/overrides, updating the linked file still broke my InDesign layout.
    In my test, the only thing I did to the imported (unformatted) table was to apply the table/cell styles and adjust column width (which is unavoidable as far as I know - didn't see anywhere I could set column width as part of a style).  But even then an update to the linked file removed all the styles and column widths I had set (and was also highly annoying as it gave me a separate error message about the formatting loss for each and every instance of the spreadsheet).
    Could be a fluke, or could be I'm missing something, but for whatever reason, I just couldn't get it to work

  • Table cell flashing

    Hi,
    Before I start to hack away a solution that might not be fx-like, I'd like to get your expert opinion about implementing cell flashing for a table view.
    I have done this several times in Swing (using a timer, a customer renderer, switching the bg/fg colors 3 times, and firing up an even table cell update), but how do implement this feature in JavaFX?
    * The table cell renderer (override def call (...)) could be used
    * The bg/fg color switch can be done using different css styles
    * what would be the best way to implement the timer and ask the view to "repaint" a specific cell?
    Thx v much

    Below is a bit of code that does something like what you want (the port to groovy should be easy). It may need some testing/tweaking for a real scenario and I'm not sure just how many animated cells you could have going at a time before performance becomes an issue (maybe someone from the JFX team could comment on this?).
    Also, regarding the use of styles for animating the change, you should be aware of this: Removing CSS style classes?
    Basically you need to make sure your 'default' style has values set for everything your 'highlight' style messes with, otherwise the highlight won't get turned off.
    import javafx.animation.FadeTransition;
    import javafx.animation.Timeline;
    import javafx.application.Application;
    import javafx.beans.value.ChangeListener;
    import javafx.beans.value.ObservableValue;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.control.TableCell;
    import javafx.scene.control.TableColumn;
    import javafx.scene.control.TableView;
    import javafx.scene.control.cell.PropertyValueFactory;
    import javafx.scene.layout.BorderPane;
    import javafx.stage.Stage;
    import javafx.util.Callback;
    import javafx.util.Duration;
    public class TestApp extends Application
        public static void main(String[] args)
            Application.launch(args);
        @Override
        public void start(Stage stage) throws Exception
            BorderPane root = new BorderPane();
            TableView<Person> table = new TableView<Person>();
            table.getItems().addAll(
                    new Person("Cathy", "Freeman"),
                    new Person("Albert", "Namatjira"),
                    new Person("Noel", "Pearson"),
                    new Person("Oodgeroo", "Nooncal")
            TableColumn<Person, String> firstNameCol = new TableColumn<Person, String>("First Name");
            firstNameCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("firstName")
            table.getColumns().add(firstNameCol);
            TableColumn<Person, String> lastNameCol = new TableColumn<Person, String>("Last Name");
            lastNameCol.setCellValueFactory(
                    new PropertyValueFactory<Person, String>("lastName")
            lastNameCol.setCellFactory(new Callback<TableColumn<Person, String>, TableCell<Person, String>>()
                public TableCell<Person, String> call(TableColumn<Person, String> column)
                    final FlashingLabel label = new FlashingLabel();
                    label.setStyle("-fx-background-color: #ffaaaa");
                    TableCell<Person, String> cell = new TableCell<Person, String>()
                        protected void updateItem(String value, boolean empty)
                            super.updateItem(value, empty);
                            label.setText(value);
                            label.setVisible(!empty);
                    cell.setGraphic(label);
                    return cell;
            table.getColumns().add(lastNameCol);
            root.setCenter(table);
            Scene scene = new Scene(root, 800, 600);
            scene.getStylesheets().add("styles.css");
            stage.setScene(scene);
            stage.show();
        public class FlashingLabel extends Label
            private FadeTransition animation;
            public FlashingLabel()
                animation = new FadeTransition(Duration.millis(1000), this);
                animation.setFromValue(1.0);
                animation.setToValue(0);
                animation.setCycleCount(Timeline.INDEFINITE);
                animation.setAutoReverse(true);
                animation.play();
                visibleProperty().addListener(new ChangeListener<Boolean>()
                    public void changed(ObservableValue<? extends Boolean> source, Boolean oldValue, Boolean newValue)
                        if (newValue)
                            animation.playFromStart();
                        else
                            animation.stop();
        public class Person
            private String firstName;
            private String lastName;
            private Person(String firstName, String lastName)
                this.firstName = firstName;
                this.lastName = lastName;
            public String getFirstName()
                return firstName;
            public String getLastName()
                return lastName;
    }

  • Update jtable cell via numeric keypad

    Hi,
    I have a problem, trying to figure out how to input numbers in a jtextfield in a jtable cell, from a group of jbuttons (rendered as a numeric keypad). I can get the cell to focus, but when I click on one of the jbuttons in the keypad, the cell loses focus and nothing is printed. I can update the cell by directly typing from the keyboard; that works fine. But I'm lost when trying to do it from the touch-screen keypad. Can anyone point me in the right direction. I assume I need to attach additional listeners somewhere.
    Thanks in-advance.
    Lee

    I can get the cell to focus, Then the code for you button would need to be something like:
    String text = (String)table.getValueAt(...);
    String updated = text + button.getText();
    table.setValueAt(updated, ...);

Maybe you are looking for

  • View Link w/ Transient View Objects

    I'm trying to create 2 view objects that contain only transient attributes and create a view link between them. I have a key defined in the parent and 2 keys in the child. When I create the view link I'm unable to generate the accessor in the source

  • Export, Import and Table declaration in custom function module

    I am creating a custom function module. Parameters needed are export internal table and one data field from the internal table. What do i need to fill for 'associated type' for these export parameters since size of the internal table and type for the

  • Which seeded page is called when session timeout happens

    Hi All, Our requirement is to route to custom page when session timeout happens. We are working on R11. Any suggestions which seeded JSP/JAVA file is called when we try to access application after session time out ? How to route to custom page when s

  • When is the next update expected for Engage?

    Post Author: DHAG CA Forum: Xcelsius and Live Office Based on my own experience and from reading this board, there clearly seems to be a need for a service pack/bug fix release. Can someone kindly let us know when (roughly) we might expect such a rel

  • Looking up values from Map/HashMap  when Objects are used as keys

    I'm trying to understand why Map/HashMap don't test for equals() when looking up a key ( which is an Object that overrides equals() and hashCode()) in the Map. I've written this code, based on some code from the SCJP book, but it is not exactly the s