JComboBox Input Sources

Hello all,
In regards to the JComboBox, I've made an application that will accept inputs to its value from two different sources / input methods. The first way is the conventional all familiar "click the drop down menu and choose an item in the popup list". The other way would be to edit a value in JTable whose value then modifies the selection shown in the combo box via:
combo.setSelectedIndex(someIndex);When looking at the ActionEvent item produced from the combo change, both methodoligies produce the same "Source" from the following call: (being the JComboBox itself)
public void actionPerformed(ActionEvent e){
    Object source = e.getSource(); //source is the JComboBox         
}I've tried to wrap the events of JComboBox changes into other methods but have run into trouble as the .setSelectedIndex(x) call produces the same ActionEvent as choosing a value from the Combo Box itself. Then subsequently the same code would execute as if the user manually selected the item from the combo box... which is not what I want. I'm wondering if anyone else has encountered this kind of situation and what they've done as a workaround. Is there is a way to determine an input source either from the ActionEvent object or by attaching another type of listerner? Perhaps having an ActionListener on the JComboBox is itself barking up the wrong tree. I could look at the stack trace elements, but that seems a little over the top.
Any thoughts? Thanks
BTW I'm still using 1.5

<snip>
I've tried to wrap the events of JComboBox changes
into other methods but have run into trouble as the
.setSelectedIndex(x) call produces the same
ActionEvent as choosing a value from the Combo Box
itself. Then subsequently the same code would execute
as if the user manually selected the item from the
combo box... which is not what I want.]
I'm wondering
if anyone else has encountered this kind of situation
and what they've done as a workaround. The solution isn't a 'workaround'. The code behaves as it should. If the JComboBox changes, and there is an event listener listening for ActionEvents, the listener should be notified.
To get the behavior you want, you should modify the ActionEvent handler. Use a boolean flag or some other indicator to determine if the event should be ignored. Here's an example using an enum:
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class ComboTest {
    private volatile ChangeType changeType = ChangeType.NORMAL;
    ComboTest() {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        final JComboBox cb = new JComboBox();
        for (int i = 0; i < 20; i++) {
            cb.addItem(i);
        cb.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                if (changeType == ChangeType.NORMAL) {
                    System.out.println("Selected: " + cb.getSelectedIndex());
        f.add(cb, BorderLayout.NORTH);
        final JTextField tf = new JTextField();
        tf.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                changeType = ChangeType.PROGRAMMATIC;
                cb.setSelectedIndex(Integer.valueOf(tf.getText()));
                changeType = ChangeType.NORMAL;
        f.add(tf, BorderLayout.SOUTH);
        f.setSize(300,200);
        f.setVisible(true);
    public static void main(String[] args) {
        new ComboTest();
    private enum ChangeType {
        NORMAL, PROGRAMMATIC;
}

Similar Messages

  • How do I add more channels to my input source?

    I'm trying to record my son's band on a iBook in the rehearsal studio, and would like to also do this type of recording on my iMac here at home, so how do I add more channels to my input source for simultaneous multi-track recording. Right now I am only getting 2 mono and 1 stereo channels.
    Ultimately I would like to add the maximum amount (probably 8 tracks), and still be able to record simultaneously with at least one guitar, one bass, one vocal mike, and the drums on one mike...
    According to Hangtimes/Garage Door website, this is a possibility, but first I must create more channels.
    Please help. THANKS...

    shidoobie wrote:
    My input source is a Tascam US-144 USB Interface that has 2 mic in's, and 2 line in's for guitar/bass.
    I would like to separately record each input on different channels simultaneously.
    You might also want to check out the M-Audio NRV10, which is a hybrid analog mixer + firewire audio interface (with I think around 10 simultaneously available separate channels), which makes it very "band friendly" for both rehearsal and recording.

  • How to restore the languages in the input sources under 'Language and Text'

    Dear all,
    Recently, I am trying to free up my disk space on my macbook and I downloaded this software call Monolingual. Basically, it removes languages that you do not use to free up the disk space.
    However, I accidentally remove the language that I use which is Japanese and now it seems like I cannot find it anywhere under the input sources of language and text.
    Does anybody know how I can restore everything back to normal?
    Thanks in advance.
    Cheers,
    Alfred

    I think you will have to reinstall your OS.    If you are running Yosemite, see
    OS X Yosemite: Reinstall OS X
    Best to avoid Monolingual and simlar "cleaning" utilties if possible, it is too easy to make mistakes that destroy parts of you system.
    Your problem has nothing to do with your hardware, so in the futue it would be best to use the software forums for similar questions:
    Mac OS & System Software

  • How to have same keyboards input source in Mac and Windows???

    I use Canadian French-CSA on my Mac keyboards input source. Using Windows 7, I can't find the good setting for my keyboards to be the same when I it keys.
    I run Windows over Parallels Desktop
    Can anybody help?
    Thank you

    Can I use an AirPort Extreme Base Station "n"
    Yes.
    and if so, will my MacBook work with this at maximum download / upload speed (i.e. equivalent to the cable)
    The speed of your internal network generally is much much faster than the speed of your internet connection. Unless he has an internet connection faster than approx 6Mbps then even dropping down to the old 802.11b Airport would not seen any decrease in speed of downloads etc...
    and will my brother's PC's also be able to connect?
    If his PC is 802.11b/g-compliant, it shouldn't have any problems connecting to the AirPort base station.
    Or is there another Airport base station?
    The other AirPorts would work, but the AirPort Express & older 802.11g AirPort Extreme base stations have a max. range of 150 feet.
    OR-- should I head down to "Generic Computer Store" and just by a wireless router (WiFi)(think that's what they call them) and connect this to his cable modem? IF SO WILL THAT WORK FOR MY MAC?
    That is always an option as well, especially since he will be the primary user throughout the year. I'd suggest going with a brand name, like Belkin, D-Link, or Linksys for the wireless router choice.

  • Indicator of changing Input Source

    Hi all,
    today I noticed strange thing. I'm used to have 2 input sources and change them using Cmd+Alt+Space, but I do'nt like to show the Input menu in menu bar. In earlier versions of OS X there was an indication shown temporarily in the centre of display, something like volume indicator. But in OS X Yosemite this indicator is missing :-(. Is it possible to allow some option to show this list again? Or will this be back in some future upgrade? I really miss this feature, because I don't need to show the input menu in menu bar, but also when changing the input source to see which input is active.
    With regards
    Petr B.

    Nobody in these forums can tell you anything about Apple's future plans, but you can ask for that feature back via
    http://www.apple.com/feedback

  • How to get input source line number

    I wrote a XSLT transformation that checks the input XML for errors.
    When the transformer finds a problem, it can terminate with <xsl:message terminate="yes">, which outputs the line number within the transformer XML source. I do so in my implementation to indicate errors.
    But i need to output the line number of the input source, not that of the transformer source, because this is the location of the error.
    Anybody knows how to do this?
    How can i get the current line number of the input source XML text?

    Hello Fritz!
    XALAN reads the entire input file (SAX) before starting with transformation.
    So overriding the input stream is no way to find this line number.
    I think this would have to be a built-in XSLT functionality within the tag "xsl:message".

  • Help required with Gnome 3 Input Sources

    I used CapsLock before gnome 3.6 upgrade all working fine, however new Input Sources broke my system a little bit
    I fixed my CapsLock by dconf-editor org\gnome\desktop\input-sources\xkb-options ['grp:caps_toggle', 'grp_switch', 'grp_led:caps'], but I can't get work
    - language switch indicator not working
    - show-flags does nothing anymore
    Any help fit is required because of usability issues

    Also, with Gnome 3.6 it's no longer possible to switch layouts with the Caps key. That setting is not available even in gnome-tweak-tool.
    I figured out how to do make the settings a lot more flexible, and fix all the layout bugs introduced by 3.6. This is done by configuring everything through setxkbmap and not letting gnome interfere with the settings.
    Remove all input sources, and the typing shortcuts from gnome keyboard settings window.
    Open dconf-editor and remove everything from "org\gnome\desktop\input-sources\xkb-options". I was not able to set it to nothing, but setting it to ['grp_led:caps'] worked. These 2 steps were needed not to interfere with the config described below.
    Install kbdd-git from aur, if you want separate layout for each window.
    Create a script with preferred setxkbmap settings. Here is mine, setting Caps to switch languages, and swapping alt and win keys on MacBook.
    #!/bin/sh
    setxkbmap -layout us,ru
    setxkbmap -option 'grp:caps_toggle'
    setxkbmap -option 'altwin:swap_lalt_lwin'
    # kbdd is needed to keep separate layout for each window.
    `which kbdd` && kbdd
    Launch gnome-session-properties and add this script to the list.
    Last edited by ikatson (2012-11-02 21:51:13)

  • How do I add a new input source in OS X lion?

    I'm a linguist who uses a piece of software called IPA palette (http://www.blugs.com/IPA/) to type special characters.  I've just upgraded my laptop to Lion, and I no longer have access to this palette.  When I look under input sources, it doesn't show up.  How can I make this software work with Lion? 

    Hi, I'm the developer of IPA Palette. Stumbled on this question only a moment ago and thought I'd address it for the record. I don't now recall whether installing Lion clobbered my existing IPA Palette installation or not. In any case, I can with high confidence state that IPA Palette has been tested on Lion and works well, so re-installing would be the recommended way to try to get it back in play.
    Hope this helps.

  • How do I add an input source besides English in Gnome Shell? [SOLVED]

    Hello.
    I'm a bit confused as to how I should add additional languages/input sources in Gnome Shell. When I ran Gnome Shell in Ubuntu, I could add additional input sources via the Region & Language section of the Gnome control panel, but in Arch I've only got English (my locale is en_US.UTF-8). I'd like to be able to switch between English & Hebrew.
    Do I need to install an underlying gnome package for handling additional input sources? Or do I need to manually add a locale? The wiki seems unclear on this. Also, should I use localectl? I'm also a bit unsure there.
    Thanks!
    Last edited by yochaigal (2015-02-21 16:38:25)

    yochaigal wrote:Or do I need to manually add a locale?
    I think so.
    Edit the file at /etc/locale.gen and un-comment the desired locale then run:
    # locale-gen
    https://wiki.archlinux.org/index.php/Lo … ng_locales

  • Bug in Vietnamese input source

    Hi all and sorry for my bad English,
    I'm Vietnamese and Vietnamese Unikey is my default input sources. However, this input mode auto add a weird character every time I've moved cursor to another place. The weird character displayed difference depend on which application I'm working.
    Please look at some screenshots below to understand what's I meant.
    Safari:
    http://img63.imageshack.us/img63/4453/screenshot20100417at221.png
    MS Word:
    http://img46.imageshack.us/img46/4453/screenshot20100417at221.png
    Thanks
    Nguyen

    For example: Tôi (you must input from keyboard: T o o i)
    After that, press any arrow button (<-, ->, etc) then the weird character will be displayed.
    Now I see it. Before I was always completing a word by hitting the space bar before doing anything else, or using the mouse.
    The weird characters are from the Unicode Private Use Area, F702 and F703, which Apple has assigned to the Arrow keys for internal processing purposes. I think it is a bug for these to ever appear in text, and something only Apple can fix. You can let them know here:
    http://www.apple.com/feedback/macosx.html

  • Allow a different input source for each document

    I just received my new MBP and am really happy about it. I'm a switcher so apologies in advance if this question is silly...
    I use both Swedish and English keyboard maps. I can switch between them using a shortcut which is fine. However, in the International settings I thought "Allow a different input source for each document" would mean that the input source I use for a specific application will be used as long as the application is running and I don't change it, no matter what source I use in other applications.
    For example: I have the English input source as default. Then I open text edit and change the source to Swedish and start typing. So far so good. I then change to another application...
    Ok, it seemed that I might be able to answer this myself... as I test I noticed the following:
    If I start typing using a source in an application THEN the source is retained. If I just switch to an application, change its source the source is NOT retained and will take the previous one.
    Now this is all and well as long as the application you are using actually presents you with a text area to write in. But there are many applications where this is not the case (where you open windows to type text). A really good example is an IM client. Lets say Skype for example (yes I know.. iChat). Until I actually start a chat there is no text input window (well there is one..) which means that it will pick up whatever source was used previously. If I keep all the chat windows open thats fine but as soon as I reopen a windows I might be forced to change the source again
    I hope I haven't overcomplicated my question which is simply what to expect when "Allow a different input source for each document" is used (I know it doesn't say "application" there and that might actually be a hint
    Many Thanks for any comments

    It's not a silly question, but I don't think there is an answer either, as it's not clear exactly what that setting is supposed to do, or if it actually does something consistently for various different kinds of apps.
    If you have not already done so, check the box for "show input menu in Finder" in system prefs/international/input menu, so you can see which layout is active at the top right of the Finder.

  • Can't login due to input source issue

    Hi!
    I'm using my MBP (Yosemite) with a hungarian input source, however, my login password was in english.
    Yesterday, I've changed it. Now, it contains hungarian characters.
    I was able to use that password for logging in as long as the Mac just went to sleep.
    This morning, however, I rebooted my MBP and now I'm unable to login.
    It seems like the default input source is english, while in my profile, it is hungarian.
    I've never had that problem before. And I'd really need my mac back, so that I could work.
    Does anyone have any solution in mind?
    Thanks,
    Peter

    At the login screen, you can select one of the available layouts by choosing from the flag menu in the upper right corner, or cycle through them by pressing the key combination command-space or command-option-space. See this support article.

  • Why is the keyboard shortcut for 'Select next input source' disabled when using Safari?

    I'm using Safari 6.0.5 and am running 10.8.4 on a MacBook Pro 13" from last year.
    I've been using Chrome and Firefox heavily recently, but switched to Safari to give it a chance. It's really nice and lightweight, which suits me.
    However, for some reason unbeknownst to me, the keyboard shortcut 'Select next input source' is disabled in Safari, in all windows/input methods.
    Since I constantly switch input methods, this is incredibly frustrating.
    It persists after quit + restart.
    Any ideas?

    Yes, just Safari. In Chrome, Firefox and all other applications it works as expected.

  • Help: Quartz Composer - Changing the Video Input Source to Firewire/Camera

    I'm creating a Quartz composition, although can't seem to be able to select anything other than the built-in iSight camera of my mac. I have a camera attached via Firewire, and can record from it into Quicktime, for example, although can't get it as an input to QC.
    I've created a video input source, and wired that to a billboard renderer. It displays the video from the iSight fine, but not from the camera.
    I'm really stuck! Help!

    Finally I managed to get this sorted!
    I'd managed to miss the settings in the patch's Inspector window. By clicking on the input patch, then the inspector, I selected the DV camera in the settings drop-down.

  • Input source

    Hi,
    I got new "pages" for macbook pro with maverics OS. It seems it's missing half of what there was in previous version. I need to use DEVANAGARI QWERTY input and it's not there. I also use diacritics and previously I had English Pro, of course not there any longer.
    Does anybody know what to do? Or should I just get back the old version?
    Thanks a lot!

    Kat Julia wrote:
    I need to use DEVANAGARI QWERTY input and it's not there. I also use diacritics and previously I had English Pro, of course not there any longer.
    Those keyboard layouts are part of the OS, not Pages.  Have you gone to System Prefences/Keyboard/Input Sources and used the Plus button to add Devangari Qwerty and US Extended to your keyboard list?  Have you checked the box for Show Input Menu in Menu Bar so you can switch keyboards by using the "flag" menu at the top right of the screen?
    You should be able to type Devanagari and accented Latin just as well in Pages 5 as you can in Pages 4.

Maybe you are looking for

  • How to compare data in a single table by month and year

    Hello Please., i would like to see the 2014-06 matched results (3rd query), if the same ssn and acctno is exist in 2012-06 and 2013-06 and 2014-06 then eliminate from results, otherwise show it select ssn, acctno From jnj.drgSamples where Channel ='K

  • View link creation on two view objects, and both view objects are populated program(not from sql)

    I have master and detail VO , both views data is loaded in program. Now for show/hide feature, I create View Link Object and using one element from both child and master VO , View Link Object created properly. But I can not able to add that view link

  • Order mismatch in selected data using Select query

    Hello Experts, We are upgrading from 4.6C to ECC6. I came across a select query on a custom table, which gives different order of data from 4.6C to ECC6. Data (no. of records) is same in both the servers but order is different. Table doesn't have ind

  • Livetype to FCS problem

    Hi, having problems importing titles from livetype into final cut studio. Ive created the titles with no problem and rendered them in LT but when I import into FCS I get a blank screen with unrendered right across the middle. What am I doing wrong???

  • Can't install iphoto 6 on mac g4

    HI, is there a trick to installing iphoto 6 on a g4 flat panel. 700hz machine. It won't install. Says there is an error. Tried everything. Thanks.