JSpinner and finding which item was selected...

With a JComboBox, I can load up my list with an array and use "getSelectedIndex()" to grab the index number of the item the user selects.
With a JSpinner (SpinnerListModel), I can load up my list with an array but there doesn't appear to be any way to retrieve an index number. Am I missing something? The best thing I can come up with is to use "getValue()" and search my array for that value and then I'd have the correct index. Seems the long way around to me.
I have other elements in the array I need to get to based on the users selection.
-Duane

If you're creating your own object class to use in the list of possible values, you could make the array index be an instance variable in this class. I just had to do something like this recently. As in:
class MySpinnerValue
  public int index;
  public String name;
  //  ... other useful stuff
  public String toString()
    return name;
// ... and somewhere we create the list, like ...
MySpinnerValue[] list=new MySpinnerValue[10];
for (int x=0;x<10;++x)
  MySpinnerValue v=new MySpinnerValue();
  v.index=x;
  list[x]=v;
}Then when you retrieve a value you just check index to see where it is in the array.
Clumsy, yes, because it relies on setting an index value equal to the array subscript, which is redundant data in a sense. (Ah, there were advantages to pointers in C, you could just say "pEntry-entry[0]" to get the index ...)

Similar Messages

  • How do you specifically let the Itemlistener know which Item was selected..

    How do you specifically let the Itemlistener know which Item was selected in a JComboBox? Anyone has any idea? What should the coding look like?

    getSelectedItem()

  • How do you specifically let an Itemlistener know which Item was selected?

    How do you specifically let the Itemlistener know which Item was selected in a JComboBox? Anyone has any idea? What should the coding look like?

    Hi,
    Try this method
    String[] petStrings = { "Bird", "Cat", "Dog", "Rabbit", "Pig" };
    JComboBox petList = new JComboBox(petStrings);
    if ( petStrings[0]==(String)petList.getSelectedItem() )
    System.out.println("I'm a bird");
    }else{

  • Which Technology was selected then creating Master Repository for ODI?

    Hi,
    Which Technology was selected then creating Master Repository for ODI SQL Server 2003? Which technolgy must be selected?
    First of all I created master repository for ODI on SQL Server 2003 via Microsoft SQL Server, it did not work.
    I checked the Driver and URL as below
    com.microsoft.sqlserver.jdbc.SQLServerDriver
    jdbc:sqlserver://<servername>:<PortNumber>;selectMthod=cursor;databasename=<databasename>;integratedsecurity=false
    there is a error as below
    com.sunopsis.tools.core.exception.SnpsRuntimeException: com.sunopsis.tools.core.exception.SnpsRuntimeException: Unable to find the XML file corresponding to your technology.
         at oracle.odi.sdk.repository.OdiRepositoryManager.createMasterRepository(OdiRepositoryManager.java)
         at com.sunopsis.wizards.MasterRepositoryWizard.d(MasterRepositoryWizard.java)
         at com.sunopsis.wizards.MasterRepositoryWizard.f(MasterRepositoryWizard.java)
         at com.sunopsis.wizards.MasterRepositoryWizard.a(MasterRepositoryWizard.java)
         at com.sunopsis.wizards.MasterRepositoryWizard.a(MasterRepositoryWizard.java)
         at com.sunopsis.wizards.MasterRepositoryWizard$IvjEventHandler.actionPerformed(MasterRepositoryWizard.java)
         at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
         at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
         at java.awt.Component.processMouseEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Window.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: com.sunopsis.tools.core.exception.SnpsRuntimeException: Unable to find the XML file corresponding to your technology.
         at com.sunopsis.repository.manager.RepositoryManager.masterRepositoryCreation(RepositoryManager.java)
         ... 29 more
    Caused by:
    com.sunopsis.tools.core.exception.SnpsRuntimeException: Unable to find the XML file corresponding to your technology.
         at com.sunopsis.repository.manager.RepositoryManager.masterRepositoryCreation(RepositoryManager.java)
         at oracle.odi.sdk.repository.OdiRepositoryManager.createMasterRepository(OdiRepositoryManager.java)
         at com.sunopsis.wizards.MasterRepositoryWizard.d(MasterRepositoryWizard.java)
         at com.sunopsis.wizards.MasterRepositoryWizard.f(MasterRepositoryWizard.java)
         at com.sunopsis.wizards.MasterRepositoryWizard.a(MasterRepositoryWizard.java)
         at com.sunopsis.wizards.MasterRepositoryWizard.a(MasterRepositoryWizard.java)
         at com.sunopsis.wizards.MasterRepositoryWizard$IvjEventHandler.actionPerformed(MasterRepositoryWizard.java)
         at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
         at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
         at java.awt.Component.processMouseEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Window.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    okan
    Edited by: ankist on Jan 15, 2010 2:46 PM

    It is highly recommended to use the JDBC Driver for SQL Server 2005, even if you are using SQL Server 2000. In ODI's pre-populated lists, it is not there - you will have to (1) get the driver yourself, downloadable from the Microsoft site. (get the driver v1.2, not the 2.0, and use a JRE v1.5, 1.5 or 1.6. The 2.0 driver from Microsoft requires the JRE 1.6)
    (2) use the
    Driver: com.microsoft.sqlserver.jdbc.SQLServerDriver
    and the URL: jdbc:sqlserver://<myserver>:<myport, default 1433>;database=<mydb>;selectMethod=cursor
    these are not automatic, you will need to type them in.
    The database must be configured for connections from tcpip.
    For more information see the blog: http://odiexperts.com/?tag=sql-server-2005

  • SO Pricing User Exit - How to know which item is selected for re-pricing.

    Hello Experts,
    I have to modify material data when user does a update pricing in VA02, the problem is...How do I know which item is selected for re-pricing (in MV45AFZZ)? I am using user exit USEREXIT_PRICING_PREPARE_TKOMP.
    For Ex: If my order has 3 items and 2nd one is selected and then 'Update' is done on 'conditions' tab. Above pricing user exit is triggered 3 times for all items, so I cant check XVBAP.
    Your help will be appreciated.
    Thanks,
    Sagar

    Hi J@Y,
    Thanks for reply. But USEREXIT_PRICING_PREPARE_TKOMP is triggered for all items, so how do I know which is current item?
    If you see in debug mode, xvbap-posnr and tkomp-kposn will have 10,20,30 everytime (for 3 times). How do I know if user has selected 20?
    Thanks,
    Sagar

  • Which item is selected?

    Hello,
    In Dreamweaver CS3 we have a drop-down list in a form. When
    the user selects an element in the list, we need to determine which
    element was selected; specifically we need the text string of the
    selected element. How do you do this? The raw code that we have so
    far is attached.
    If there is an online tutorial or sample code for this, that
    would be great.

    The element or item that was selected is automatically placed
    in a form variable for you by CS3. You can access it by binding it
    to the screen you are calling.

  • I have been using firefox aurora 7 for mac. Most of my handful of add-ons have been disabled -- including Read It Later and Feedly, which I was making good use of. Can you tell me when they will be enabled for firefox aurora 7?

    I have been using firefox aurora 7 for mac. Most of my handful of add-ons have been disabled -- including Read It Later and Feedly, which I was making good use of. Can you tell me when they will be enabled for firefox aurora 7? Maybe I should go back to firefox 6

    You can use the Tab key to select a search engine on the bottom bar and press Enter to use the search engine to do the search.
    *https://support.mozilla.org/kb/Search+bar
    In the current Firefox 34 release there is a new "one-off" search bar.
    This search bar doesn't show the name of the search engine and a logo.
    You can type one letter to make a drop-down list appear where you can see suggestions and see the used search engine and that also has bar at the bottom where you can select other search engines that are enabled via the Search tab in Options/Preferences.
    You can use the Tab key to select one of the other available search engines and press the Enter key to search with the selected search engine.
    Click the search engine icon and click "Change Search Settings" to open the Search tab in Options/Preferences (positioned between Tabs and Content) to select the default search engine and select which search engines to show in the search bar drop-down list that opens when you start typing search terms.

  • I have design standard with creative cloud, I have installed this on 2 computers, my office and home which I was told was allowed, I have just tried to open an indesign file from the office at home and and error message said that this was created with a n

    I have design standard with creative cloud, I have installed this on 2 computers, my office and home which I was told was allowed, I have just tried to open an indesign file from the office at home and and error message said that this was created with a newer version? they are the same versions and both are up to date, I was asked this morning to put in my adobe id email and password to connect to CC which I have never been asked to do before, can anyone help?

    what's your home version (click help>about) and was that just a warning so you were able to open the file?

  • When in sleep mode iPhone 4 loses signal but when it's back on it searches and finds signal. Was 5.0.1. update to 5.1 but no changes

    When in sleep mode iPhone 4 loses signal but when it's back on it searches and finds signal. iOS was 5.0.1, update to 5.1 but no changes.
    Battery problem, anntena or motherboard? pleas help.

    it could be a motherboard problem. Last month I spilled liquid on to my iphone and since I didn't have warranty for it I had to take it to a "phone doctor". He fixed it but mentioned that motherboard is working fine but he can not say for sure for how long it will last, and that I may experience some wierd problems. I'm having this exact problem the day I got my iphone back.
    Well no longer but the solution still seems wierd. I turned on the "location services" because I saw in the "system services" screen that "cell network search" was turned on. I figured if I don't screw with location services, it would be okay. So, after three hours, I terminated the sleep in 10-20-30 minutes and 1 hour intervals, it seems I no longer have the problem but I'm going to sleep over it to be sure. Also make sure to turn on the "auto" option on the "carrier" menu.
    I will post the outcome if I don't forget about this page.

  • Iphone was stolen. and find my iphone was turned off. How can I erase all data

    Last night my iPhone was stolen. And find my iphone was turned off. How can i erase all data on my phone remotely?

    You can't do anything if Find My Phone was not enabled.
    What To Do If Your iDevice Is Lost Or Stolen
    iPhone, iPod Touch, and iPad
    If you activated Find My Phone before it was lost or stolen, you can track it only if it is connected to the Internet by Wi-Fi or cellular. What you cannot do is track your device using a serial number or other identifying number. You cannot expect Apple or anyone else to find your device for you. You cannot recover your loss unless you insure your device for such loss. It is not covered by your warranty.
    If your iPhone, iPod, iPod Touch, or iPad is lost or stolen what do you do? There are things you should have done in advance - before you lost it or it was stolen - and some things to do after the fact. Here are some suggestions:
    This link, Re: Help! I misplaced / lost my iPhone 5 today morning in delta Chelsea hotel downtown an I am not able to track it. Please help!, has some good advice regarding your options when your iDevice is lost or stolen.
      1. Reporting a lost or stolen Apple product
      2. Find my lost iPod Touch
      3. AT&T. Sprint, and Verizon can block stolen phones/tablets
      4. What-To-Do-When-Iphone-Is-Stolen
      5. iCloud- Use Lost Mode
      6. What to do if your iOS device is lost or stolen
      7. 6 Ways to Track and Recover Your Lost/Stolen iPhone
      8. Find My iPhone
      9. Report Stolen iPad | Stolen Lost Found Online
    It pays to be proactive by following the advice on using Find My Phone before you lose your device:
      1. Find My iPhone
      2. Setup your iDevice on iCloud
      3. OS X Lion/Mountain Lion- About Find My Mac
      4. How To Set Up Free Find Your iPhone (Even on Unsupported Devices)

  • Identifying which line was selected from a WebDynpro table

    Hi,
    can any one give me some advice, I've created a view which displays a table of filenames, which in fact are "LinkToAction" columns. The idea was that when a filename(LinkToAction) was selected, I could retrieve the appropriate file from the Applicatio server and Open the file in Excel or Save as Excel. My problem is, when I select a filename I don't know how to identify what line was selected in the table. Any advice would be great.
    Thanks,
    C

    Hi , Just identify its element which is lead selected and read attribut of that element .
    Have the code for the same
    DATA:
        node_nd_worlflow                    TYPE REF TO if_wd_context_node,
        elem_nd_worlflow                    TYPE REF TO if_wd_context_element,
        stru_nd_worlflow                    TYPE wd_this->element_nd_worlflow ,
        lead_selection_index                TYPE i,
        relation_no                         TYPE guid_32.
    navigate from <CONTEXT> to <ND_WORLFLOW> via lead selection
      node_nd_worlflow = wd_context->get_child_node( name = wd_this->wdctx_nd_worlflow ).
    @TODO handle not set lead selection
      IF ( node_nd_worlflow IS INITIAL ).
      ENDIF.
    get element via lead selection
      lead_selection_index = node_nd_worlflow->get_lead_selection_index( ).
      elem_nd_worlflow = node_nd_worlflow->get_element( index = lead_selection_index ).
    elem_nd_worlflow->get_static_attributes( IMPORTING static_attributes = stru_nd_worlflow ).
    Cheers
    Parry

  • On iPhoto you can click info and see which camera was the source for the photograph, is there any way to identify which camera took the video on iMovie?

    Is there a way to determine which camera was the source for video clips in iMovie?  You can do this in iPhoto by clicking info but I can't find out how to do it in iMovie.

    Not as far as I know.  (you can often tell from the file name format).
    Geoff.

  • UITextField and knowing which one was first responder

    I have a app with several UITextFields and I want to know which textfield was the first responder within the function.
    ie I have a text field created in interface builder and its outlet is assigned to nameField.
    So how can I know when nameField was the one that received the input from the keyboard of DONE ??
    - (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
        return YES;
    I've tried
    - (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
        [theTextField resignFirstResponder];
        if(theTextField == nameField)
            NSLog(@"I got here");
        return YES;
    But my NSLog output is not sent, so I don't know why theTextField is evaluating to false.
    Thanks

    Take a view based application and name it as textField.
    Make Sure that in interface builder set each textField delegate to File's Owner. Otherwise it won't work.
    Here is the code:
    textFieldViewController.h
    #import <UIKit/UIKit.h>
    @interface textFieldViewController : UIViewController <UITextFieldDelegate> {
              UITextField *textField1;
              UITextField *textField2;
              UITextField *textField3;
              UITextField *textField4;
              UITextField *textField5;
    @property (nonatomic, retain) IBOutlet UITextField *textField1;
    @property (nonatomic, retain) IBOutlet UITextField *textField2;
    @property (nonatomic, retain) IBOutlet UITextField *textField3;
    @property (nonatomic, retain) IBOutlet UITextField *textField4;
    @property (nonatomic, retain) IBOutlet UITextField *textField5;
    @end
    textFieldViewController.m
    #import "textFieldViewController.h"
    @implementation textFieldViewController
    @synthesize textField1;
    @synthesize textField2;
    @synthesize textField3;
    @synthesize textField4;
    @synthesize textField5;
    - (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
              [theTextField resignFirstResponder];
              if (theTextField == textField1)
                        NSLog(@"I Got here");
              return YES;
    - (void)dealloc {
              [textField1 release];
              [textField2 release];
              [textField3 release];
              [textField4 release];
              [textField5 release];
        [super dealloc];
    @end

  • Knowing which Row was selected when Hide/Show is clicked

    Hi everyone,
    I have an advanced table, with some search criteria that works. I have added a "detail" flag and when I click the link Hide/Show, the details are displayed.
    How can I get in the code which Hide/Show link was clicked? I am more interesting in getting the Row from the VO which the Hide/Show link was clicked?
    When I get the "event" parameter from the pageContext (pageContext.getParameter("event") ) it returns "hide" or "show", but I don't know which was row that was clicked.
    What I am trying to accomplish is the following. In my advanced table I have "Select" checkBoxes. I want to add the "Hide/Show details" functionality and try to have the details displayed in an advanced table with its own "Select" checkBoxes.
    Can it be done?

    Hi,
    Create a Primary Key in View Object's Query for the table.
    Now to know on which row hide/show has been clicked you need to capture the row reference which is nothing but Primary Key for that row.
    Use this code in processformrequest:
    if(("hide".equalsIgnoreCase(pageContext.getParameter("event"))))
    String rowReference = pageContext.getParameter(OAWebBeanConstants.EVENT_SOURCE_ROW_REFERENCE);
    TestMassDeleteSearchVORowImpl row = (TestMassDeleteSearchVORowImpl)am.findRowByRef(rowReference);
    String lname = (String) row.getSelectFlag();//to get the value of checkbox
    Thanks,
    Gaurav

  • Remembering which tab was selected in panelTabbedPane

    I need to have a way such that a panelTabbedPane would be dynamic. it has to remember the last selected tab or set which tab would be activated. Ex. i click tab3 of a tabbed page then it goes to a non-tabbed page, if i press CANCEL on the non-tabbed page it should go back to the tab3 - the calling tab, instead of the selectedIndex tab or like the default tab.
    Is tabChangeListener an option and how can that be implemented?
    Can you help me out? thank you.

    Hi Vj
    Are you saying that you have multiple parameters and that in each parameter the user can pick a different value and that you then want the system to sort in the order of those items?
    With some manipulation of the data you can do it. Here is what I would do and I will assume there are 3 parameters called User1, User2, User3:
    1. Create a new calculation called MySort like this:
    CASE WHEN "User Name" = :User1 THEN '1'|| "User Name" WHEN "User Name" = :User2 THEN '2'||"User Name" ELSE '3'||"User Name" END
    2. Now you create a Group Sort on this new calculation and make it hidden - the items will then appear in the order you entered them in parameters 1, 2 and 3
    If you want to use a single parameter and allow your user to enter up to three value then this can be done too but you have to change the parameter to not allow the user to key multiple values. Instead you will be using a single parameter with each individual value separated by something other than a comma, say a /.
    What you do next is use the SUBSTR command to split out the individual pieces and use those in your condition such as:
    "User Name" = Value1 OR "Use Name" = Value2 OR "User Name" = Value3, where Value1, Value2 and Value3 come by splitting up the single parameter into multiple values.
    With this done you do a similar job as I showed you at the beginning for completing the sort:
    CASE WHEN "User Name" = Value1 THEN '1'|| Value1 WHEN "User Name" = Value2 THEN '2'|| Value2 ELSE '3'|| Value3 END
    Best wishes
    Michael

Maybe you are looking for

  • IPad 2 push notifications don't work on home wifi network

    I have a new iPad 2 and I'm trying to use imo.im for instant messaging. however, in most cases, I do not get push notifications for new messages at all, and when they do appear, they are delayed by several minutes. I installed the push test app and a

  • Running ".sh" file from a stored procedure

    Hi, I need to call a file.sh linux bat file whit arguments from a stored procedure. How can I do? Thanks in advance...

  • What is a Reasonable Tradeoff Between System and Data Space in Windows 7 64bit?

    I have a brand new W530 with the 500 GB HD -- 445 GB actual total space in C: ("Windows7_OS"), including about 85 GB of OS, pre-installed applications, and Lenovo bloat-ware).  I plan to create a separate user-data partition by stealing space from th

  • Integrate multiple javabeans in one webservice

    Hi! I'm developing web services for a company, and i've a problem. I've yet built a webservice which connects via SOAP to a JavaBean. But now I want to build a webservice who connects to multiple JavaBeans (which contain the functions for the webserv

  • Why is my internet so slow?

    OK... I have an office out behind my house that I publish a weekly 'shopper' from.  Been in business for 20+ years and I have most of the latest, greatest Mac equpiment.  I have an Apple AirPort base station in the office and a bridge in the house fo