Update the testfield when setSelectedItem() for editable JComboBox

Hi,
I am having problem with setSelectedItem() and setSelectedIndex() methods of editable JComboBox.
I extended JComboBox with default dataModel. When I enter some string in the textfield of the combobox, I call insertItemAt() method to dynamically grow the list. The application requires to clear the textfield everytime I enter something and press "return" key. To make it work, I insert an empty string to the list at the very beginning and call the setSelectedItem("") method in the actionPerformed().
Now the problem is that I know the setSelectedItem("") is called since the getActionCommand() returns "comboBoxChanged" everytime I enter something in the textfield, but the testfield is not cleared. And if I select one item from the list and press "enter" key, the textfield is cleared. To make things more interesting, after I enter the first string and press "enter", the textfield really get cleared, but not for all other later input. Is this a bug? Can anyone please help me? Thanks a lot. Below is my code snippet.
public class MyComboBox extends JComboBox implements ActionListener
public GsISCommComboBox()
jbInit();
private void jbInit() throws Exception
this.setEditable(true);
this.addActionListener(this);
insertItemAt("",0);
public void actionPerformed(ActionEvent e)
String str=null;
String strrr=e.getActionCommand();
System.out.println("getActionCommand: "+strrr);
if(strrr.equalsIgnoreCase("comboBoxChanged"))
str=(String)this.getSelectedItem();
return;
else
str=strrr;
// other stuff to process the string and do things
setSelectedItem("");
repaint();
hidePopup();
insertItemAt(str,0);

Try inserting your string first and then, try clearing the combobox's textfield.
insertItemAt(str,0);
setSelectedItem("");
hidePopup();
repaint();
Since you add the "" string at the begining, it will have the index 0. Perhaps, you want to insert your string this way:
// insert string at the end
insertItemAt(str, this.getItemCount());
//Then use the
setSelectedIndex(0);
But you need to remember that if you add an item at the begining, index 0 may not be your '' '' string after that.
I hope that it helps.

