JList Selection Listener

How can i add a listener to a JList so that it runs a method when the selection has changed? I have already looked at the tutorial but it seems to be over complicated for what i need.
I have tried:
addFinanceList.addListSelectionListener(new ListSelectionListener()
public void valueChanged(ListSelectionEvent event)
CP.getFinance().loadFinance((String)addFinanceList.getSelectedValue());
updateDisplay();
But this never executes.
Can anyone help?

Sure it never executes? If you select items in the
list, what you've written looks correct. I'd shove a
println or log message in the valueChanged method to
see what's happening.Tried that...still nothing happens!

Similar Messages

  • JList selection is listened twice

    Hi
    How to make JList selection listener to catch selection events for only one mouse click (mouse pressed or mouse released)

    Hi,
    you are right!
    first time e.getValueIsAdjusting() is true second time
    it is false. It does not corrspond to mousePressed or mouseReleased. I think the first is an item loosing selection and the second is another item getting selection (just a guess).
    Phil

  • JList Selection Event

    Hi, here is one problem i am facing.
    i have a JList and i am using Selection Listener for that. Now selection listener has only one even in it valueChanged. which is only fired when some value is changed in the JList, i.e., if we select the same value twice consecutively, this event is fired only once only when that value is selscted for the first time. but i want this even to be fired every time i select a value (even twice or thrice consecutively). can u plz help me or tell me any other event?
    -Ashish

    problem is I cannot recieve which chat room is selected (let's say I don't know how to get it :) )Sorry I didn't get the humor :-( So let's try a dry answer:
    Try "jlist.getSelectedValue()" and cast it to the common supertype of all objects stuffed in the JList's model (I assume they are String or ChatRoom objects).
    and also selected index is appended twice when I click on any of them ? Can it be done by double click ?You receive two events (deselection of current item - selection of new item). You can distinguish them with event.getValueIsAdjusting().
    Brgds.

  • Issue with Selection Listener when the table has only one row

    Hi All ,
    I have developed a table in which I am using Selection Listener to perform some task when any row is selected.
    It is working fine when I have more than 1 row in the table, but when I have only one row in the table , the selection listener do not call the corresponding method in bean.
    I understand that selection event will be raised only when the row is changed, but in the use case when only one row is there, what should be done to make the selection listener work ?
    In the selection listener I have written code to make the selected row as current row , and perform the required task.
    Please suggest a way out for this situation.
    Thanks in advance.

    Hi,
    try removing this attr from table
    selectedRowKeys="#{bindings.xxx_VO1.collectionModel.selectedRow}"

  • Custom Selection Listener not getting fired

    I am using JDeveloper 11.1.1.4 and have been trying to follow the advice given in the ADF Code Corner example 68. The only difference in my application/project, is that I am trying to develop the master table on a page fragment with a task flow attached for the JSFF containing the detail table. My master table on the primary JSFF has a custom selection listener on it. When testing the deployed package--putting the primary task flow on a JSPX page, the tables are showing, but when I select a different row on the master table, the new row is highlighted but nothing happens to execute the custom listener. I am sure of this because I've added a System.out.println as the very first line in it and it doesn't put the message out. I am getting no errors on the weblogic logs. I looked on the client side's html output and can't see anything that would trigger that a change occurred to send back to the server. Any ideas (outside of upgrading to another version of Jdeveloper) would be greatly appreciated. I am not sure if providing any of my code would be of any help in this issue.

    Thanks to all who responded. I have multiple rows showing in my master table and when I select a different row, I get no event that executes my method. I tried adding the "binding.itterator." to the EL for the SelectionListener and that didn't work either. Besides both the examples in the ADF Code Corner 23 and 68 show it just as "class.method" as I have it. A small snippet from my table is below:
              <af:table value="#{bindings.HOT_trans_sumVO1.collectionModel}"
                        var="row" rows="#{bindings.HOT_trans_sumVO1.rangeSize}"
                        emptyText="#{bindings.HOT_trans_sumVO1.viewable ? 'No data to display.' : 'Access Denied.'}"
                        fetchSize="#{bindings.HOT_trans_sumVO1.rangeSize}"
                        rowBandingInterval="0"
                        selectedRowKeys="#{bindings.HOT_trans_sumVO1.collectionModel.selectedRow}"
                        *selectionListener="#{HotTransSummBean.onTxnSummTblRowSelect}"*                   
                        rowSelection="single" id="txnsummtbl"
                        columnStretching="last" width="100%" autoHeightRows="5"
                        contentDelivery="whenAvailable" immediate="true"
                        clientComponent="true" first="0">Also note that I have this backing bean defined on the task flow as a requestScope as it is in the example 68--example 23 does not state a scope level. Again, my method starts out with an output statement that never gets executed:
        public void onTxnSummTblRowSelect(SelectionEvent selectionEvent) {
          System.out.println("Entered onTxnSummTblRowSelect method.");

  • Creating a generic selection listener for af:table

    Hi,
    I'm using JDeveloper 11.1.1.5.0, and I have a simple requirement to set up a custom selection listener for an af:table component.
    So far, I was doing this by using a custom function to invoke the EL to perform the makeCurrent operation. However, I came across Frank Nimphius' PDF on how to build a generic selection listener, and this seemed like a better way to go about it. The problem is, the CollectionModel class used in the sample code is now deprecated. Is anyone aware of the currently supported way to implement a generic selection listener?
    Thanks,
    Gill

    this snap shot of the code i write it to get the current employee id whcich is selected
        public void select(SelectionEvent selectionEvent) {
            // Add event code here...
             RichTable  _table = (RichTable)selectionEvent.getSource();
             CollectionModel _tableModel = (CollectionModel)((RichTable)selectionEvent.getSource()).getValue();
            JUCtrlHierBinding _adfTableBinding = (JUCtrlHierBinding)_tableModel.getWrappedData();
            DCIteratorBinding _tableIteratorBinding = _adfTableBinding.getDCIteratorBinding();
            //Acess the ADF iterator binding that is used with ADF table binding
            Object _selectedRowData = _table.getSelectedRowData();
            JUCtrlHierNodeBinding _nodeBinding =
                (JUCtrlHierNodeBinding)_selectedRowData; //get the row key from the node binding and set it //as the current row in the iterator
              Key _rwKey = _nodeBinding.getRowKey();
              _tableIteratorBinding.setCurrentRowWithKey( _rwKey.toStringFormat(true));
            DCIteratorBinding it = _adfTableBinding.getDCIteratorBinding();
           System.out.println( it.getCurrentRow().getAttribute("EmployeeId"));
        }this code i written 11.1.2

  • Can't get child node in tree selection listener

    I am making a fusion web application using JDeveloper 11G (11.1.1.2.0).
    I have created two view objects linked together. Let's call them VoDepartments and VoEmployees, linked on DepartmentId.
    I hava made a tree with a af:switcher
    <af:switcher id="s1" facetName="#{node.hierType.structureDefName}">
    <f:facet name="view.VoDepartments">
      <af:outputText value="#{node}" id="ot1"/>
    </f:facet>
    <f:facet name="view.VoEmployees">
      <af:outputText value="#{node}" id="ot2"/>
    </f:facet>
    </af:switcher>I made a selection listener based on a guide by Frank Nimphius
    RichTree tree1 = (RichTree) selectionEvent.getSource();
    RowKeySet rks2 = selectionEvent.getAddedSet();
    Iterator rksIterator = rks2.iterator();
    if (rksIterator.hasNext()){
      List key = (List)rksIterator.next();
      JUCtrlHierBinding treeBinding = null;
      treeBinding = (JUCtrlHierBinding) ((CollectionModel)tree1.getValue()).getWrappedData();
      JUCtrlHierNodeBinding nodeBinding = nodeBinding = treeBinding.findNodeByKeyPath(key);
      String nodeStuctureDefname = nodeBinding.getHierTypeBinding().getStructureDefName(); //Here is the nullpointerexception for employees
      String employees = "view.VoEmployees";
      String departments = "view.VoDepartments";
      if (nodeStuctureDefname.equalsIgnoreCase(departments)){
       String dept = (String) nodeBinding.getAttribute("Department_name");  
       System.out.println("Department = "+dept);
      else if (nodeStuctureDefname.equalsIgnoreCase(employees)){
       String emp = (String) nodeBinding.getAttribute("First_name");  
       System.out.println("Employee = "+emp);
      else{
       //what the heck did the user click on? Ask him ;-)
    }Pagedef:
    Executables:
    <iterator Binds="VoDepartments2" RangeSize="25" DataControl="AppMainDataControl" id="VoDepartments2Iterator"/>
    Bindings:
    <tree IterBinding="VoDepartments2Iterator" id="VoDepartments2">
    <nodeDefinition DefName="view.VoDepartments" Name="VoDepartments20">
      <AttrNames>
       <Item Value="DepartmentId"/>
      </AttrNames>
      <Accessors>
       <Item Value="VoEmployees"/>
      </Accessors>
    </nodeDefinition>
    <nodeDefinition DefName="view.VoEmployees2" Name="VoDepartments21">
      <AttrNames>
       <Item Value="First_name"/>
       <Item Value="Last_name"/>
      </AttrNames>
    </nodeDefinition>
    </tree>The tree works just fine and list all it should list. I can click the department and my selection listener print the departments name in the console.
    I can expand a department and list all employees. The problems is when I click an employee, I get null pointer exception.
    I have found out that the selectin listener can't find nodeBiding for employees. So nodeBinding.getHierTypeBinding().getStructureDefName(); throw NullpointerException.
    Anyone have an idea of what's wrong? Please help.
    -Thomas
    Edited by: Thomas H on Mar 22, 2010 8:21 AM

    Hi,
    if you open the tree binding editor, it has an entry "Target Data Source" for each of the node levels that you can use and point to an iterator binding representing the node. Not sure if this solves the issue, but chaces are.
    1. create an iterator for a child VO (using the not dependent child VO instance)
    2. Edit Target Data Source for the binding to e.g. ${bindings.EmployeesView1Iterator}
    Frank

  • Selection listener

    i have written a bean in the selection listener of an af:table... but this does not get called on pageload
    I am refreshing a region which contains child records... based on the selection of a particular record in the af:table
    How to call this one on pageload. after pageload when i select the master records it works well... but on pageload my method doesnt get called and all records are coming

    Hi,
    you can queue a SelectionListener from Java
    SelectionListener selListener = new SelectionListener(...,...,...);
    selListener.queue();So if you find a method that is invoked on page load (e.g. phaseListener on f:view) then this can be used
    Frank

  • Problem getting the Table Data with the selection listener

    Hi All,
    I am working on a tree and table components. I wrote a logic in the backing bean in such a way that when I expand a node the child nodes for the tree are getting added dynamically and also getting the data in the table for the node expanded in the tree using the same Toplink Query . I added the selection listener for the table and when I am selecting a row in the table I am getting the Null Pointer Exception as the RowKeySet Value for the row selected is coming null.
    Can any one please help me out with this problem
    I will be very thankful
    Regards,
    Madhavi.

    Hi All,
    I am working on a tree and table components. I wrote a logic in the backing bean in such a way that when I expand a node the child nodes for the tree are getting added dynamically and also getting the data in the table for the node expanded in the tree using the same Toplink Query . I added the selection listener for the table and when I am selecting a row in the table I am getting the Null Pointer Exception as the RowKeySet Value for the row selected is coming null.
    Can any one please help me out with this problem
    I will be very thankful
    Regards,
    Madhavi.

  • JList selection problems

    I'm having problems with JList selection - it's really wierd.
    I have a Jlist and on different selections I want to do stuff - well, I do see the GUI line get highlighted but everytime my ListSelectionListener is called the selected index stays 0.
    also, it always calls the ListSelectionListener twice for every selection I make.
    here's how my code looks:
    (typesList is my JList)
    typesList.setSelectedIndex(0);
    typesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    typesList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {       
            int newSelection = typesList.getSelectedIndex(); //this returns always 0!        ...
          }

    Look at the line getValueIsAdjusting... (only one selection is processed. And, this code works and provides proper index.
        * Method to load all Tables from Database user
        public void loadTables() {
            // run Database request
            tableListModel = getListModelData("select object_name from user_objects where object_type = 'TABLE'");
            // now plug List with Model
            tableList = new JList(tableListModel);
            tableList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            tableList.setSelectedIndex(0);
            //tableList.addListSelectionListener(this);
            tableList.addListSelectionListener(
                new ListSelectionListener() {
                    public void valueChanged( ListSelectionEvent e )
                        if(e.getValueIsAdjusting()) return;
                        String tablename = tableList.getSelectedValue().toString();
                        showColumnData(tablename);
                        displayAllTableData(tablename); //intensive (reworking)
            jScrollPane1.add(tableList);
            jScrollPane1.setViewportView(tableList);
            showColumnData(tableList.getSelectedValue().toString());
        }PiratePete
    http://www.piratepetesoftware.com

  • Adding selection listener

    How do I add a Selection listener to the cancel button in a Windows file open window??

    Are you using FileDialog or JFileChooser?

  • Tree selection listener problem

    I have a JTree which uses a selection listener.
    I encounter a problem when I collapse a row while a leaf has focus.
    My program doesn't hang but so many error messages scroll up my prompt.
    How can I resolve this problem?
    Thanks!

    try to capture the error messages. If you are unable to get them from standard output, try redirecting to a file like:
    prompt>java samp > xwhere samp is your class file and x is the file your output is redirected to. After you collapse the leaf that has focus, close the application and open the file 'x'. Copy and paste the errors here.
    I'll see what I can do!

  • TreeTable Selection Listener Issue

    I have a treeTable and i have used custom selection Listener instead of using bindings.<viewObject>.treeModel.makeCurrent. since i had to do more than just makeCurrent on selection, i choose this approach. Everything is working except, when i refresh the treeTable after create, the activeRow will be first row but selection shows on where i have last selected.
    My custom selectionListener is working very fine but i have noticed that when i refresh treeTable selectionListener is never called. but only called when i make selection... Is there anyway i can get my custom selectionListener be called on refresh of treetable or is there any other way i can control selection on fresh of treeTable.
    It will be highly appreciated if you can suggest me way.
    Thanks

    Thanks Timo for the reply. I have a customization to select the second row of the tree table by default. I am customizing the 'selectedRowKeys' value to achieve this default selection. It works fine for the first time.
    In the below scenario it's is not working,
    1. Select a row other than default selected
    2. After some action i am refreshing the table, now the focus(highlight) is on the previous selected row but actually the selectedkey is second row(Scenario1)
    This my tree table structure,
    Revision 0
    - - - - Scenario1
    - - - - Scenario2
    - - - - Scenario3
    Revision 1
    - - - - Scenario 4
    - - - - Scenario 5
    - - - - Scenario 6
    Thanks,
    Nagesh

  • Getting NullPointerException in ADF form using Custom Selection Listener

    Hi,
    I am getting NullPointerException from getRowKey() in GenericTableSelectionHandler.java while pressing "Page Down" key or continuous pressing of "Down Arrow" key in Read Only ADF form (Query, Sort Enabled) using Custom Selection Listener.
    I have used the custom selection listener as mentioned at http://www.oracle.com/technetwork/developer-tools/adf/learnmore/23-generic-table-selection-listener-169162.pdf
    The requirement to use custom Selection Listener to populate some fields from the selected row.
    J Developer Version: 11.1.1.4.0
    The error is as below
    +<LifecycleImpl> <_handleException> ADF_FACES-60098:Faces lifecycle receives unhandled exceptions in phase INVOKE_APPLICATION 5+
    javax.el.ELException: java.lang.NullPointerException
    +     at com.sun.el.parser.AstValue.invoke(Unknown Source)+
    +     at com.sun.el.MethodExpressionImpl.invoke(Unknown Source)+
    +     at org.apache.myfaces.trinidad.component.UIXComponentBase.broadcastToMethodExpression(UIXComponentBase.java:1300)+
    +     at org.apache.myfaces.trinidad.component.UIXTable.broadcast(UIXTable.java:268)+
    +     at oracle.adf.view.rich.component.UIXTable.broadcast(UIXTable.java:144)+
    +     at oracle.adf.view.rich.component.rich.data.RichTable.broadcast(RichTable.java:402)+
    +     at org.apache.myfaces.trinidad.component.UIXCollection.broadcast(UIXCollection.java:148)+
    +     at org.apache.myfaces.trinidad.component.UIXTable.broadcast(UIXTable.java:271)+
    +     at oracle.adf.view.rich.component.UIXTable.broadcast(UIXTable.java:144)+
    +     at oracle.adf.view.rich.component.rich.data.RichTable.broadcast(RichTable.java:402)+
    +     at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent$1.run(ContextSwitchingComponent.java:92)+
    +     at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent._processPhase(ContextSwitchingComponent.java:361)+
    +     at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent.broadcast(ContextSwitchingComponent.java:96)+
    +     at oracle.adf.view.rich.component.fragment.UIXInclude.broadcast(UIXInclude.java:102)+
    +     at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent$1.run(ContextSwitchingComponent.java:92)+
    +     at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent._processPhase(ContextSwitchingComponent.java:361)+
    +     at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent.broadcast(ContextSwitchingComponent.java:96)+
    +     at oracle.adf.view.rich.component.fragment.UIXInclude.broadcast(UIXInclude.java:96)+
    +     at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.broadcastEvents(LifecycleImpl.java:879)+
    +     at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:312)+
    +     at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:185)+
    +     at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)+
    +     at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)+
    +     at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)+
    +     at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)+
    +     at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)+
    +     at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)+
    +     at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:205)+
    +     at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)+
    +     at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:106)+
    +     at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:446)+
    +     at oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(AdsFilter.java:60)+
    +     at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:446)+
    +     at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:271)+
    +     at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:177)+
    +     at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)+
    +     at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)+
    +     at oracle.adf.library.webapp.LibraryFilter.doFilter(LibraryFilter.java:175)+
    +     at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)+
    +     at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:111)+
    +     at java.security.AccessController.doPrivileged(Native Method)+
    +     at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:313)+
    +     at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:413)+
    +     at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:94)+
    +     at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:161)+
    +     at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)+
    +     at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)+
    +     at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:136)+
    +     at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)+
    +     at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)+
    +     at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)+
    +     at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)+
    +     at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)+
    +     at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)+
    +     at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)+
    +     at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)+
    +     at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)+
    +     at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)+
    +     at weblogic.work.ExecuteThread.execute(ExecuteThread.java:207)+
    +     at weblogic.work.ExecuteThread.run(ExecuteThread.java:176)+
    Caused by: java.lang.NullPointerException
    +     at ibm.view.GenericTableSelectionHandler.makeCurrent(GenericTableSelectionHandler.java:48)+
    +     at ibm.view.backing.Testpage.XxSelectListener(Testpage.java:207)+
    +     at sun.reflect.GeneratedMethodAccessor355.invoke(Unknown Source)+
    +     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)+
    +     at java.lang.reflect.Method.invoke(Method.java:597)+
    +     ... 60 more+
    The table structure is as below for your reference
    +<af:table value="#{bindings.TestTableAdfView1.collectionModel}"+
    var="row"
    +rows="#{bindings.TestTableAdfView1.rangeSize}"+
    +emptyText="#{bindings.TestTableAdfView1.viewable ? 'No data to display.' : 'Access Denied.'}"+
    +fetchSize="#{bindings.TestTableAdfView1.rangeSize}"+
    +rowBandingInterval="0"+
    +filterModel="#{bindings.TestTableAdfView1Query.queryDescriptor}"+
    +queryListener="#{bindings.TestTableAdfView1Query.processQuery}"+
    +filterVisible="true" varStatus="vs"+
    +rowSelection="single"+
    +binding="#{backingBeanScope.backing_testpage.t1}"+
    +id="t1"+
    +selectionListener="#{backingBeanScope.backing_testpage.XxSelectListener}">+
    Any help to resolve the issue is highly appreciated.
    Thanks,
    Arijit
    Edited by: user10570755 on Aug 2, 2011 11:19 PM

    //selection with the selection in the ADF model Object
    _selectedRowData = _table.getSelectedRowData();
    //cast to JUCtrlHierNodeBinding, which is the ADF object //that represents a row
    JUCtrlHierNodeBinding _nodeBinding = (JUCtrlHierNodeBinding) _selectedRowData;
    //get the row key from the node binding and set it //as the current row in the iterator
    Key _rwKey = _nodeBinding.getRowKey();i guess nodeBinding becoming null here.. _table.getSelectedRowData().. is not returnign anything                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • 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

