JComboBox event problem

Hi ,
I have JComboBox in my application. I added action listener for this. When I set the values programmatically I don't want the code in the actionperformed to be executed. I can do it indirectly by using boolean flag for this, but I want to know is there any other (neat) way we can achieve this.
Thanks

You can always check to see if there is a selected index...
myComboBox.addActionListener
     new ActionListener()
          public void actionPerformed(ActionEvent e)
               if (((JComboBox)e.getSource()).getSelectedIndex() != -1)
                    //perform your operations here.
);Another way to do it would be to write your own custom action listener and consume() any event that you don't want.
Hope that helps.

Similar Messages

  • InputField fire event problem in webDynpro

    I have one validation or Fire Event problem with respect to Inputfield in web Dynpro.
    I have one Input filed and created the context varible for that, then i mapped the context varible to the InputField, and i changed the context varible type as date.So , when i run the view , it will show the calender near to the text box to select the perticular date. On select of the perticular date. It will populate selected  date in to the inputField.
    On selection of the perticular date. Based on the date i want to generate the next 12 months date at runtime in different text boxes. But the only event available for the InputField is only "onEnter". This is not useful in my case, bcz on selection of the Date , the user may not use the Enter key. so , how can use the other events like onSelection or onChange events in the InputFields to reach my needs.
    Any one  give me the idea to solve this problem.
    Vijay

    Hello Vishal,
    You may also refer the sample code in the below link
    <a href="http://sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/0c0dcacd-0401-0010-b4bd-a05a0b4d68c8">http://sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/0c0dcacd-0401-0010-b4bd-a05a0b4d68c8</a>
    Regards,
    Sudeep.

  • More event problems

    Hello again, I have yet another event problem. When I try to use this code I get an error saying Abstract class actionPerformed is not implemented in non- abstract class TableWindow. I'm not quit sure how I'm supposed to implement it.

    Here is what I believe to be the relevant code. addWindowListener works but addFocusListener returns the error.
    // Table window
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class TableWindow extends Frame implements ActionListener
    public TableWindow ()
    Create Window
    super ("Test Window");
    setBackground (SystemColor.control);
    setLocation (0, 0);
    setLayout (new GridLayout (5, 5));
    addWindowListener (new WindowAdapter ()
    public void windowClosing (WindowEvent e)
    try
    if (Connected == true)
    // Close the Statement
    stmt.close ();
    // Close the connection
    con.close ();
    catch (SQLException sqle)
    dispose ();
    System.exit (0);
    tPane = new JTabbedPane ();
    tPane.addChangeListener (new ChangeListener ()
    public void stateChanged (ChangeEvent c)
    //Status.setText ("Clicked");
    tablePane = new JPanel ();
    recordPane = new JPanel ();
    recordPane.addFocusListener(new FocusListener()
    public void focusGained(FocusEvent e)
    Status.setText ("Clicked");
    queryPane = new JPanel ();
    TName1 = new TextField (25);
    TName2 = new TextField (25);
    TName3 = new TextField (25);
    idField = new TextField (10);
    idField2 = new TextField (10);
    TitleField = new TextField (25);
    TitleField2 = new TextField (25);
    result = new TextArea ("Under Construction", 5, 30);
    NewT = new Button ("New Table");
    NewR = new Button ("New Record");
    NewQ = new Button ("New Query");
    NewT.addActionListener (this);
    NewR.addActionListener (this);
    NewQ.addActionListener (this);
    TNameLabel1 = new Label ("Enter name of table here");
    TNameLabel2 = new Label ("Enter name of table here");
    TNameLabel3 = new Label ("Enter name of table here");
    idLabel = new Label ("Enter movie ID here");
    TitleLabel = new Label ("Enter title of Movie here");
    TitleLabel2 = new Label ("Enter title of Movie here");
    tablePane.add (TNameLabel1);
    tablePane.add (TName1);
    tablePane.add (NewT);
    recordPane.add (TNameLabel2);
    recordPane.add (TName2);
    recordPane.add (idLabel);
    recordPane.add (idField);
    recordPane.add (TitleLabel);
    recordPane.add (TitleField);
    recordPane.add (NewR);
    //recordPane.add (tableChoice);
    queryPane.add (TNameLabel3);
    queryPane.add (TName3);
    queryPane.add (TitleLabel2);
    queryPane.add (TitleField2);
    queryPane.add (NewQ);
    queryPane.add (result);
    Status = new Label ("");
    // make the window and add components to it
    tPane.addTab ("Table", tablePane);
    tPane.addTab ("Record", recordPane);
    tPane.addTab ("Query", queryPane);
    add (tPane, BorderLayout.CENTER);
    add (Status, BorderLayout.SOUTH);
    pack ();
    setVisible (true);
    public static void main (String args [])
    ConnectToDatabase ("vdds");
    TableWindow tw = new TableWindow ();
    }

  • Event problem with JComboBox

    Hi, javamen.
    I ve gotten a little problem when working with Itemlistener interface. My combo has 4 options, in which the first one always appears when the applet starts up. Whenever the user DOESNT change it and submit the applet form, throught a button click, the applet gets a NullPointerException. But, if the user changes the option, i always get it, throught my interface' methods(ItemStateChanged). Of course, i know its because there was no combobox event, just a button event (click). So, how can i deal with this situation, since i need to get the combobox option content.
    Regards, Euclides.

    But, this is the question! I dont know how to initialize the combobox' first option. Help me, please! I am using the addItem method as follow:
    MakeJCombo ( JComboBox ComboObj) {
    ComboObj.addItem ("option1");
    ComboObj.addItem ("option2");
    ComboObj.addItem ("option3");
    then:
    public void itemStateChange(ItemEvent ie) ...
    Object origem = ie.getSource()...
    if (origem == ComboObj) ...

  • Multiple JComboBox Event Handling Problem

    Hi, guys
    I am a newbie in Java. I need to create three JComboBox, say date, month and year and a JButton "submit". After I select the entries from the three JComboBox, I click the "search" button to display something in terms of the information I selected, but I have no idea how to write the actionPerformed( ActionEvent evt) to deal with the problem. Can anyone give me some hint?
    Any help would be appreciated.

    If you are asking how to write a basic event handler for when your button is pressed, RTM.
    http://java.sun.com/docs/books/tutorial/uiswing/events/index.html

  • JComboBox Action Event problems

    I have a complex UI with which I am having action event issues. Basically, the panel displays info about an object, which can be selected from within the panel through a button/popup window mechanism. A JComboBox (#1) selection determines the contents of another JComboBox (#2) on the same panel. Currently an ActionEvent fires when the user makes a selection using #1 that updates #2. This fuctions correctly with repeated testing so long as a new object is not selected.
    When a new object is selected from within this panel this ActionEvent no longer fires. JComboBox #1 will be updated correctly and #2 will reflect the initial selection in #1, but user selections in #1 will not fire the ActionEvent and thus #2 is never updated.
    Any help is appreciated. I feel like I'm missing something basic here, but I've stared at it for long enough...

    By the way, the workaround is to use the ItemListener as the ItemStateChanged Event is fired reliably.

  • JCombobox selection problem

    Hello,
    I have some problem implementing events associated with JComboBox. My requirement is "the event should get fired only when an item is selected in the combobox". It may occur thet using arrow keys I can traverse all elements in the combobox and on item change the event should not get fired. I tried with itemstatechanged, actionperformed but no result.
    Any help will be appreciated.
    regards,
    Ranjan

    A simple working example:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class ComboBoxAction extends JFrame implements ActionListener
         private JComboBox comboBox;
         public ComboBoxAction()
              comboBox = new JComboBox();
              comboBox.addActionListener( this );
              comboBox.addItem( "Item 1" );
              comboBox.addItem( "Item 2" );
              comboBox.addItem( "Item 3" );
              comboBox.addItem( "Item 4" );
              //  This prevents action events from being fired when the
              //  up/down arrow keys are used on the dropdown menu
              comboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
              getContentPane().add( comboBox );
         public void actionPerformed(ActionEvent e)
              System.out.println( comboBox.getSelectedItem() );
              //  make sure popup is closed when 'isTableCellEditor' is used
              comboBox.hidePopup();
         public static void main(String[] args)
              JFrame frame = new ComboBoxAction();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible( true );
    }

  • JComboBox listener problem

    Hi all,
    I have following problem, i use combobox and i need to write listener for selecting item.
    But both ActionListener and ItemListener are unusable for me, because i dont know how to differ between selecting item when combobox is poped up.
    I dont want to react on going thru items in popup, but only to FINAL select of button.
    Please Help.
    Mathew, HSIGP

         This works on non editable combo boxes
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class ComboBoxAction extends JFrame implements ActionListener
         JComboBox comboBox;
         public ComboBoxAction()
              comboBox = new JComboBox();
              comboBox.addActionListener( this );
              comboBox.addItem( "Item 1" );
              comboBox.addItem( "Item 2" );
              comboBox.addItem( "Item 3" );
              comboBox.addItem( "Item 4" );
              //  This prevents action events from being fired when the
              //  up/down arrow keys are used on the dropdown menu
              comboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
              getContentPane().add( comboBox );
         public void actionPerformed(ActionEvent e)
              System.out.println( comboBox.getSelectedItem() );
              //  make sure popup is closed when 'isTableCellEditor' is used
              comboBox.hidePopup();
         public static void main(String[] args)
              final ComboBoxAction frame = new ComboBoxAction();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible( true );
    }

  • JComboBox Render Problem........

    Hi I have a problem in JCombox renderer in my application Problem is i have Three comboBox columns in my table wing same Renderer and Editor. second and third combo column's aree working fine But in first combo-column if i add a new row clicking add button and if change a value in top- most comboBox i will reflect in all ComboBox's below, this is not happening in othe two Combo-column. i'am not at all gettin why this happens where i am using same renderer for all combo-columns how to stop this, When a new row is add ComboBox first item as Selected,
    Can any one please tell me how to solve this,
    since i cannot past entair application i am pasting example with similar suituation using same renderer.
    Thank's in Advance
    CODE:-
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.DefaultCellEditor;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableCellRenderer;
    import javax.swing.table.TableColumn;
    * @author 501376972
    public class MainTable extends JFrame{
    DefaultTableModel model = null;
    JTable table = null;
    JScrollPane scrollpane = null;
    JButton btCancel = null;
    JButton btADD = null;
    JPanel panelButton = null;
    public Object[][] data = null;
    String column[] = {" ","A","B","C","D","E","F"};
    String oprator[] = {" ","=","/","*","-","+"};
    String number[] = {" ","1","2","3","4","5","6"};
    /** Creates a new instance of MainTable */
    public MainTable() {
    model = new DefaultTableModel();
    model.addColumn("Column");
    model.addColumn("Operator");
    model.addColumn("Value");
    model.addColumn("Number");
    table = new JTable();
    table.setModel(model);
    data = new Object[][]{
    {column, oprator, null, number}
    model.addRow(data);
    TableColumn colCol = table.getColumnModel().getColumn(0);
    colCol.setCellRenderer(new ComboBoxCellRenderer(column));
    colCol.setCellEditor(new ComboBoxCellEditor(column));
    TableColumn colOpr = table.getColumnModel().getColumn(1);
    colOpr.setCellRenderer(new ComboBoxCellRenderer(oprator));
    colOpr.setCellEditor(new ComboBoxCellEditor(oprator));
    TableColumn colLog = table.getColumnModel().getColumn(3);
    colLog.setCellRenderer(new ComboBoxCellRenderer(number));
    colLog.setCellEditor(new ComboBoxCellEditor(number));
    scrollpane = new JScrollPane(table);
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(scrollpane,BorderLayout.CENTER);
    panelButton = new JPanel();
    btADD = new JButton("ADD");
    btCancel = new JButton("Cancel");
    panelButton.add(btADD);
    panelButton.add(btCancel);
    getContentPane().add(panelButton,BorderLayout.SOUTH);
    btCancel.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
    dispose();
    btADD.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
    model.addRow(data);
    getContentPane().add(scrollpane);
    setSize(500,500);
    class ComboBoxCellRenderer extends JComboBox implements TableCellRenderer {
    public ComboBoxCellRenderer(String[] items) {
    super(items);
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    if (isSelected) {
    //DO NOTHIING
    } else {
    //DO NOTHIING
    // Select the current value
    if(value == null)
    setSelectedIndex(0);
    else
    setSelectedItem(value);
    return this;
    public class ComboBoxCellEditor extends DefaultCellEditor {
    public ComboBoxCellEditor(String[] items) {
    super(new JComboBox(items));
    * @param args the command line arguments
    public static void main(String[] args) {
    MainTable mt = new MainTable();
    mt.setVisible(true);
    }

    Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the posted code retains its original formatting.
    Don't know why the code works the way it does, but the code is wrong. The correct way to add a row is like this:
    //model.addRow(data);
    String[] rowData = { " ", " ", " ", " "};
    model.addRow(rowData);

  • JComboBox MouseListener Problem

    Hi!
    I have problem in getting mouseEntered event from a JComboBox. I have registered a MouseListener with it but it doesn't fire any mouseEvent. Anyone has any idea how to get the mouseEntered Event fired from a JComboBox??
    Thanks!!

    Even I, have a similar problem. My obejective is to display the tooltip, When I move the mouse over every individual item in the combo box. The combo basically has a JList. So, I overrided the getListCellRenderer(...) method. It is not displaying the toolTip when the combo initially has no selectedItem. If there is a selected item, the first time itslef, it displays the toolTip. If theres no selectedItem, it displays the toolTip when I move the mouse out of the combo(when the combo is expanded). Tried all possible combinations... but doesnt work. Have set the toolTip with setToolTipText() method... and when I print the toolTip with getToolTipText() method. It prints correctly, but isnt getting displayed.. :-(

  • JComboBox event ItemChanged is called repeatedly

    Hi all,
    I've got an JApplet with 2 JComboBoxes. The first both of them are added to ItemListener.
    When a entry of the first ComboBox is selected I delete
    the contents of the second one and add other contents.
    (I have to do so)
    The problem :
    The itemStateChanged event occurs of Combo2 occurs
    after itemStateChanged of Combo1 and vice versa multiple times.
    How can I avoid this. When I select an item from combo1
    only this event should occure. When I select an item from combo2 only this event should occure.
    public void itemStateChanged(ItemEvent ie) {
          String sName = (String)ie.getItem();
          if(ie.getSource() == ((CQdbl_Beanstandung)m_appletParent).jchoBereich) {
             if(ie.getStateChange() == ItemEvent.SELECTED) {
                //department BML-V1  and BML-V2 have the same masks
                if(sName.compareTo("BML-V2") == 0) {
                   ((CQdbl_Beanstandung)m_appletParent).setBmlv2();
                } else  if(sName.compareTo("BML-V1/WE") == 0) {
                   ((CQdbl_Beanstandung)m_appletParent).setBmlv1we();
                } else  if(sName.compareTo("BML-V1/WA") == 0) {
                   ((CQdbl_Beanstandung)m_appletParent).setBmlv1wa();
                //get new form contents
                ((CQdbl_Beanstandung)m_appletParent).refreshForm();
          } else if(ie.getSource() == ((CQdbl_Beanstandung)m_appletParent).jchoVerursacher) {
             if(ie.getStateChange() == ItemEvent.SELECTED) {
                ((CQdbl_Beanstandung)m_appletParent).setKst();

    make a variable itemStateThatOughtToBe
    in your ItemListenrer first ask if the current itemstate is istemStateThatOughtToBe. if return else execute your normal code.
    If you don't want the itemlistener to become active with this particualr change first set ItemStateTahtOughttoBe and then change the item

  • JComboBox Event help

    sir
    i have three JComboBoxes .
    firstcombobox will be loaded on start up .
    basing on the First combobox item selected the second combo box is filled up.
    basing on the second the third one will be filled up.
    based on the third combobox the text feild beside it should be locked or unlocked
    i have the problem with the comboboxes events in which events i have to write all the three please help me

    in the following link there is a code example it will help u and u have to make combobox model to all stuff
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=688505

  • Events problem with (Java and ActiveX)

    Hi,
    I use an ActiveX component with Java and i've got a problem with events.
    Java classes were generated with Bridge2Java (IBM).
    In order to manage events I added a listener in my application :
         javaMyActiveX = new MyActiveX();
         javaMyActiveX.add_DMyActiveXEventsListener(new _DMyActiveXEventsAdapter());
    I also added a constructor in the _DMyActiveXEventsAdapter class and I fill the body of methods.
    The ActiveX generates two types of events :
    - The ones are directly generated by methods.
    - The others are generated by a thread.
    With MS Products (VB, Visual C++, Visual J++), I catch all events.
    With java (jdk 1.4), I catch only events generated by methods.
    Can anyone help me.

    I'm not 100% sure, but the last time I used that bridge, it only worked if you ran your Java app within a Microsoft VM.

  • Help needed with Image Events problem

    Hi there I'm writing what I thought was a simple script to convert a folder full of images from jpg to tiff. But the script fails when trying to convert the first image in the folder. Instead of converting the image, Preview opens with the image shown and I get this error message: error "The variable ImageRef is not defined." number -2753 from "ImageRef".
    I have seen some posts about other people having the same problem, but I haven't seen any solutions.
    Here's the script.
    on run
    tell application "Finder"
    set PicturesFolder to ((path to home folder) as string) & "Pictures:SenseCam" as alias
    set Photographs to (get entire contents of PicturesFolder) as alias list
    end tell
    tell application "Image Events"
    launch
    repeat with Photo in Photographs
    if (Photo as string) ends with "jpg" then
    set ImageRef to open Photo
    save ImageRef in Photographs as TIFF
    close ImageRef
    end if
    end repeat
    end tell
    tell application "Finder"
    repeat with Photo in Photographs
    delete Photo
    end repeat
    end tell
    end run
    Thanks in advance for any help.
    John

    Hello
    You may try something like the modified code below.
    Noticiable changes :
    #1 - Removed the parentheses. Your original code won't yield alias list but a list of finder objects, which is the reason why Preview opens the image. (The statment 'open finderObject' behaves the same as double clicking it in Finder)
    #2 - Only delete the original jpeg files which are converted to tiff.
    #3 - Build new path for converted image.
    #4 - Save in new path. (When saving image in a format other than its original format, always save the image to a new file and do not attempt to overwrite the source file.)
    cf.
    http://www.macosxautomation.com/applescript/imageevents/08.html
    on run
    tell application "Finder"
    set PicturesFolder to (path to home folder as string) & "Pictures:SenseCam:" as alias
    set Photographs to get entire contents of PicturesFolder as alias list -- #1
    end tell
    set DonePhotos to {} -- #2
    tell application "Image Events"
    launch
    repeat with Photo in Photographs
    set Photo to Photo's contents
    set oldPath to Photo as string
    if oldPath ends with ".jpg" then
    set newPath to oldPath's text 1 thru -5 & ".tif" -- #3
    set ImageRef to open Photo
    save ImageRef as TIFF in newPath -- #4
    close ImageRef
    set end of DonePhotos to Photo -- #2
    end if
    end repeat
    end tell
    tell application "Finder"
    delete DonePhotos -- #2
    end tell
    end run
    Hope this may help,
    H

  • ICal all-day event problem

    iCal on my iPad worked fine for a while. Now, many of my all day events (but not all of them) are showing up a day early on my iPad on week view. Everything is fine on all other devices (iPhone, MacBook) and all is fine on iPad on day, month and list view. All timed events are in the right place. But all day events in week view are a disaster and turning off the iPad isn't helping. Any advice?

    Did you travel out of your home time zone and first notice the problem then? I spent an hour and a half on the phone with Apple Care while I was in the Central zone (I live in Eastern) and nothing the supervisor suggested worked (deleting the account, resetting, turning ipad off, etc). They'd bumped me up to a supervisor because the regular guy had no idea. Supervisor said no one on the internal tech board had seen that particular problem. The final assumption was it was a software glitch on my ipad--the advice was a complete restore which was going to have to wait until I returned home because he said it would take too long over the Verizon mi-fi I was using while traveling. Anyway--I got home to Eastern time, immediately pulled out the ipad to do the restore and all the all-day events were in the right place and have remained in the right place since then. My best guess is that it's a time zone issue but it doesn't make much sense. All my timed events stayed right where they were supposed to be the whole time (time zone support turned off).

Maybe you are looking for

  • Regarding issues connecting to EJB 2 from OSB

    Hi, I am trying to connect from OSB 11g to EJB 2 which is deployed on weblogic 7.1. I am getting this error. <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <soapenv:Fault> <faultcode>soapenv:Server</faultc

  • Having trouble getting audiobooks onto iPod Touch

    I've tried troubleshooting this for my mom to no avail... We've found them in the iPod tab on iTunes -- they are all there, and she's able to check the box to Sync to her iPod, but nothing. She's got enough capacity... we've even tried moving them to

  • Mini-player with 'Rating' and 'Next' controls?

    iTunes 10.6.3.25 on Win 7. Is there a way that I can get a smaller player window that would still give me immediate access to the 'Rating' buttons and also allow me to easily do a 'Next' to get to the next song in the Playlist? Thanks!

  • Re install i tunes in mac but i cant

    when i try install the new version the I tunes ,i dont know what happen with my computer? i try erase the i tunes in mac but i can't & know i can't open i tunes what can i do please somebody help me? and know i can't make download new software for ip

  • Resizing Images in InDesign CS5

    Hi, I jumped from CS3 to CS5. In CS5, when I resize images they enlarge or decrease from the center and no longer resize from where my curser pulls from.  Is there a setting that I can change for the image to resize from my curser and not the middle