Similar Messages

  • HT201441 Hi I bought a second-hand phone iphone4, I update the software when you want to activate the phone asked for my registration icloud I do not know what is the password for this registration, can you tell me how to go to the next step without such

    Hi I bought a second-hand phone iphone4, I update the software when you want to activate the phone asked for my registration icloud I do not know what is the password for this registration, can you tell me how to go to the next step without such registration in icloud
    my ICCID is 8935905000307066111

    Unfortunately, you cannot do very much with your phone unless you get assistance from the previous owner, they should either provide you with the password to unlock it or remove their account from the phone entirely remotely through iCloud.com > Find My Phone.

  • How can I know about the latest updates / versions which when available for all the CC products, without having to install and check it with the Desktoip Creative Cloud Application ?

    How can I know about the latest updates / versions which when available for all the CC products, without having to install and check it with the Desktoip Creative Cloud Application ?

    Thanks for looking into this Jeff!
    I work with an Inventory module software and is responsible for software detection across several computers. Once an updated version comes up, I update our database with latest software details to get it detected if installed on any machines.
    The problem tracking updates with Desktop Creative Cloud Software are;
    1)We have to have it installed with the CC applications in-order to get the notification of the latest updates and have to check everyday.
    2)Only relates to the latest updates, so in-between we may miss a prior update unknowingly.Hence, the remote machines having those updates may not get  detected with the software version update which would create problem in reporting.
    3)For all CC products, there is no base or previous updates available for installation if we miss one.
    I went through the Adobe Products Update pages [Product updates] which holds good when it comes to Acrobat and Reader software which I follow to track down any newer updates but this is inconsistent when it comes to CC products like in After Effects CC, Dreamweaver CC etc...
    So overall to be very specific, is there any one channel I can follow to get the notifications only for the updates on CC products and then may be I can rely on Desktop Creative Cloud for installation if not available anywhere like in product update pages of Adobe ?
    Regards,
    Subrat

  • Hello..i have the macbook pro and i had a password when it opens and when i have updated the software when i delete something it asks me every time to put my password ;/ how do i delete my password or just correct a setting for it?

    hello..i have the macbook pro and i had a password when it opens and when i have updated the software when i delete something it asks me every time to put my password ;/ how do i delete my password or just correct a setting for it?

    You may need to rebuild permissions on your user account. To do this,boot to your Recovery partition (holding down the Command and R keys while booting) and open Terminal from the Utilities menu. In Terminal, type:  ‘resetpassword’ (without the ’s), hit return, and select the admin user. You are not going to reset your password. Click on the icon for your Macs hard drive at the top. From the drop down below it select the user account which is having issues. At the bottom of the window, you'll see an area labeled Restore Home Directory Permissions and ACLs. Click the reset button there. The process takes a few minutes. When complete, restart.   
    Repair User Permissions

  • Hello. I appreciate your help. I am in FCP7 and trying to do Boris Vector Shape effect. When I try to pull the  vector shape square from the view window to the Superimpose, I get the message: insufficient content for edit. Why?

    Hello. I appreciate your help. I am in FCP7 and trying to do Boris Vector Shape effect. When I try to pull the  vector shape square from the view window to the Superimpose, I get the message: insufficient content for edit. Why? I did this effect before and everything worked well. Thank you for your help.

    Make sure that you have no active I/O markers on the Timeline (use Option X keys to clear them).

  • In the Student and Teacher plan for $19.99 monthly, does it automatically update the programs when need to be?

    I currently have the cloud but the previous plan I purchased does not allow automatic updates, therefore I still have CS6, I am hoping with purchasing a new plan it will automatically be able to update the programs when they need to be updated.

    There are updates and upgrades.
    The Cloud app will automatically apply minor updates.
    Upgrades e.g. CC to CC 2014 have to be separately installed by the user whenever you are ready to install the major version upgrade.

  • HT203421 i buy a macbook air with my friend and i changed the apple id also.at first i can update the application but now its impossible to update the application.when i clock to update it shows the id of my fren andsomebody do you have idea to solve this

    i buy a macbook air with my friend and i changed the apple id also.at first i can update the application but now its impossible to update the application.when i clock to update it shows the id of my fren andsomebody do you have idea to solve this problem.

    The first thing to do with a second-hand computer is to erase the internal drive and install a clean copy of OS X. You — not the previous owner — must do that. How you do it depends on the model, and on whether you already own another Mac. If you're not sure of the model, enter the serial number on this page. Then find the model on this page to see what OS version was originally installed.
    1. You don't own another Mac.
    If the machine shipped with OS X 10.4 or 10.5, you need a boxed and shrink-wrapped retail Snow Leopard (OS X 10.6) installation disc from the Apple Store or a reputable reseller — not from eBay or anything of the kind. If the machine has less than 1 GB of memory, you'll need to add more in order to install 10.6. Preferably, install as much memory as it can take, according to the technical specifications.
    If the machine shipped with OS X 10.6, you need the installation media that came with it: gray installation discs, or a USB flash drive for some MacBook Air models. For early MBA models, you may need a USB optical drive or Remote Disc. You should have received the media from the previous owner, but if you didn't, order replacements from Apple. A retail disc, or the gray discs from another model, will not work.
    To boot from an optical disc or a flash drive, insert it, then reboot and hold down the C key at the startup chime. Release the key when you see the gray Apple logo on the screen.
    If the machine shipped with OS X 10.7 or later, you don't need media. It should boot into Internet Recovery mode when you hold down the key combination option-command-R at the startup chime. Release the keys when you see a spinning globe.
    2. You do own another Mac.
    If you already own another Mac that was upgraded in the App Store to the version of OS X that you want to install, and if the new Mac is compatible with it, then you can install it. Use Recovery Disk Assistant to create a bootable USB device and boot the new Mac from it by holding down the C key at the startup chime. Alternatively, if you have a Time Machine backup of OS X 10.7.3 or later on an external hard drive (not a Time Capsule or other network device), you can boot from that by holding down the option key and selecting it from the row of icons that appears. Note that if your other Mac was never upgraded in the App Store, you can't use this method.
    Once booted in Recovery, launch Disk Utility and select the icon of the internal drive — not any of the volume icons nested beneath it. In the Partition tab, select the default options: a GUID partition table with one data volume in Mac OS Extended (Journaled) format. This operation will permanently remove all existing data on the drive.
    After partitioning, quit Disk Utility and run the OS X Installer. You will need the Apple ID and password that you used to upgrade. When the installation is done, the system will automatically reboot into the Setup Assistant, which will prompt you to transfer the data from another Mac, its backups, or from a Windows computer. If you have any data to transfer, this is usually the best time to do it.
    Then run Software Update and install all available system updates from Apple. To upgrade to a major version of OS X newer than 10.6, get it from the Mac App Store. Note that you can't keep an upgraded version that was installed by the previous owner. He or she can't legally transfer it to you, and without the Apple ID you won't be able to update it in Software Update or reinstall, if that becomes necessary. The same goes for any App Store products that the previous owner installed — you have to repurchase them.
    If the previous owner "accepted" the bundled iLife applications (iPhoto, iMovie, and Garage Band) in the App Store so that he or she could update them, then they're linked to that Apple ID and you won't be able to download them without buying them. Reportedly, Apple customer service has sometimes issued redemption codes for these apps to second owners who asked.
    If the previous owner didn't deauthorize the computer in the iTunes Store under his Apple ID, you wont be able to  authorize it immediately under your ID. In that case, you'll either have to wait up to 90 days or contact iTunes Support.

  • Curious about the iOS 5 software that is coming out.  If I wait til its release to buy my iPhone 4 will it come with the iOS5 software already on it?  or should I go ahead and buy my iPhone 4 and then update the software when the iOS5 is released?

    curious about the iOS 5 software that is coming out.  If I wait til its release to buy my iPhone 4 will it come with the iOS5 software already on it?  or should I go ahead and buy my iPhone 4 and then update the software when the iOS5 is released?

    Keaten wrote:
    Yea I would have to say wait until the release of IOS 5, because the phone will probably run it a lot smoother. I mean go ahead and buy the Iphone 4 if you are dying to have it, because you can just update it which is no big deal at all, but it would be the smarter thing to wait for the new updates.
    And the networ issue as far as I am aware is fixed on the Verizon iPhones, so it really depends on which service you have.
    - correct me if i am wrong
    Have to disagree here, Apple have not even announced an iphone 5, it is pointless to speculate that we will see one or not see one until Apple actually releases a statement. ios was built and tested on the iphone 4 so there will not be any slowdown or laggyness compared to a phone that has not been released yet.
    If we are advising potential apple product buyers then we should not be putting them off buying a iphone 4 on speculations alone. Just because apple have for the last few years released an iphone every june/july does not mean then have to stick to this approach.
    Apple have not issued any statement regarding an iphone 5, until this time it does not exist, only in heresay on the internet.
    Any one looking to get an iphone 4, to you i would say waiting until ios 5 is released is a personal choice, no matter if you wait or not you will be able to update via itunes. One way or another in the future you will have to do an ios update via itunes whether this is the 5.0 software or 5,2,1.
    Please note that Apple are very closed mouthed about new hardware releases and potentially a new iphone could be round the corner, however there is no evidence to suggerst this, i.e Apple have not even mentioned an iphone 5 this year anything you hear towards the contrary is media spin thus far and speculation.
    ios 5 was built and tested to work seamlessly on iphone 4, the beta software released to developers is being tested on iphone 4. Please do not listen to people telling you that the iphone 4 will not run this ios as well as a phone that does not exist yet. When iphone 5 launches it will most likely have dual processors and not until its launch will the next gen apps start appearing.

  • I have an IPad 4.  After updating the system, when I try to look at picture on Facebook and make it larger, there is just a "circle" in the middle of the page instead of the picture.  Can anyone help me?

    I have an IPad 4.  After updating the system, when I try to look at picture on Facebook and make it larger, there is just a "circle" in the middle of the page instead of the picture.  Can anyone help me?

    Close all open apps by double-tapping the home button, then swiping up and off the screen with the app window (not the smaller icon).
    Reset your device: hold down the home button along with the sleep/wake button until the screen goes black and you see the Apple, then let go. (No data loss)

  • I have Adobe Photoshop and Adobe Lightroom on my MacBook Pro laptop. I bought an iMac and I'd like to move my installations to the larger display desktop for editing purposes. How can I go about transferring them?

    I have Adobe Photoshop and Adobe Lightroom on my MacBook Pro laptop. I bought an iMac and I'd like to move my installations to the larger display desktop for editing purposes. How can I go about transferring them?

    I have the same question. It seems that Adobe is almost impossible to contact (I ended up here at the forums to ask the same question).
    I will never buy another Adobe product again if I can get another program to replace it. If this is customer service then it is NON EXISTENT!
    I notice that your question has not been answered and why should you have to get the information from a forum? I know of no other company that makes you do this for simple product information.
    NOT HAPPY with this version of arrogant customer service (nor am I happy about renting Photoshop products into the future - it is just a money grab in my opinion). I will be voting with my feet and going elsewhere in future.

  • What does the I phone 4s newest update the 6.1 do for the I phone 4s??

    What does the I phone newest update the 6.1 do for the I phone 4s

    http://support.apple.com/kb/DL1624

  • I created a magazine using a IDD template including bleeds. When I exported to make a PDF, it cut off part of the document when uploading for printing. When I incude bleeds, it makes the document too big for printing. I need help :)

    I created a magazine using a template including bleeds. When I exported to make a PDF, it cut off part of the document when uploading for printing. When I incude bleeds, it makes the document too big for printing. I need help

    eehenry wrote:
    It is a problem with a secondary provider, "mag cloud" .
    Right, so to advise you we'd need to know the particulars of MagCloud's spec for your project; format, trim size, bleed, etc.
    It's doubtful that anything happened "when uploading for printing," so long as you were uploading a PDF, as opposed to the native InDesign file. Did the PDF look right to you before uploading?

  • Live type files look grainy and do not fill the background when used for green screen backgrounds.

    live type files look grainy and do not fill the background when used for green screen backgrounds. Ideas?

    What I want to do is somehow make my entire iMovie project smaller by compressing it somehow but without losing any footage or audio or quality. At the moment the project is a 56GB iMovie project lasting approx 1hr. I have a mixture of miniDV footage, titles created in Live Type (they are better quality than anything available in iMovie) and audio.
    The miniDV footage is automatically compressed when it transfers from my camcorder to my Mac, no worries there.
    The LiveType titles contain a motion background (imported into LT) and then text which appears and disappears at set points. The titles vary in length but are about 5 seconds each.
    The file size for the LT titles is approx 180MB per clip, the movie requires about 20 or so of these clips, making a very large file size overall.
    Is there a way that I can save something in LT so that the file size is smaller yet still keep the quality and use the clip in my iMovie ?

  • How did i open the site of photoshop for editing my photos

    How did i open the site of photoshop for editing? I only get a youtube video about how to do it.

    Hello, you opened many discussions, but gave very few informations, and we have a hard time to understand your question.
    Let's follow up where you were given an answer: http://forums.adobe.com/message/6114680#6114680

  • What is the best free app for editing word and excel documents in ipad?

    what is the best free app for editing word and excel documents in ipad?

    You can download free Quickoffice.
    https://itunes.apple.com/sg/app/quickoffice/id578386521?mt=8

Maybe you are looking for