Maybe you are looking for

  • Linking Subreports based on group in the main report

    Hello, I have a main report that groups by department, month, and then employee name.  I put a subreport in at the month and name level (it brings back statistics for a particular employee for the chosen month).  The subreport is based on a completel

  • Setting up NWDI for E-Commerce 5.0 and getting" No component configured"

    Hi Experts, Our basis consultant recently installed NWDI. I am having trouble setting up a Track for our E-commerce development. If i try to save my track it gives the message "No component configured". When I try to setup my Runtime sytem and give t

  • Problem with mp3 mu

    Then I have a mp3 muvo2 from 4 gb the problem I am that me it is itself blocked after the modernization of firmware.have tried to resettarlo but more is not ignited. I wanted to ask as I can resolve this type of problem thanks.<FONT color=#000080>

  • Where do i add a new email alias?

    I can no longer find where i set up a new alias email address for my iCloud account. I have found "alternate" email addresses but this doesn't accept anything i try to add as an alias so I'm guessing its not that.. This USED to be easy.. Any ideas? T

  • Why have BT put a backdoor in the 8.1.H.J firmware...

    Hi all. Some know me here because I worked out how to unlock the Home Hub 1.5 and 2 so that they can be recycled and used on non BT connections. Some don't like me because I talk straight, which is what I am going to do now. This is a question for th