Dynamic JComboBox small bug...

Hey,
I have made the following script to create a JComboBox containing car makes, which has an actionListener on it, so when a car make is selected the model can be set and a JComboBox for the model is created:
        String[] carManString = { "Audi", "BMW", "Ford", "Fiat", "Nissan", "Rover", "Volkswagen", "Vauxhall" };
        JComboBox carManList = new JComboBox(carManString);
        carManList.setSelectedIndex(0);
        carManList.setBounds( 125, 20, 120, 20 );
        policyPanel.add( carManList );
        // add actionListener to set specific model for make
        carManList.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {           
                JComboBox carManList = (JComboBox)e.getSource(); //find out car make
                final String carMake = (String)carManList.getSelectedItem();          
                Runnable updateAComponent = new Runnable() {
                public void run() {
                if( carMake == "Audi" )
                {   String[] carModelString = { "Audi_1", "Audi_2", "Audi_3", "Audi_4", "Audi_5" }; 
                JComboBox carModelList = new JComboBox(carModelString); //create combo box for model
                carModelList.setSelectedIndex(0);
                carModelList.setBounds( 305, 20, 120, 20 );
                policyPanel.remove( carModelList ); // remove previously selected models from panel
                policyPanel.add( carModelList ); // add new combobox of models
                else if ( carMake == "BMW" )
                {   String[] carModelString = { "BMW_1", "BMW_2", "BMW_3", "BMW_4", "BMW_5" }; 
                JComboBox carModelList = new JComboBox(carModelString);
                carModelList.setSelectedIndex(0);
                carModelList.setBounds( 305, 20, 120, 20 );
                policyPanel.remove( carModelList );
                policyPanel.add( carModelList );  
                else if ( carMake == "Ford" )
                {   String[] carModelString = { "Ford_1", "Ford_2", "Ford_3", "Ford_4", "Ford_5" }; 
                JComboBox carModelList = new JComboBox(carModelString);
                carModelList.setSelectedIndex(0);
                carModelList.setBounds( 305, 20, 120, 20 );
                policyPanel.remove( carModelList );
                policyPanel.add( carModelList );  
                else if ( carMake == "Fiat" )
                {   String[] carModelString = { "Fiat_1", "Fiat_2", "Fiat_3", "Fiat_4", "Fiat_5" }; 
                JComboBox carModelList = new JComboBox(carModelString);
                carModelList.setSelectedIndex(0);
                carModelList.setBounds( 305, 20, 120, 20 );
                policyPanel.remove( carModelList );
                policyPanel.add( carModelList );  
                else if ( carMake == "Nissan" )
                {   String[] carModelString = { "Nissan_1", "Nissan_2", "Nissan_3", "Nissan_4", "Nissan_5" }; 
                JComboBox carModelList = new JComboBox(carModelString);
                carModelList.setSelectedIndex(0);
                carModelList.setBounds( 305, 20, 120, 20 );
                policyPanel.remove( carModelList );
                policyPanel.add( carModelList );          
                else if ( carMake == "Rover" )
                {   String[] carModelString = { "Rover_1", "Rover_2", "Rover_3", "Rover_4", "Rover_5" }; 
                JComboBox carModelList = new JComboBox(carModelString);
                carModelList.setSelectedIndex(0);
                carModelList.setBounds( 305, 20, 120, 20 );
                policyPanel.remove( carModelList );
                policyPanel.add( carModelList );   
                else if ( carMake == "Volkswagen" )
                {   String[] carModelString = { "Volkswagen_1", "Volkswagen_2", "Volkswagen_3", "Volkswagen_4", "Volkswagen_5" }; 
                JComboBox carModelList = new JComboBox(carModelString);
                carModelList.setSelectedIndex(0);
                carModelList.setBounds( 305, 20, 120, 20 );
                policyPanel.remove( carModelList );
                policyPanel.add( carModelList );  
                else if ( carMake == "Vauxhall" )
                {   String[] carModelString = { "Vauxhall_1", "Vauxhall_2", "Vauxhall_3", "Vauxhall_4", "Vauxhall_5" }; 
                JComboBox carModelList = new JComboBox(carModelString);
                carModelList.setSelectedIndex(0);
                carModelList.setBounds( 305, 20, 120, 20 );
                policyPanel.remove( carModelList );
                policyPanel.add( carModelList );  
SwingUtilities.invokeLater(updateAComponent);
        });This seems to work fine apart from a few small problems.
The first is that the model comboBox only update after the make is chosen, then if you click somewhere on the JFrame it will update...should it not update immediatly when a selection is made?
The second problem is, if I click on the model combobox and select a model, the models change back to whatever the first make was selected...so if i choose Audi, then BMW and click the model combobox it will change back to the Audi models...
Any help greatly appretiated...
-Ross

removing/adding you need to include a validate, but looking at your code a bit more , this
might be all you need to do (you'll need additional code for any event of picking eg Audi_3)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Testing extends JFrame
  String[] carManString = { "Audi", "BMW", "Ford", "Fiat", "Nissan", "Rover", "Volkswagen", "Vauxhall" };
  JComboBox carManList = new JComboBox(carManString);
  public Testing()
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(200,100);
    setLocation(400,300);
    carManList.setSelectedIndex(0);
    carManList.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e){
        String[][] modelStrings =
          {{ "Audi_1", "Audi_2", "Audi_3", "Audi_4", "Audi_5" },
           { "BMW_1", "BMW_2", "BMW_3", "BMW_4", "BMW_5" },
           { "Ford_1", "Ford_2", "Ford_3", "Ford_4", "Ford_5" },
           { "Fiat_1", "Fiat_2", "Fiat_3", "Fiat_4", "Fiat_5" },
           { "Nissan_1", "Nissan_2", "Nissan_3", "Nissan_4", "Nissan_5" },
           { "Rover_1", "Rover_2", "Rover_3", "Rover_4", "Rover_5" },
           { "Volkswagen_1", "Volkswagen_2", "Volkswagen_3", "Volkswagen_4", "Volkswagen_5" },
           { "Vauxhall_1", "Vauxhall_2", "Vauxhall_3", "Vauxhall_4", "Vauxhall_5" }};
        DefaultComboBoxModel newModel = new DefaultComboBoxModel(modelStrings[carManList.getSelectedIndex()]);
        carManList.setModel(newModel);
        carManList.removeActionListener(this);}});
    JPanel jp = new JPanel();
    jp.add(carManList);
    getContentPane().add(jp);
  public static void main(String[] args){new Testing().setVisible(true);}
}

Similar Messages

  • Satellite P500-1D6 - Small bug between cover plate and screen.

    Hi
    I have a small bug (in Dutch: "donderbeestje") between the protective glass and the actual screen.
    Where I bought the laptop they yell me that they can't do anything about it and this is not under warranty of Toshiba.
    For me however, this should be under warranty of Toshiba.
    The screen with it's upper layers should be firmly closed so that no foreign objects can come in between.
    So, my question is if this is under warranty or if not, what can I do to get this thing out of there?
    Kind regards,
    Pascal.

    Hey,
    Regarding such hardware related problems you should contact an official authorized service provider. The guys can repair notebooks under warrant for free if its a warranty case. Furthermore they can give you an exact if its normal or hardware problem.
    Here its only an user to user forum so nobody can give you an exact answer but a full list of all ASPs you can find here:
    http://eu.computers.toshiba-europe.com > Support & Downloads > Find an authorized service provider

  • It looked like a small bug going up and down on my screen then it stopped about 12 o clock a quarter of the way from the top, now it seems to be burned in to the inside of the screen, anyone seen this before?  And what can be done about it,  macbook pro

    I have what looked like a small bug that ran up and down the screen and then sudenly stopped in center upper half of screen and now appears to be burned in to the inside of the screen, anyone had this probelm before and what can be done about it?

    Thanks for the suggestion, the next step was to call Apple, who gave me a claim number, which I discovered you must have to get anything done with them.  They refered me to a Apple store or repair center, after some reseach took it to the Computer Store in Mobile, Alabama and they were excellent.  They took pictures of the screen with bug submitted it to Apple who denied the claim but they kept kicking it up to the next level and finally Apple agreed to sent new cover.  The Computer Store had the cover the next day, they changed it out and now I am bug free.  If your in the area of Mobile Alabama you can feel good about getting help from the Computer Store.  For the two folks that responded to my note, Thank You, good comments and good advice.

  • Small Bug in Flash 8: loading swf that´s a vectorized image in many layers

    Hi! There´s a small bug in flash 8. If you load a swf
    that it´s a vectorized image in many layers, when you give it
    an action in onLoadInit, like mc.onRelease, the mc don´t
    "catch" that action. You can try loading an image (it works), a lot
    of swf (it works), but with this kind of swf the actions onRelease,
    onPress, etc... don´t work.
    The
    swf
    I´ll make a different vectorized image to make it works
    (if there is only one layer it works)

    Seems odd it will only run once. Usually if a cache problem
    you get the same
    results even when you update the movie or server scripts.
    If it is
    http:// it is not local even if from the browser
    cache.
    Verify the html is validated.
    Check to see if this applies to all swfs. Create a simple
    hello world swf
    that connects to a JSP script that returns a simple value to
    Flash. If that
    seems to work, then the problem is in the JSP or
    Actionscripting coding.
    Check you can load the JSP script repeatedly using a direct
    call to it on
    the browser line using
    http://.
    Lon Hosford
    www.lonhosford.com
    Flash, Actionscript and Flash Media Server examples:
    http://flashexamples.hosfordusa.com
    May many happy bits flow your way!
    "srikanth_s_india" <[email protected]> wrote
    in message
    news:e6obld$lfb$[email protected]..
    > Thanks for the article link.
    >
    > I can't provide the URL as it is within our application
    which requires
    > logging
    > in. However, one more interesting thing about it is that
    it always works
    > for
    > the first time (in the browser/machine) but not from the
    next time.
    >
    > My doubt is whether it is because of the caching? When
    it loads for the
    > first
    > time, the HTML and SWF files load from our server and
    hence are allowed to
    > communicate with our JSP. However, when it loads the
    subsequent times, it
    > probably loads from the cache and hence considered as a
    local file and not
    > allowed to communicate with our JSP file which is on the
    Internet.
    >
    > Can anybody tell me how to enable a local SWF file to
    load SWF files from
    > the
    > Internet & access URLs from the Internet in Flash 8
    pluggin?
    >

  • Small bug in WAP4410N firmware 2.0.3.3

    Attached is a screenshot of a small bug in the System Up Time. It shows Hour:Day:Sec where it should show Hour:Min:Sec.

    It seems to happen when using external monitor and "Mirroring" is enabled.
    We'll do some more tests to fully confirm
    If someone else has also noticed this, please post details.
    Thanks!
    HD Cam Team
    Group of photographers and filmmakers using Canon cameras for serious purposes.
    www.hdcamteam.com | www.twitter.com/HDCamTeam | www.facebook.com/HDCamTeam

  • Small bug in iTunes 7.4.3. on Win XP Pro SP2

    It's a small bug. When I try to edit few or more MP3's file information (ID Tag), but they are "read-only", the change dialog appear normally - all edit forms are enabled - but when I press "OK" the changes didn't save and no error box appear.
    I think that somebody understand this - sorry for my English!

    Yes I do, I'm using an administrator account.
    I dont understand what is going on.
    I had an Oracle 8i installed before. but I delete all the registry entries. And installed the jre 1.4.2.05.
    But nothing . Always abort in 36%.

  • Some small bugs and errors

    Hi,
    In the meantime, waiting for the DPS network fix, I have some small bugs and errors to post:
    #1: When signed ot from the folio builder panel, the click to create new folio message isn't useful, as it doesn't work. You must be signed in.
    #2: "System Status" cut off on the DPS Status Website:

    Hi Bob,
    Just tested again. but nope, it doesn't work for me anymore. Since one of the latest updates, I can only create folios, when I'm signed in. Here is my video proof:
    This is the case for me on two (tested) computers running CS5.5 and CS6!
    That's why I thought this feature has been removed.

  • Small bug: Database configuration - Initialization parameters

    Hi!
    SQLDeveloper version: 3.2.20.09
    View -> DBA -> Database configuration -> Initialization Parameters -> right click "Open" -> editor with "Parameter" and "Value" (inter alia) columns appears
    Changing value for parameter "optimizer_features_enable" isn't working:
    Example:
    Parameter: optimizer_features_enable
    Changing value from 11.2.0.1 to 9.2.0 -> commiting changes -> ORA-02017 error appears ("integer value required")
    In "Messages - Log" window appears the following statement: ALTER SYSTEM SET optimizer_features_enable=9.2.0 COMMENT='' SCOPE=MEMORY
    I think rather it should be: ALTER SYSTEM SET optimizer_features_enable='9.2.0' COMMENT='' SCOPE=MEMORY
    It looks like a small bug.

    Hi dz_r,
    One workaround for this case is, when editing the data in the grid cell, to enclose the Oracle version in single quotes. After committing to apply the update (which works), the grid refresh strips away the single quotes, leaving the desired value displayed in the cell.
    So this is, as you say, a small bug. Note that not all parameters of type String require single quotes, e. g., cursor_sharing=exact. Probably any String beginning with a numeric digit should be enclosed in quotes automatically.
    I logged the following bug:
    Bug 16733790 - UPDATING INITIALIZATION PARAMETER OF TYPE STRING FAILS IF BEGINS WITH A NUMERIC
    Thanks for reporting this,
    Gary
    SQL Developer Team

  • Small bug in DHCP setting

    If I write a message in DHCP settings using quote (for example: Welcome to "NewNetwork") the base assigns to the clients a local IP (169.x.x.x) and no connections to internet.
    If I write the same message without quotes (Welcome to NewNetwork) IP assigned to the client are correct (10.0.1.x or other ranges) and all works fine.
    A small bug but all a night to find it!

    Right, the original method does not make much sense. It shows the point wrt.Generics, though.

  • Small bug in 4.0.4

    Hi, I own Neo V with android 4.0.4 installed, I found a small bug:
    In the smart dial if you press the volume up or down, instead of ringer volume it sets media volume. It's no big deal but it is a bug

    Thanks for posting this. I will feed this back to the developers.
    What do you think about this forum? Let us know by doing this short survey.

  • A small bug on lock screen

    Hi,
    there was a bug on lock screen before the update and it is still there. I thought Sony might have not been noticed it because it is really a small bug so I wanted to give information. If you use draw pattern when you touch left or right bottom corner for a while it reflects as you touch widget. Or if you slide top to down at right or left corner it enlarges the widget.
    Edit: I have take some screen shots:

    Sorry for spam but someone should take care of this 

  • Polymorphic VI / Select Type (small bug ?)

    My english is not good enough to explain all this, so i prefer to use a picture
    I think this behavior is not correct   (small bug ?)
    this problem is about the use of a polymorphic vi and the "Select Type" command.
    (my polymorphic vi in attached file)
    for a quick test -----> QUICK_TEST.vi 
    Attachments:
    polymorphic (Wait ms + dataflow).zip ‏101 KB

    CAR 354827 discussed in this thread has been fixed in LabVIEW 2013

  • A small bug in Windows Media Player 12 on Windows 8.1 and Windows 7

    First of all, do excuse me as I have absolutely no idea where to go to report bugs in either Windows Media Player, or the Microsoft's Media Foundation filters that most probably handle the actual parsing and decoding. I see that some related bug reports
    have gotten noticed here on the Technet forums, and thus ended up writing here.
    Some time ago I helped a fellow internet user to update his encoding pipe line from quite an older version of ffmpeg and libx264 to a newer one. After some testing, I noticed him being unhappy with the result because of "black borders" around the
    video clip, but only in WMP12, not in other players. Being interested in what this was, I went on and started checking out the behavior.
    What I found out is that, with the newer ffmpeg and libx264, WMP12 was only seeing the video resolution (which was 1440x1080) at first, and resized/matched the player window according to that. Only after that did it then, within this window, actually show
    the video and apply the correct aspect ratio to it (4:3 sample/pixel aspect ratio, or 16:9 display aspect ratio). In other words, the video would play correctly, but within a 4:3 display aspect ratio video surface, leading to black bars on the top and the
    bottom.
    Now, if you manually resize the window, the black borders would of course go away. This is because they were not part of the video, but just something the player had based its window size calculations on originally. With the older ffmpeg + libx264 mix
    things would Just Work, and the auto-sizing worked.
    So I went off to look up all the data in the files that could relate to aspect ratio :) .
    [tkhd: Track Header Box] in the container has the width and height set to 1920x1080 in both files, so this is most probably ignored
    [pasp: Pixel Aspect Ratio Box] in the container is only present in the new one, and thus most probably ignored. hSpacing and vSpacing are set to 4 and 3, thus becoming 4:3 (this is the
    pixel or sample aspect ratio, so this is correct for 1440x1080 to be shown as 16:9). This information, if available, should trump the aspect ratio information in the stream (a quote from ISO/IEC 14496-12: "These
    (pasp and clap boxes) are both optional; if present, they over-ride the declarations (if any) in
    structures specific to the video codec, which structures should be examined if these boxes are absent.") .
    In the actual AVC/H.264 stream both files have aspect_ratio_idc set. The older file has the value set to 255 (Extended_SAR structure follows), and Extended_SAR then contains sar_width set to 4 and sar_height set to 3. On the newer file, on the other hand,
    we have a value of 14. Looking at the H.264 specification, value 14 is defined as "4:3 , 1440x1080 16:9 frame without horizontal overscan"
    So... Since the pasp box seems to be completely irrelevant and ignored, and since the tkhd box contains exactly the same information in both cases and thus seems to be ignored, the only thing that comes to mind is that:
    Only the information from the AVC/H.264 video stream is actually taken into mention at this stage.
    The AVC/H.264 video stream parser does not know the aspect_ratio_idc value 14.
    I haven't actually tried to change the values in the parameter set's VUI parameters around to be sure of this being the reason, but, unless WMP misunderstands what the pasp box's value means (4:3 read as the aspect ratio for the whole picture, instead of
    one sample/pixel), that's the only reason I can see this happening because of.
    A small sample mp4 file for this issue is provided at fushizen.eu/samples/wmp12_mp4/merry_christmas.mp4 . Having the automatic zoom set to 50% does help replicating it with smaller displays :) . WMP will resize its video window to a 4:3 display aspect ratio,
    and then show the 16:9 display aspect ratio content within that. This happens with both Windows 8.1 as well as Windows 7, on Windows Media Player 12.
    Now, if the issue is actually on ffmpeg's or libx264's side, feel free to note the technical problems with the sample, and I will review and then report them if I see the related specifications agreeing on the issue. So far this seems to be purely a problem
    with the related Media Foundation filters, and/or Windows Media Player 12.

    I have a lot of grief with this version of Windows Media Player.
    It is very buggy and frustrating to use.
    I have my Music library on a QNAP NAS, which is as reliable as they come.
    System notifications make it not save changes.  It also does not do a good job of interpreting albums and artists from folders.  Changes to track names are not saved, nor are tracks moved to other albums, renamed albums, changes to genre, artist
    or date.  It separates and merges albums/tracks without sense or reason.  Some changes I've made up to 4 times, then closed WMP and re-started my machine to check if it has/hasn't saved the changes.  Often it has not.
    This is the first time I've used WMP in this capacity, and I do not recommend it.
    New service pack please.

  • Small bugs in software on iPhone 3G running iOS 4.1

    Hi, since I upgraded my iPhone 3G to iOS 4.1 a few days ago, I have noticed a couple of small problems/bugs, and was wondering if anyone else has had similar experiences. One problem is, before iOS 4.1, when I was running the 3.1.2 software, my wifi signal "strength" indicator would usually show full bars for our home wifi network. Now, with the iOS 4.1 upgrade, the wifi signal strength generally (with the same network) shows as being one bar less than maximum.
    The other problem is a bug with listening to song previews in the "iTunes" app. I'm pretty sure that before the 4.1 software, I could tap a song once and the preview would start playing pretty quickly. Now, however, this works about one out of five times, and the rest of the time the "spinning indicator" spins for ages, and the only way it will play a song preview is if I tap the name of the song again. This is just a minor annoyance, but ideally it would be good to have the feature working as well as it did in the 3.1.2 software.
    Has anyone else experienced these problems with iOS 4.1 on an iPhone 3G? And could it be to do with the fact that I upgraded an existing install of iPhone OS (for instance, if I was installing Mac OS X and I was having problems, I'd do a clean install instead of an upgrade install)? Could it be worth trying to set up the phone as a new phone to try and avoid these problems? Many thanks,
    Arko Chakrabarty

    One thing about this update, that is supposed (among other things) to resolve the iPhone 3G bugs:
    well, it is better, but not yet perfect! Some slowliness and freezes left!
    Come on, Apple guys (and girls), go for it!!! Get iPhone 3g a real update! You know you can do it Please??
    Oh, one more thing:
    the iPhone 3G is my wife's. I now have an iPhone4. And with the 4.0.2 update, I saw some slowliness. Just a little bit, of course, not like the iPhone 3G! Well, cout that be a lead?
    Message was edited by: Arnaud Davidian

  • JLabel Text merges into JComboBox - GBLayout bug?

    Hello,
    http://666kb.com/i/ayv9fbt03b8v1bkcy.png
    as you can see the text of the JLabel goes into the JComboBox, buy why? The Code looks ok to me:
    panel3.setLayout(new GridBagLayout());       
           addJComponentToJPanel( panel3,movieFormatLB       ,0 , 0 , 4 , 1 , 1 , 1 , GridBagConstraints.NORTH,GridBagConstraints.BOTH);
           addJComponentToJPanel( panel3,movieFormatCB       ,1 , 0 , 1 , 1 , 1 , 1 , GridBagConstraints.NORTH,GridBagConstraints.BOTH);      
           addJComponentToJPanel( panel3,movieFormatAddBT    ,2 , 0 , 1 , 1 , 1 , 1 , GridBagConstraints.NORTH,GridBagConstraints.BOTH);
           addJComponentToJPanel( panel3,movieFormatDelBT    ,3 , 0 , 1 , 1 , 1 , 1 , GridBagConstraints.NORTH,GridBagConstraints.BOTH);
           addJComponentToJPanel( panel3,playLengthLB        ,0 , 1 , 1 , 1 , 1 , 1 , GridBagConstraints.NORTH,GridBagConstraints.BOTH);
           addJComponentToJPanel( panel3,playLengthCB        ,1 , 1 , 1 , 1 , 1 , 1 , GridBagConstraints.NORTH,GridBagConstraints.BOTH);      
           addJComponentToJPanel( panel3,playLengthAddBT     ,2 , 1 , 1 , 1 , 1 , 1 , GridBagConstraints.NORTH,GridBagConstraints.BOTH);
           addJComponentToJPanel( panel3,playLengthDelBT     ,3 , 1 , 1 , 1 , 1 , 1 , GridBagConstraints.NORTH,GridBagConstraints.BOTH);
           addJPanelToJFrame( panel3,0,2,1,1,1,5,GridBagConstraints.NORTH,GridBagConstraints.BOTH);        another problem is why can`t I change the width of the add/del Buttons? I can enter any value in in weightX doesnt matter nothing changes?

    void addJComponentToJPanel(JPanel panel, JComponent c, int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, int anchor, int fill )
             panel.add(c, new GridBagConstraints(gridx, gridy, gridwidth, gridheight, weightx, weighty, anchor, fill, new Insets(0, 0, 0, 0), 0, 0));       
        }when i change this line:
    addJComponentToJPanel( panel3,movieFormatCB       ,1 , 0 , 1 , 1 , 1 , 1 , GridBagConstraints.NORTH,GridBagConstraints.BOTH); to this:
    addJComponentToJPanel( panel3,movieFormatCB ,1 , 0 , 1 , 1 , *30* , 1 , GridBagConstraints.NORTH,GridBagConstraints.BOTH);
    JLabel + JComboBox are still more merging into each other not only that the add/del Buttons dont get smaller by widening the JComboBox but this is what i wanna achieve.

Maybe you are looking for