How to listener a table cell

I have this table cell editable and I want to listen when value changes (to update the database data) but I am not being able to do that, any help?
I also would like to activate the new cell value with ENTER key, the way it is now I have to get ou of the cell clicking outside somewhere or using TAB key to move.
I am using these tow classes to Editor and Renderer (for numbers):
import java.awt.*;
import java.text.*;
import javax.swing.table.*;
import javax.swing.*;
public class DecimalRenderer extends DefaultTableCellRenderer {
    DecimalFormat  formatter;
    public DecimalRenderer(String pattern) {
        this(new DecimalFormat(pattern));
    public DecimalRenderer(DecimalFormat formatter) {
        this.formatter = formatter;
        setHorizontalAlignment(JLabel.RIGHT);
    public void setValue(Object value) {
        setText((value == null) ? "" : formatter.format(((Double)value).doubleValue()));
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        cell.setBackground( Color.white );
        cell.setForeground( Color.black );
        return cell;
import java.awt.*;
import javax.swing.table.*;
import javax.swing.*;
public class NumberCellEditor extends AbstractCellEditor implements TableCellEditor {
    //protected JTextField textField;
    protected JFormattedTextField textField;
    private JTable tableUsed;
    protected Object oldValue;
    public NumberCellEditor() {
        textField = new JFormattedTextField();
        textField.setEditable(true);
        textField.setHorizontalAlignment(SwingConstants.RIGHT);
        textField.setFont(new java.awt.Font("Tahoma", 1, 12));
        textField.setBackground(Color.white);
        textField.setForeground(Color.red);
    public NumberCellEditor(int decimal) {
        textField = new JFormattedTextField();
        textField.setEditable(true);
        textField.setHorizontalAlignment(SwingConstants.RIGHT);
        textField.setBackground(Color.white);
        textField.setForeground(Color.red);
        textField.setFormatterFactory(Lib.setFormatDouble(decimal));
        public NumberCellEditor(boolean currency, int decimal) {
        textField = new JFormattedTextField();
        textField.setEditable(true);
        textField.setHorizontalAlignment(SwingConstants.RIGHT);
        textField.setBackground(Color.white);
        textField.setForeground(Color.red);
        textField.setFormatterFactory(Lib.setCurrencyFormat(decimal));
    private void setConfig(){
        textField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                if(tableUsed.isEditing()){
                    tableUsed.getCellEditor().stopCellEditing();
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
        //textField.setText(value.toString());
        textField.setValue(value);
        oldValue = value;
        this.tableUsed = table;
        String className = value.getClass().getName();
        System.out.println("Type: "+className);
        return textField;
    /** Returns the value contained in the editor */
    public Object getCellEditorValue() {
        String name = oldValue.getClass().getName();
        Object returnValue=null;
        try {
            if (name.equals("java.lang.Integer"))
                returnValue = new java.lang.Integer(textField.getText());
            else if (name.equals("java.lang.Double"))
                returnValue = (Double)textField.getValue(); //new java.lang.Double(textField.getText());
            else if (name.equals("java.lang.Float"))
                returnValue = new java.lang.Float(textField.getText());
            else if (name.equals("java.lang.Long"))
                returnValue = new java.lang.Long(textField.getText());
            else if (name.equals("java.lang.Short"))
                returnValue = new java.lang.Short(textField.getText());
            else if (name.equals("java.lang.Byte"))
                returnValue = new java.lang.Byte(textField.getText());
            else if (name.equals("java.math.BigDecimal"))
                returnValue = new java.math.BigDecimal(textField.getText());
            else if (name.equals("java.math.BigInteger"))
                returnValue = new java.math.BigInteger(textField.getText());
        } catch (NumberFormatException e) {}
        return returnValue;
}My code to that column/cell:
TableColumn columnValueService = tabelaListaQuantidade.getColumn(colunas[4]);
columnValueService.setPreferredWidth(150);
columnValueService.setCellRenderer(new DecimalRenderer("###,###,##0.00"));
columnValueService.setCellEditor(new NumberCellEditor(true, 2));I would appreciate any help.
Thanks

I want to listen when value changes Use a TableModelListener
I also would like to activate the new cell value with ENTER keyThis is the default behaviour with the default editors. I suggest you extend the default editor instead of extending the abstract editor

Similar Messages

  • Add action listener to table cell

    The topic of my previous thread was:
    How can I get characters, which user inputs into table cell?
    I've added lisateners to table:
    table.addKeyListener(new java.awt.event.KeyAdapter() {
                public void keyPressed(java.awt.event.KeyEvent evt){
                    System.out.println("keyPressed");
                public void keyReleased(java.awt.event.KeyEvent evt){
                    System.out.println("keyReleased");
                public void keyTyped(java.awt.event.KeyEvent evt) {
                    System.out.println("keyTyped");
            });But it's not exactly what I need.
    I need to do the same, but with table cell.
    I want to see user input char by char and set color font for user input string.
    How can I add action listener to tble cell?

    This is my newly created JTextField which I will use as CellEditor for My JTable
    JTextField textField = new JTextField(); //creating Component
            textField.addKeyListener(new java.awt.event.KeyAdapter(){ //adding KeyListener
                public void keyReleased(java.awt.event.KeyEvent evt){
                    System.out.println("keyReleased" + ((JTextField)evt.getSource()).getText() + "column = " +table.getSelectedColumn());//test functionality
                    if ( isColumnHasSameValue(table.getSelectedRow(),table.getSelectedColumn(), ((JTextField)evt.getSource()).getText() ) ){//test column for equal values
                        ((JTextField)evt.getSource()).setForeground(Color.RED); //if there is equal value set Color.RED for JTextField text
                    else{ //else set Color.BLACK
                        ((JTextField)evt.getSource()).setForeground(Color.BLACK);
            table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(textField)); //set custom CellEditor
    private boolean isColumnHasSameValue(int row, int column, String testVal){
            testVal = testVal.trim().toLowerCase(); //put away UpperCase and empty spaces
            for(int i=0;i<model.getRowCount();i++){
               if(i == row){
                   continue;//skip selected row where user inputs text
               if(model.getValueAt(i,column).toString().trim().toLowerCase().startsWith(testVal)){
                    return true; //if test passed
            return false; //if there are no mathes
        }I have a question:
    It seems to me, I did not use optimal solution for JTable values testing.
    What can ty else?
    Maybe, It is better to use
    tableModel.getDataVector();And then use Pattern and Matcher ?
    Am I right?

  • How to enable a table cell dynamically?

    Hi
    I have a javafx TableView with editable and non-editable columns. I have set editable columns CellFactory to a custom EditableTextCell.This makes the whole column editable on load of the Scene.
    I have one more requirement for the same table. I have to make the table cell editable at runtime based on a flag in item mapped to tablerow. Only a single row cell should get editable not all the cells in column. How to do that? Please suggest.

    Perhaps something like this
    create or replace view v_myview
    as
    select id, name, 'table1' as tbl_nm from table1
    union all
    select id, name, 'table2' from table2
    union all
    select id, name, 'table3' from table3
    union all
    select id, name, 'table4' from table4
    select name
      from v_myview
    where id = 101
       and tbl_nm = :P101_TABLE_NAME;

  • How to create a table cell occupy more than one row using PDF.

    Hi,
    I want create a pdf report,which contains a table cell occupied more than one line.
    just like html language: <rowspan = 2>
    merge cells in one row is allowed,we can use merge cells command(like colspan in html).
    but how to mege cells in one column?

    Hi,
    I want create a pdf report,which contains a table cell occupied more than one line.
    just like html language: <rowspan = 2>
    merge cells in one row is allowed,we can use merge cells command(like colspan in html).
    but how to mege cells in one column?

  • How to link a table cell?

    Hi,
    What would be the best way to link this table cell? I want the entire cell to be linked rather than just the text inside it.
    <table width="160" border="0" align="right" cellpadding="5" cellspacing="0" class="backgroundbox-video">
                          <tr>
    <td width="167" align="left" valign="top"><p class="navheader-lg">Video Clip</p>
                                <p class="navheader-sm">Watch a short<br />
                                  testimonial video</p></td>
                          </tr>
    Thanks so much
    Laura

    Here is what I have in the style sheet...
    .vidA a {
        text-decoration: none;
        display:block;
        background-image: url(../images/videoclip-imageandcolor-tr.gif) no-repeat scroll right bottom;
        background-color:#B1D6D5;
        padding:10px;
    .vidA a:link, .vidA a:visited, .vidA a:hover{
        color:black;
    .vidA a:hover{
        background-color:#4AA3C9;
    .vidA p {
        margin:5px;
    .audioA a {
        text-decoration: none;
        display:block;
        background-image: url(../images/audioclip-imageandcolor-tr.gif) no-repeat scroll right bottom;
        background-color:#B1D6D5;
        padding:10px;
    .audioA a:link, .vidA a:visited, .vidA a:hover{
        color:black;
    .audioA a:hover{
        background-color:#4AA3C9;
    .audioA p {
        margin:5px;
    and here is what I have for those tables...
    <td align="right" valign="top" bgcolor="#FFFFFF"><table width="160" border="0" align="right" cellpadding="5" cellspacing="0" class="backgroundbox-video">
                          <tr>
                            <td class="vidA" width="167" height="100" align="left" valign="middle"><a href="http://www.12results.com/video1.html" onclick="MM_openBrWindow('http://www.12results.com/video1.html','','width=400,height=400');return false">
          <span class="navheader-lg">Video Clip</span><br />
          <span class="navheader-sm"><br />
          Watch a short<br />
          testimonial video</span></a></td>
                          </tr>
                        </table></td>
                      </tr>
                      <tr>
                        <td align="right" valign="top" bgcolor="#FFFFFF"><table width="160" border="0" align="right" cellpadding="5" cellspacing="0" class="backgroundbox-audio">
                          <tr>
                            <td class="audioA" width="167" height="100" align="left" valign="middle"><a href="http://www.12results.com/video1.html" onclick="MM_openBrWindow('http://www.12results.com/video1.html','','width=400,height=400');return false"> <span class="navheader-lg">Audio Clip</span><br />
                                  <span class="navheader-sm"><br />
                                  Listen to a 40 min<br />
    interview about SAW</span></a></td>
                          </tr>
                        </table></td>
    ---I completely removed the styles for those tables (was background-video, background-audio) because all it had was the background styling (which you said to remove) and can't see any other reason to have it there?
    So it's perfect except for the background images are not showing...so did I do something wrong in the fireworks/make transparent process do you think?
    Thanks...
    Laura

  • How to highlight the table cell color in respective colors as needed per the requirements??

    var aData = [
        {notificationNo: "10000000", description: "Maintenance for boiler", location: "G001-STG-UTLR-BLR", equipmentNo: "100000053", orderStatus: "ordered"},
        {notificationNo: "10000010", description: "Genreal Maintenance for boiler", location: "G001-STG-UTLR-BLR", equipmentNo: "100000053", orderStatus: "notordered"},
        {notificationNo: "10000011", description: "boiler Maintenance", location: "G001-STG-UTLR-BLR", equipmentNo: "100000053", orderStatus: "ordered"},
        {notificationNo: "10000012", description: "Pump breakdown", location: "G001-STG-UTLR-BLR", equipmentNo: "100000053", orderStatus: "ordered"},
        {notificationNo: "10000013", description: "External service boiler", location: "G001-STG-UTLR-BLR", equipmentNo: "100000053", orderStatus: "notordered"},
    jQuery.sap.require("sap.ui.model.json.JSONModel");
    var oEnterpriseAsset_NotificationConsole;
    sap.ui.model.json.JSONModel.extend("EAM_Notification_Console", {
        CreateNotificationConsole:function(){
            oEnterpriseAsset_NotificationConsole = this;
                var oTable = new sap.ui.table.Table({
                //title: "Table Example",
                visibleRowCount: 7,
                firstVisibleRow: 3,
                selectionMode: sap.ui.table.SelectionMode.Single,
            /*    toolbar: new sap.ui.commons.Toolbar({items: [
                    new sap.ui.commons.Button({text: "Button in the Toolbar", press: function() { alert("Button pressed!"); }})
                extension: [
                    new sap.ui.commons.Button({text: "Button in the Extension Area", press: function() { alert("Button pressed!"); }})
            }).addStyleClass("tableform");;
            oTable.addColumn(new sap.ui.table.Column({
            label: new sap.ui.commons.Label({text: "Notification"}),
            template: new sap.ui.commons.Link().bindProperty("text", "notificationNo").bindProperty("href", "href",
                    function(aValue)
            //    sortProperty: "notificationNo",
                //filterProperty: "notificationNo",
                width: "200px"
            oTable.addColumn(new sap.ui.table.Column({
                label: new sap.ui.commons.Label({text: "Description"}),
                template: new sap.ui.commons.Link().bindProperty("text", "description").bindProperty("href", "href"),
                //sortProperty: "notificationNo",
                //filterProperty: "notificationNo",
                //width: "200px"
            var oModel = new sap.ui.model.json.JSONModel();
            oModel.setData({modelData: aData});
            oTable.setModel(oModel);
            oTable.bindRows("/modelData");
        var idForTable= "DimTable"
            //alert("id of tbale " + idForTable);
            var htmlOutput = '<table id=' + idForTable + ' name="DimTab" style="border: 1px solid black;margin-left:15px;" cellpadding=6 cellspacing=0><tr style="background-color:#E5E5E5"><td><b>Dimension</b></td><td><b>Value</b></td></tr>';
            for(var i=0;i<aData.length;i++)
             alert(aData[i].notificationNo);
            htmlOutput += '<tr style="display:none;"><td style="border-right:1px solid #e5e5e5;">Contract No</td><td>'+ aData[i].notificationNo+'</td></tr>';
            htmlOutput += '<tr style="display:none;"><td  style="border-right:1px solid #e5e5e5;">Unit No</td><td>'+ aData[i].description+'</td></tr>';
            htmlOutput += '</table>';   
             var html2 = new sap.ui.core.HTML({
                 // static content
                 //content : "<div style='position:relative;background-color:white;'>Weather</div><script src='//www.gmodules.com/ig/ifr?url=http://www.google.com/ig/modules/builtin_weather.xml&synd=open&w=320&h=200&title=__MSG_weather_title__&lang=en&country=ALL&border=http%3A%2F%2Fwww.gmodules.com%2Fig%2Fimages%2F&output=js'></script>",
            content : htmlOutput,
                  //2 wrkng sydney content : '<div id="cont_Mzc0NjN8NXwxfDF8NHxlZGY1ZjV8M3xGRkZGRkZ8Y3wx"><div id="spa_Mzc0NjN8NXwxfDF8NHxlZGY1ZjV8M3xGRkZGRkZ8Y3wx"><a id="a_Mzc0NjN8NXwxfDF8NHxlZGY1ZjV8M3xGRkZGRkZ8Y3wx" href="http://www.weather-wherever.co.uk/australia/sydney_v37463/" target="_blank" style="color:#333;text-decoration:none;">Weather forecast</a> © weather</div><script type="text/javascript" src="http://widget.weather-wherever.co.uk/js/Mzc0NjN8NXwxfDF8NHxlZGY1ZjV8M3xGRkZGRkZ8Y3wx"></script></div>',
                  //content : '<div style="margin-left:-10px;margin-top:10px;width:100%;"><LINK rel="StyleSheet" href="http://weatherandtime.net/new_wid/w_5/style.css" type="text/css" media="screen"><div class="ww_5" id="ww_5_2119"><div class="l_b"></div><div class="c_b"><div class="day" id="d_0"><span class="den"></span><br><span class="date"></span><br><span class="temp"></span><div class="pict"></div><span class="press"></span><br><span class="hum"></span><br><span class="vet"></span><br></div><div class="day" id="d_1"><span class="den"></span><br><span class="date"></span><br><span class="temp"></span><div class="pict"></div><span class="press"></span><br><span class="hum"></span><br><span class="vet"></span><br></div><div class="day" id="d_2"><span class="den"></span><br><span class="date"></span><br><span class="temp"></span><div class="pict"></div><span class="press"></span><br><span class="hum"></span><br><span class="vet"></span><br></div><div class="cl"></div><div class="links"><a target="_blank" title="Pune Weather forecast" href="http://weatherandtime.net/en/Asia/India/Pune-weather.html">Pune Weather forecast</a><br><a style="font-size:12px !important;color:#12A0D7 !important;text-decoration:none !important;" href="http://weatherandtime.net/en/widgets-gallery.html" title="weather"></a></div></div><div class="r_b"></div></div><script type="text/javascript" src="http://weatherandtime.net/w_5.js?city=2119&lang=en&type=2&day=3"></script></div>',
              // initially behaves the same as Sample 1
                 preferDOM : false,
                 // use the afterRendering event for 2 purposes
        return     oTable;
    /* In the screen shot as u can see.. I have to highlight the table cell in green color and red color for ordered and unordered status(which is binded to a json data) respectively....anyone please help??

    Hi Abhi,
                   Check this link it may helpHow I made highlight of specific values in Table

  • JavaFX2.2 TableView:How to make a table cell be edited without mouse click?

    Hi,
    I've encounter a problem with editable table cells. I'm using the TableView in my project just as the Tutorial on Oracle (http://docs.oracle.com/javafx/2/ui_controls/table-view.htm).
    According to it, I use the setCellFactory method to reimplement the table cell as a text field with the help of the TextFieldTableCell class. However, I found the steps is a little complex to get to the point where the cell can be edited:
    1.Let the table cell be selected by using direction key.
    2.Press “Enter” to converts the cell to a text filed so that it is ready to be edited.
    3.Clicking in the text field allows the contents to be edited
    The problem is step 3, that you must use the mouse to click before you can input data in this table cell.
    So, is there a solution to avoid step 3? That is the text field allows the data inputting when you just press “Enter”(step 2).
    By the way, English is not my native language. Hope I have made myself clear.

    Hi,
    You need to pass the focus to the text field when the startEditing event occurs. In the class that extends TableCell you use for cellFactory:
    public void startEdit() {
    super.startEdit();
    createTextField();
    setText(null);
    setGraphic(textField);
    * put focus on the textfield so user can directly typed on it
    Runnable r = new Runnable() {
    @Override
    public void run() {
    getGraphic().requestFocus();
    Platform.runLater(r);
    }

  • How to apply a table cell style based on grep search?

    Anyone that know how to make a script that searches in an Indesign table for
    -> All cells where the text starts with "Banana"
    -> And apply cell style "Yellow" to these cells?
    I have been searching on forums for somedays and got this tip: https://github.com/seuzo/regex_cellstyle/blob/master/regex_cellstyle.jsx
    -> But that script is in japanese and also use dialogs.
    All help most appriciated!

    Hi Frankeman,
    Please try the below code, may it should be helpful:
    var myDoc = app.activeDocument
    app.findTextPreferences = app.changeTextPreferences = null
    app.findTextPreferences.findWhat = "Banana"
    var myFound = myDoc.findText()
    for(i=0; i<myFound.length; i++)
        if(myFound[i].parent.constructor.name == "Cell")
       myFound[i].parent.appliedCellStyle = "Yellow"
    Suppose the code is working fine for you, then please click correct answers.
    thanks
    Beginner_X

  • How to listen a JTable cell is changed?

    is it have any Listener can know the JTable cell cursor change to other?
    Thanks!

    JTable exposes a ListSelectionModel through getSelectionModel() that you can listen to for changes in the selected row. I think you need to get the TableColumnModel to detect changes in the selected column:
    table.getSelectionModel().addSelectionListener(selectionListener);
    table.getColumnModel().getSelectionModel().addSelectionListener(selectionListener);selectionListener should get notified if a change is made to the selected row or column.
    Hope this helps.

  • How do with change table cells from staticText1 to button1 in run time?

    I have two question:
    first: I think change table's cells from staticText to button in run time?
    how do?
    second: I think change table column's order in run time?how do?
    ex:
    =============change before===========
    name age
    wtu 22
    =============chnage after=============
    age name
    22 wtu
    thanks

    Try something like this:
    1. Drop a Table. By default it has three columns.
    2. Drop a button inside the third column. Set its id property to buttonInColumn3, and set its rendered property to false.
    3. Drop another button, this time outside the table. Set its id property to buttonOutsideTable.
    4. Double-click the buttonOutsideTable and make the method look as follows:
    public String buttonOutsideTable_action() {
    //switch the first two columns
    List cols = tableRowGroup1.getChildren();
    Object col = cols.remove(0);
    cols.add(1, col);
    //toggle between showing staticText3 and buttonInColumn3 (in the third column)
    staticText3.setRendered(!staticText3.isRendered());
    buttonInColumn3.setRendered(!buttonInColumn3.isRendered());
    return null;
    5. Run the application and click the button outside the table several times.

  • Grep: How to fill a table cell with certain color

    I have an excel sheet with 5000 rows that needs to be formatted in Indesign.
    1. Is there a way to get a certain color fill of the cell depending on text. Lets say if the text is "apple", the cell should fill with red (and text also color red to make it disappear).
    2. How do I make two different character styles to appear in the same cell (information is tab-separeted but sometimes I would like to have 2 "paragraphs" in one cell sometimes – with that I mean two tab-delimited cells from excel to appear in ONE cell in indesign).
    Thanks in advance
    Example of what I would like to accomplish:  http://tinypic.com/r/vo4och/6

    Yes but wouldn't that make the field contain a string?
    I tried something like that, and every field I edit becomes left-justified, and String (instead of int, float which is right-justified)
    Matthew

  • How to set ADF table cell value in managed bean

    Hi all,
    I have an ADF table on my page, let's assume with three columns with Input text box: col A, col B and col C where column C is hidden, when I click on Submit is possible to set in managed bean the value of column C for each rows?
    Thk in advance.
    L-

    Hi,
    you can create a button with an ActionListener. In the ActionListener you can iterate over the rows (using the iterator) and set the value on the attribute. If you need to save the changes you can call the commit operation binding.
    Linda

  • 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 to change Table Cell Field Type Dynamically?

    Hi All,
    I am fetching some news data from backend DB and displaying them in a WD Table. Now one News Item may or may not have a URL behind it. If I find the URL as null then I want to display the news as simple TextView otherwise as LinkToUrl. How can I change this input type dynamically for each row in the runtime?
    If I use LinkToUrl all the time then the items which has URL as null gets displayed as normal text, but they are of very faint color and I can not change the text design. Whether if I user TextView I can set some text design like Header2, Header 3 etc.
    Can anybody please help with some code block? My main requirement is how to change the table cell input type dynamically.
    Thanks in Advance.
    Shubhadip

    Hi Shubhadip,
    This is the sample code for creating and adding a table cell editor table dynamically.
    public static void wdDoModifyView
    (IPrivateDynamicTableCreationView wdThis, IPrivateDynamicTableCreationView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
    //@@begin wdDoModifyView
    /*** 1.Create Table **/
    IWDTable table =
    (IWDTable) view.createElement(IWDTable.class, "table1");
    table.setWidth("100%");
    table.setVisibleRowCount(data.length);
    /*** 2.Create nameColumn **/
    IWDTableColumn nameColumn =
    (IWDTableColumn) view.createElement(IWDTableColumn.class, "Name");
    IWDCaption colHeader =
    (IWDCaption) view.createElement(IWDCaption.class, "NameHeader");
    colHeader.setText("–¼‘O");
    nameColumn.setHeader(colHeader);
    IWDTextView nameViewer =
    (IWDTextView) view.createElement(IWDTextView.class, "NameViewer");
    nameViewer.bindText(nameAtt);
    IWDTableCellEditor editor = (IWDTableCellEditor) nameViewer;
    nameColumn.setTableCellEditor(editor);
    table.addColumn(nameColumn);
    IWDTableColumn nationalityColumn =
    (IWDTableColumn) view.createElement(
    IWDTableColumn.class,
    "Nationality");
    IWDTableCellEditor nationalityEditor =
    (IWDTableCellEditor) nationalityViewer;
    nationalityColumn.setTableCellEditor(nationalityEditor);
    table.addColumn(nationalityColumn);
    /** 3. Bind context to table **/
    table.bindDataSource(nodeInfo);
    //@@end
    Bala
    Kindly reward appropriate points.

  • Table Cell Editor which allows to input multiple lines of text...

    Hi there
    Does anyone know how to write a table cell editor which allows users to input multiple lines of text? please provide some sample if possible...
    Thanks
    Ken

    I'm assuming you also want the renderer to display multiple lines? if so, make a class that extends JTextArea and that implements the TableCellEditor and TableCellRenderer interfaces, then set instances of this as the editor and renderer for the TableColumn in question. The implementation of most of the methods in these interfaces is trivial, often just this.setBackground() based on the table.getSelectionBackground() or table.getBackground(), a this.setText() based on the value passed in, then just a 'return this'.
    You might want to make an abstract class which implements these interfaces for you, and which delegates to a simple abstract method that you override to return the renderer/editor component.
    Note that you must use two instances of the class you make, one for the renderer and one for the editor, since it must be able to be able to render the remainder of the table's cells without interfering with the JTextArea performing the editing. (alternatively you could make two classes that extend JTextArea, each just implementing one of the interfaces, but this is more effort I think.) Also note that you must increase the table's row height to get more than one row visible.

Maybe you are looking for

  • Custom D2k form not displayed correctly in Oracle Apps 12.1.1

    Hi, I have created a custom form for Oracle Apps 12.1.1 using Oracle Forms 10g. This form was registered on DEV instance and it was working fine there. Recently the DEV instance is refreshed by cloning CRP2 instance. I used FNDLOAD to download the se

  • Read from a internal table whose name is decided in runtime

    Dear ABAPers I've an internal table's name in a variable, the name is populated in runtime (user_command->ls_selfield-tabname). Now that using the name (in the variable) i need to read a row from that particular internal table (which is populated int

  • How to use the Zoom for Pocket PC 2003?

    I try to use the LabVIEW7.1 PDA module zoom feature in my Pocket PC 2003. But I can not make it works right. For example, if I try to zoom to rectangle, the graph does not draw in the selected rectangle. I attached my code. Attachments: sin.vi ‏48 KB

  • G/L account changes

    Hi, How can I see the G/L account changes which have been made in transactions FS00/FSS0? If I don't want a recalculation in foreign currency when posting to an account, do I need to flag the "Only balances in locl currency" box? Are there any other

  • How to know when DND in progress?

    How do I know when a DND is in progress can't seem to find any where to call isDragInprogress() or something similar. My problem is that my JPanel flickers when it is dragged over because of the constant call to validate() so I want to disable the va