How to listen for cell selection changes within a JTable

Problem: my table has 8 columns, with 4 of them containing very large text (up to 1000 chars). Solution is to set the initial size these columns so that the 1st 20 chars are visible, and if one of these columns gains focus/selection via mouse-clicking/tabbing/arrow keys, the entire text is shown in a JTextArea below the table.
I added a ListSelectionListener to the table, but this only informs me when the row selection has changed.
I added a FocusListener to the table, but this only informs me when the table gains/loses focus, not when it's been changed within.
I added a TableColumnModelListener to the TableColumnModel, but this only informs me when the column selection has changed.
I didn't bother with MouseListener as this won't handle change of selection via tabbing.
The LSL got me half way there, and the TCML got me the other half. Any ideas on how to combine?
Or is there something obvious that I'm missing?

Walter Laan wrote:
Use both and call the same method which updates the text area based on the current selected (or focused == lead selection index) cell.Yeah - that's what I figured. I just didn't know if there was a magic bullet (i.e., a single listener) out there that I was missing.
While you are at it, also add a table model listener which calls the same method if the selected cell is updated.I'll keep that in mind, but it's not necessary in this particular case. The table cells in question will be uneditable. The text area will have supporting Edit/Save/Cancel buttons.

Similar Messages

  • How to find for which select statement performance is more

    hi gurus
    can anyone suggest me
    if we have 2 select statements than
    how to find for which select statement performance is more
    thanks&regards
    kals.

    hi check this..
    1 .the select statement in which the primary and secondary keys are used will gives the good performance .
    2.if the select statement had select up to  i row is good than the select single..
    go to st05 and check the performance..
    regards,
    venkat

  • How to veto a JComboBox selection change in ItemListener

    I have a JComboBox whose current value is tied to some data cached in my application. I want to be able to examine the selection in an ItemListener attached to the JComboBox, and if the value is different than what I have cached, I want to ask the user if they really want to change because the change will render some other data as no longer valid. If the user wants to abandon the change, then I want to "abandon" or "veto" the selection change and reset it to the old value.
    For instance, if the combo box has values "Foo" and "Bar" in it, and "Foo" is the cached selection, then the user goes and changes the selection to "Bar", I want to prompt them with something like "You have changed the value to Bar. Doing so will render XXX no longer valid. Do you want to continue?" -- if they cancel the change, then leave the selection as "Foo".
    What is the best way to do this within ItemListener's itemStateChanged? Are there better ways to do this besides what I've outlined? I didn't see anything in "Core JFC" book or the JDK documentation that discussed this sort of thing.
    Thanks in advance,
    Eric

    Hi,
    It is a design problem and not realy a language problem... The way I create vetoing design it that a keep the previous selection of the JComboBox... upon action I look if the application can do the new computation...if not...ask the user... if true| run calculations if not set the JComboBox to the previous selection...
    JRG

  • How to restrict the cell selection in JTable based on cell contents...

    Hi all,
    I have some problem related to table cell selection.
    I have a table that represets the calendar of some month and year.
    I have the restriction that at one time only one cell could be selected.
    Now i want the cell seletion like this,
    I want only those dates to be selected if that date is after 'today'.
    that is I want to restrict the selection of previous dates.
    how can i do this.
    I have overridden the table methods like this, still no use.
    table = new JTable(model) {
    setOpaque(false);
    setSurrendersFocusOnKeystroke(false);
    setRowHeight(20);
    JTableHeader header = getTableHeader();
    header.setOpaque(false);
    getTableHeader().setReorderingAllowed(false);
    setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    getTableHeader().setResizingAllowed(false);
    setCellSelectionEnabled(true);
    setFocusable(true);
    setBackground(new Color(247, 251, 255));
    setFont(newFont);
    public boolean isCellEditable(int row, int col) {
    return false;
    public boolean isCellSelected(int row, int col) {
    int r = getSelectedRow();
    int c = getSelectedColumn();
    String val = (String)getValueAt(r,c);
    Calendar cal = Calendar.getInstance();
    cal.set(currentYear+1900, month,Integer.parseInt(val));
    Date d = cal.getTime();
    Date currentDate = new Date();
    if (d.before(currentDate)) {
         return false;
    } else {
         return true;
    Someone please help...
    -Soni

    Try overriding the changeSelection(....) method of JTable.
    public void changeSelection(int row, int column, boolean toggle, boolean extend)
         if (d.after(currentDate)
              super.changeSelection(row, column, toggle, extend);
    }

  • How to determine which object was change within a snapshot

    Dear All,
    We are using OWB 9.2.0.4 with Oracle database 9.2.0.7.
    I have taken a full snapshot of an OWB project that includes several modules(cascade). I one of the modules I have created a new table, and added it to an existing mapping in that module.
    When I compare the module with the snapshot I took before, I get that all modules have changed and all thier mappings. When drilling down I can see that for the objects I did not change only an internal property was changed.
    How can I determine what has changed? Do I have to drill down on all objects?
    Regards
    Galit

    Hi,
    We are using 10.2.0.4.36 for the client and 10.2.0.4.0 enterprise edition for the database.(info from the session props window)
    rgrds Mike

  • How to 'veto' a jList selection change

    Hi All,
    I have a JList which I'm using as a record selector - so whenever my user selects an item on the list, the associated record is loaded up into the other controls on this form for editing. If the user edits any of the data items, I want to ask whether to save changes or not if another item is selected from the JList. So, I've added code in my 'selection changed' function to check for changes and show a 'yes/no/cancel' JOptionPane. The code for my 'yes' and 'no' respones work fine - either save the changes or not, then show the next record. My problem is handling if a user clicks cancel...
    If the user selects 'Cancel', I dont want any of my "show new record" code to execute (this is easy, I can just 'return' out of the function) but also I don't want the JList selection to change. I've tried calling setSelectedIndex() back to the originally selected item, but this in turn triggers my 'selection changed' function to be called again, which causes the user to be asked twice whether they want to save changes!
    So, what I'm after is a kind of beforeSelectionChanged event, which allows the possibility of denying the selection change - but it doesn't look like this exists! I vaguely remember another language (possibly C++/MFC) having this - the user's action could be ignored depending on the return value of the function. Can anyone offer a way of achieving this in Java?
    (It's been a while since I last touched Java, and I'm a complete n00b with Swing. Using NetBeans as my IDE.)
    Thanks in advance for any suggestions!
    Andy

    The way I do it, is to implement a VetoableSelectionModel similar to a bean with a vetoable property: on selection change it queries registered VetoableChangeListeners if they don't object and backs out if one of them barks.
    HTH
    Jeanette

  • How to listen for key press when air app does not have focus

    Hi,
    I am developing a application in air and part of the functionality I need is the ability for the app to listen for when a specific key is pressed, even when the air app does not have focus.
    Is there support for this for windows or mac? If not, how might this be accomplished? ANE?    

    Ok Mr. Smartass...Ok
    I'm building a browser that is always open, and when
    a user presses Ctrl+F1 (notice, just those two keys,
    I don't care what else they press...) the browser
    will open up. That way, you don't have to wait for it
    to load all the time.You have two ideas here. One is having a universal key map that always gets ctrl-f1 sent to your app. The other is a program that is constantly running so that you don't have to wait for it to open up. The former is not possible (and this is a good thing) As warneria and I have been saying, it is bad design for an app to try to force an OS to implement this kind of feature.
    If you're not going to help please don't post at all;
    it's a waste of time for both you, me, and anyone
    else who may need help on the same subject. Why wouldBelieve it or not, I am helping you.
    See
    http://www.google.com/search?hl=en&lr=&q=programming+code+side+effects
    and
    http://www.faqs.org/docs/artu/ch04s02.html
    "Doug McIlroy's advice to �Do one thing well� is usually interpreted as being about simplicity. But it's also, implicitly and at least as importantly, about orthogonality."
    anyone in their right mind who's trying to steal
    people's passwords come out and say, "I'm not trying
    to steal people's passwords!"wait, your question is why would someone trying to steal passwords say I'm not trying to steal passwords? I think duplicitous people in their right minds might try to trick you that way.
    Beyond that, even if you're not a malicious hacker - and I am sure you are not - if someone posts a solution to your problem, malicious coders then will have learned how to do it. If you think you're programming or using these forums in a bubble, you are not.

  • How to go for some customize change in SAP Std.

    Hi all,
    I have to hide some in F-47 and other operation in some fields.
    My question is how to go for enhancing a SAP std. and how to identify the exits in which the code is to be return and how to activate that exit. Pls help me with the steps.
    Thanks in advance,
    Vivek

    To know what are the exits present in that t-code,
    steps are:
    1) go to se-93.: write the t-code of that transaction where u want to see the exits.: ex: va01.
    display : copy the package name.
    2) cmod : create the project name.
    3) under enhancements press f4 key, now paste the package name..n enter.
    4) it will give all the existing user-exits for that va01.
    try 4 this..

  • How to search for a particular element within a XML variable using studio?

    All,
    I am using studio 7.0 to develop a webbased application. In this, i need to access
    an oracle db using a WLAI Application View from my Workflow. I get some data back
    from Oracle as an XML variable and then apply an XPath statement to access the
    individual columns returned.
    My problem arises when there are no records in the db matching my criteria and
    an empty XML variable is returned to me from the app view. In these cases my
    XPath statement fails in studio causing an improper exit.
    Does anybody know how to check for content in a XML varaible using studio? So
    that if there is content i can proceed with XPath and if there is no content,
    then i will take a different route.
    Thanks in advance
    Regards
    Sri

    If I remember correctly, the adapter will return an XML document that contains
    XML elements for each row. You can just simply check the count of these elements
    with an XPath statement: ie. count(response/row)
    "Sri " <[email protected]> wrote:
    >
    All,
    I am using studio 7.0 to develop a webbased application. In this, i need
    to access
    an oracle db using a WLAI Application View from my Workflow. I get some
    data back
    from Oracle as an XML variable and then apply an XPath statement to access
    the
    individual columns returned.
    My problem arises when there are no records in the db matching my criteria
    and
    an empty XML variable is returned to me from the app view. In these
    cases my
    XPath statement fails in studio causing an improper exit.
    Does anybody know how to check for content in a XML varaible using studio?
    So
    that if there is content i can proceed with XPath and if there is no
    content,
    then i will take a different route.
    Thanks in advance
    Regards
    Sri

  • How to do Multi Cell Selection in JTable

    Dear Friends,
    Any body know Multi cell selection in jtable......
    Thanks

    Try overriding the changeSelection(....) method of JTable.
    public void changeSelection(int row, int column, boolean toggle, boolean extend)
         if (d.after(currentDate)
              super.changeSelection(row, column, toggle, extend);
    }

  • How to listen for inputs without a component? For creating bots

    I mean, for example, I want to write a a program that listens for keys f12 to (for example) skip the track in a media player and f11 to skip back. Thinks like the like :P. But I want to do this without any component, becasue the program won't have the focus at all.
    If it is needed to create a dll just tell as much as you pacience affords.

    I mean, for example, I want to write a a program that
    listens for keys f12 to (for example) skip the track
    in a media player and f11 to skip back. Thinks like
    the like :P. But I want to do this without any
    component, becasue the program won't have the focus
    at all. >Translation : I need a system keylogger.
    You can't do this in Java. And it will be OS specific.

  • How to search for the selected text with a non-default search engine?

    Hi,
    Before the recent update of the search bar, you could select your "current" search engine, and a search for the selected text (right-click on selection) would use that engine.
    Now, it seems that you can only search for the selected text using the default engine. If that's correct, this is a major step backwards for me. For instance, I can't have Google as my default search engine, and search for a selected text on eBay!
    Or am I missing something?
    Thanks!
    R.

    I find this extension very useful for items selected on web pages. It offers all your search engines with select>right click.
    https://addons.mozilla.org/en-US/firefox/addon/context-search/?src=search

  • Reacting on selection-changes in a JTable...

    Hello,
    I created an AbstractTableModel which is the basic for my JTable. Now I want to react on changes of the selection in the table. So I implemented a ListSelectionListener and overwrote the valueChanged()-method. But there is no reaction when the selection changes...is there a special trick with this method, or what else could be the reason for my problem ?
    Thanx,
    Findus

    Did you register your listener?
    yourTable().getSelectionModel().addListSelectionListener(yourListener);

  • How to listen for a change in a JTextArea?

    well ..... the subject says it all :)

    The JavaDoc says it all :)
    The java.awt.TextArea could be monitored for changes by adding a TextListener for TextEvents. In the JTextComponent based components, changes are broadcasted from the model via a DocumentEvent to DocumentListeners. The DocumentEvent gives the location of the change and the kind of change if desired. The code fragment might look something like:
    DocumentListener myListener = ??;
    JTextArea myArea = ??;
    myArea.getDocument().addDocumentListener(myListener);http://java.sun.com/j2se/1.4/docs/api/javax/swing/JTextArea.html
    Col

  • How to prevent action (lead selection change) with popup (confirmation)?

    Hello all,
    I have an application where I want the user to confirm when he selects a new line in a table. When the user selects a new line in the table an other used component reloads its data based on the new line selected. If the user has not pressed the save button before selecting a new line, any changes in the used component will be lost.
    Currently I use onLeadSelect action on the table to call the load_data method(id=xxx) on the used component in order to display data relevant for id=xxx based the new line.
    I can open a popup to confirm from the onLeadSelect-action or the WDDoBeforeAction, but the action still happens; it doesn't wait for the user to respond. And then any changes are lost...
    I may have to store the parameters sent to the onLeadSelect method in context and continue when the button action from the pop-up returns via subscribed method, but I think this is an unelegant way of doing this.
    There must be a better way...? Any ideas?
    Regards,
    Christian Frier

    on the lead select event handler you can show the popup and no other logic. Move your logic to the ok and cancel button handlers of the pop up.

Maybe you are looking for