Events on jcombobox

in a metal look and feel the following events does not work<p>
on a JComboBox<p>
action event,itemlistener,focuslistener,keyevents<p>
how can i apply these events?in a metal look and feel.

If you are running on windows, use this code. I had just attached a piece of code to run in Windows look and feel. Here it works fine once you double click and then click in the editable area. Just wondering why it's not working with Java Look and Feel.
import javax.swing.*;
import java.awt.event.MouseListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class M extends JFrame
JComboBox combo;
public M()
combo = new JComboBox();
combo.addMouseListener(new MouseAdapter()
public void mouseClicked(MouseEvent e)
System.out.println(e.getClickCount());
if(e.getClickCount() == 2)
combo.setEditable(true);
getContentPane().add(combo);
pack();
setVisible(true);
public static void main(String a[])
try
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
catch(Exception ex)
ex.printStackTrace();
new M();
Thanks,
Kalyan

Similar Messages

  • PopupMenuListener event on JComboBox fires multiple times per selection

              // webAddressBox IS OF TYPE javax.swing.JComboBox
               webAddressBox.addPopupMenuListener(new PopupMenuAdapter() {
                    /** @uses {@link com.ppowell.tools.ObjectTools.SimpleBrowser.Surf} */
                    final Surf surf = new Surf(webAddressBox.getSelectedItem().toString());
                     * Perform {@link #surf} processing
                     * @param evt {@link javax.swing.event.PopupMenuEvent}
                    public void popupMenuWillBecomeInvisible(PopupMenuEvent evt) {
                        System.out.println("you selected:");
                        surf.doURLProcessing();
    * PopupMenuAdapter.java
    * Created on February 16, 2007, 11:53 AM
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package com.ppowell.tools.ObjectTools.SwingTools;
    import javax.swing.event.PopupMenuEvent;
    import javax.swing.event.PopupMenuListener;
    * Will allow for greater flexibility by implementing {@link javax.swing.event.PopupMenuListener}
    * @author Phil Powell
    * @version JDK 1.6.0
    public abstract class PopupMenuAdapter implements PopupMenuListener {
        /** Creates a new instance of PopupMenuAdapter */
        public PopupMenuAdapter() {}
         * Overrides {@link javax.swing.event.PopupMenuListener} method popupMenuCanceled
         * @param evt {@link javax.swing.event.PopupMenuEvent}
        public void popupMenuCanceled(PopupMenuEvent evt) {}
         * Overrides {@link javax.swing.event.PopupMenuListener} method popupMenuWillBecomeInvisible
         * @param evt {@link javax.swing.event.PopupMenuEvent}
        public void popupMenuWillBecomeInvisible(PopupMenuEvent evt) {}
         * Overrides {@link javax.swing.event.PopupMenuListener} method popupMenuWillBecomeVisible
         * @param evt {@link javax.swing.event.PopupMenuEvent}
        public void popupMenuWillBecomeVisible(PopupMenuEvent evt) {}
    }This code is supposed to handle a single selection from a JComboBox webAddressBox. The front-end functionality of this code blocks works just fine to the user, however, upon viewing the "behind the scenes action", I noticed that the overriden popupMenuWillBecomeInvisible() method within the anonymous inner class instance of PopupAdapter is being called 2 times upon the first time you select something from webAddressBox, 4 times the next time you select something, 8 times the next time, and so on..
    Obviously this is a tremendous waste of resources to have it call that many times exponentially - it should only call once each time you select something from webAddressBox, but I can't figure out how to get that to happen.
    What suggestions might you have to accomplish this? I already have an ActionListener that runs separately from PopupMenuAdapter that handles the user either clicking a JButton or hitting ENTER - this works just fine.
    Thanx
    Phil

    is being called 2 times upon the first time youselect something from
    webAddressBox, 4 times the next time you selectsomething, 8 times the next time, and so on..
    Then you are adding the listener to the component
    multiple times.WTO sigh.. thanx! :)

  • Programatic item events in JComboBox

    I have three JComboBoxes. Each has an ItemListener which calls setCustomerFields.
    public void setCustomerFields(ItemEvent e)
    JComboBox aComboBox = (JComboBox) e.getSource();
    int aIndex = aComboBox.getSelectedIndex();
    myAddressComboBox.setSelectedIndex(aIndex);
    myCustNameComboBox.setSelectedIndex(aIndex);
    myCustNumComboBox.setSelectedIndex(aIndex);
    Each JComboBox looks something like:
    myAddressComboBox = new JComboBox(myAddresses);
    myAddressComboBox.setEditable(true);
    myAddressComboBox.addItemListener(new ItemListener() {
    public void itemStateChanged(ItemEvent e) {
    setCustomerFields(e); } } );
    The purpose is to have all three JCombBoxes stay in sync. When the user selects a value in one setCustomerFields will set the value in the others. The API documentation for JComboBox.addItemListener states addItemListener Specified by: addItemListener in interface ItemSelectable. ItemSelectable Method Details for addItemListener says "Adds a listener to receive item events when the state of an item is changed by the user. Item events are not sent when an item's state is set programmatically. If l is null, no exception is thrown and no action is performed."
    This tells me that "item events are not sent when an item's state is set programmatically." So calling setSelectedIndex in setCustomerFIields should not send an Iterm event. BUT IT IS. And thus I get an endless loop.
    My work around is to call removeItermListener in setCustomerFields.
    I have looked through the forum and found some similar questions but no definitive answer (except call removeItemListener) Also I see reference to a bug http://developer.java.sun.com/developer/bugParade/bugs/4664606.html which is similar but not directly related.
    So my questions:
    1) Am I using ItemListener correctly?
    2) If so why is the Item Event occurring in setCustomerField?
    3) Is the documentation wrong?
    4) I choice ItemListener over ActionListener because ItemListener "isn't" supposed to fire when the state changes programatically. Was that the correct choice?
    Thanks
    Brad

    ItemEvent should send when ever setSelectedIndex call, but you can do one thing :
    public void itemStateChanged(ItemEvent e) {
    if( e.getStateChange() == ItemEvent.SELECTED ){
    setCustomerFields(e); }
    may be this will work from your situation, or i guess you can use some flags type too for checking which one combobox changed then do appropriate action for this.

  • MouseEntered event and JComboBox

    I have a status area on a JInternalFrame. I can send text to it from a JTextField by using the mouseEntered method. How can I send text from a JComboBox. It doesn't seem to recognize the mouseEntered event.

    This is a litle bit trickier. Your combobox elements must be objects that are listening to mouse motion

  • Events and jComboBox

    //I wounder how the jComboBox works.
    //First I add items to the combobox:
    for(i=0;i<10;i++){
         jComboBox1.addItem("Name " + i);
    jComboBox1.setSelectedIndex(-1);
    //So far, so good.
    //Now I want to print out the name that the user has selected from the combobox.
    void jCboNamn_actionPerformed(ActionEvent e) {
    //Print selected name
    System.out.println(jCboNamn.getSelectedItem());
    //The problem is that this event fires when:
    //     1) I fill the combobox with the first item
    //     2) I make no item selected
    //Is there another event I should use??
    //Thanks for helping =)

    I cant get the combo to work as planned. I wish to use System.out.println() to print the name which the user has selected from the combobox (the same moment as when the user select the item in the combobox). I have tried to implement the itemListener (if thats the proper way to solve the problem..) without success. I'm grateful for any kind of help.
    package testproj;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class CFrame1 extends JFrame {
    JPanel contentPane;
    BorderLayout borderLayout1 = new BorderLayout();
    JPanel jPanel1 = new JPanel();
    JComboBox jComboBox1 = new JComboBox();
    //Construct the frame
    public CFrame1() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    int i=1;
    for(i=1;i<11;i++){
    jComboBox1.addItem("Namn " +i);
    jComboBox1.setSelectedIndex(-1);
    //Component initialization
    private void jbInit() throws Exception {
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(borderLayout1);
    this.setSize(new Dimension(400, 300));
    this.setTitle("Learning Java");
    jPanel1.setLayout(null);
    jComboBox1.setBackground(Color.white);
    jComboBox1.setBounds(new Rectangle(57, 33, 286, 21));
    contentPane.add(jPanel1, BorderLayout.CENTER);
    jPanel1.add(jComboBox1, null);
    //Overridden so we can exit when window is closed
    protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
    System.exit(0);

  • How to handle editing events in a JComboBox

    I have a editable JComboBox. User can select value either using the drop-down box or by editing.
    I am able to get the drop-down selct event. However, I am not sure how should I handle the edit event on JComboBox.
    Particularly, here is the use-case I wish to handle.
    User edited the JComboBox by clicking back space key. I want to fire an event once user is done editing. How can I find if user is done editing ?

    User, please always tell us your jdev version.
    In general you use a valueChangeListener which is fired when the user tabs out of the field...
    Timo

  • JComboBox fires an event only after changed selection?!

    I have added a JComboBox to my application, combined with an ActionListener which is added to the combobox just after initialization. It works fine, but there is one problem left:
    Generally, an event for the ActionListener is initially only fired by a combobox, if the user selects a different item than the last selected one. But I need an event that is fired by the combobox each time an item will be selected, even if it is the same item as the last selected one.
    I tried to use an ItemChangeListener, but it gave no success (and sense), it fires an event each time the user wants to select an item from the combobox' item list, that is no solution.
    Best way to solve this problem? I thought about a adding a MouseListener, but that might be the longest way. There seems to be no special method in JComboBox class to set this desired property?
    Any suggestions?

    Hello,
    thank you for your answer so far. Well, here is a trivial source code with the problem that still exists (see also my text at the end of this post). This one has been tested using Java 2 SDK V1.4, even using the newest SDK version did not change anything on the behaviour:
    import javax.swing.*;
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    * JComboBox-Test: using Java 2 SDK V1.4, ActionEvent is only fired by combobox, if
    * a different item than the previous one is selected from combobox;
    public class Forum3 extends JFrame implements ActionListener {
        String[] CB_ITEMS = {
            "item 1",
            "item 2",
            "item 3",
        public Forum3 () {
            super();
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setLayout(new FlowLayout());
            JComboBox cb = new JComboBox(CB_ITEMS);
            cb.addActionListener(this);
            getContentPane().add(cb);
        public void actionPerformed (ActionEvent e) {
            System.out.println("action!");
        public static void main (String[] argv) {
            Forum3 test = new Forum3();
            test.setSize(300,200);
            test.setVisible(true);
    }If you start this program (I am also using Windows XP), you see the JFrame window including the JComboBox. "item 1" is selected by default. If you click again on "item 1", no event will be fired. An event will be fired only, if you choose "item 2" or "item 3". You can try this with any other of the given items. An event will be only fired, if you choose a different item than the last one.
    What I need, is a routine that fires an event each time any item is selected!
    I would be grateful for a helpful hint, how to solve this in a "clean" way :-)

  • Event Handler for a JComboBox in JTable

    Hi,
    I am using a JTable with one column having JComboBox as CellEditor, I Want to handle event for jcomboBox such that if I am selecting any item from JcomboBox item , i check if there is any field before that in the Jtable Cell if yes then I am setting it to null or the previous value. I have implemented CellEditorListener to it but it is not working fine, so if anyone can please help me out..

    If I read you right, you want to use a multiple keystroke combo box as an editor in a JTable?
    If you create the JComboBox as you would like it and then install it as an editor in the column(s) JTable the editor will work like the JComboBox
    Example:
    //- you would have that keyselection Manager class
    // This key selection manager will handle selections based on multiple keys.
    class MyKeySelectionManager implements JComboBox.KeySelectionManager {    ....    };
    //- Create the JComboBox with the multiple keystroke ability
    //- Create a read-only combobox
    String[] items = {"Ant", "Ape", "Bat", "Boa", "Cat", "Cow"};
    JComboBox cboBox = new JComboBox(items);
    // Install the custom key selection manager
    cboBox.setKeySelectionManager(new MyKeySelectionManager());
    //- combo box editor for the JTable
    DefaultCellEditor cboBoxCellEditor = new DefaultCellEditor(cboBox);
    //- set the editor to the specified COlumn in the JTable - for example the first column (0)
    tcm.getColumn(0).setCellEditor(cboBoxCellEditor); Finally, it may be necessary to to put a KeyPressed listener for the Tab key, and if you enter the column that has the JComboBox:
    1) start the editting
    table.editCellAt(row, col);2) get the editor component and cast it into a JComboBox (in this case)
    Component comp = table.getEditorComponent();
    JComboBox cboComp = (JComboBox) comp;3) give this compent the foucus to do its deed     
    cboComp.requestFocus();Hope this helps!
    dd

  • Adding an event listener to combo box

    I am working on a mortgage calculator and I cannot figure out how to add an event listener to a combo box.
    I want to get the mortgage term and interest rate to calucate the mortgage using the combo cox. Here is my program.
    Modify the mortgage program to allow the user to input the amount of a mortgage
    and then select from a menu of mortgage loans: 7 year at 5.35%, 15 year at 5.50%, and
    30 year at 5.75%. Use an array for the different loans. Display the mortgage payment
    amount. Then, list the loan balance and interest paid for each payment over the term
    of the loan. Allow the user to loop back and enter a new amount and make a new
    selection, with resulting new values. Allow user to exit if running as an application
    (can't do that for an applet though).
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.text.NumberFormat;
    import java.util.Locale;
    //creates class MortgageCalculator
    public class MortgageCalculator extends JFrame implements ActionListener {
    //creates title for calculator
         JPanel row = new JPanel();
         JLabel mortgageCalculator = new JLabel("MORTGAGE CALCULATOR", JLabel.CENTER);
    //creates labels and text fields for amount entered          
         JPanel firstRow = new JPanel(new GridLayout(3,1,1,1));
         JLabel mortgageLabel = new JLabel("Mortgage Payment $", JLabel.LEFT);
         JTextField mortgageAmount = new JTextField(10);
         JPanel secondRow = new JPanel();
         JLabel termLabel = new JLabel("Mortgage Term/Interest Rate", JLabel.LEFT);
         String[] term = {"7", "15", "30"};
         JComboBox mortgageTerm = new JComboBox(term);
         JPanel thirdRow = new JPanel();
         JLabel interestLabel = new JLabel("Interest Rate (%)", JLabel.LEFT);
         String[] interest = {"5.35", "5.50", "5.75"};
         JComboBox interestRate = new JComboBox(interest);
         JPanel fourthRow = new JPanel(new GridLayout(3, 2, 10, 10));
         JLabel paymentLabel = new JLabel("Monthly Payment $", JLabel.LEFT);
         JTextField monthlyPayment = new JTextField(10);
    //create buttons to calculate payment and clear fields
         JPanel fifthRow = new JPanel(new GridLayout(3, 2, 1, 1));
         JButton calculateButton = new JButton("CALCULATE PAYMENT");
         JButton clearButton = new JButton("CLEAR");
         JButton exitButton = new JButton("EXIT");
    //Display area
         JPanel sixthRow = new JPanel(new GridLayout(2, 2, 10, 10));
         JLabel displayArea = new JLabel(" ", JLabel.LEFT);
         JTextArea textarea = new JTextArea(" ", 8, 50);
    public MortgageCalculator() {
         super("Mortgage Calculator");                     //title of frame
         setSize(550, 350);                                             //size of frame
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         Container pane = getContentPane();
         GridLayout grid = new GridLayout(7, 3, 10, 10);
         pane.setLayout(grid);
         pane.add(row);
         pane.add(mortgageCalculator);
         pane.add(firstRow);
         pane.add(mortgageLabel);
         pane.add(mortgageAmount);
         pane.add(secondRow);
         pane.add(termLabel);
         pane.add(mortgageTerm);
         pane.add(thirdRow);
         pane.add(interestLabel);
         pane.add(interestRate);
         pane.add(fourthRow);
         pane.add(paymentLabel);
         pane.add(monthlyPayment);
         monthlyPayment.setEnabled(false);
         pane.add(fifthRow);
         pane.add(calculateButton);
         pane.add(clearButton);
         pane.add(exitButton);
         pane.add(sixthRow);
         pane.add(textarea); //adds texaarea to frame
         pane.add(displayArea);
         setContentPane(pane);
         setVisible(true);
         //Adds Listener to buttons
         calculateButton.addActionListener(this);
         clearButton.addActionListener(this);
         exitButton.addActionListener(this);
         mortgageTerm.addActionListener(this);
         interestRate.addActionListener(this);
    public void actionPerformed(ActionEvent event) { 
         Object command = event.getSource();
         JComboBox mortgageTerm = (JComboBox)event.getSource();
         String termYear = (String)mortgageTerm.getSelectedItem();
    if (command == calculateButton) //calculates mortgage payment
         int year = Integer.parseInt(mortgageTerm.getText());
         double rate = new Double(interestRate.getText()).doubleValue();
         double mortgage = new Double(mortgageAmount.getText()).doubleValue();
         double interest = rate /100.0 / 12.0;
         double monthly = mortgage *(interest/(1-Math.pow(interest+1,-12.0 * year)));
                   NumberFormat myCurrencyFormatter;
                   myCurrencyFormatter = NumberFormat.getCurrencyInstance(Locale.US);
                   monthlyPayment.setText(myCurrencyFormatter.format(monthly));
         if(command == clearButton) //clears all text fields
                   mortgageAmount.setText(null);
                   //mortgageTerm.setText(null);
                   //interestRate.setText(null);
                   monthlyPayment.setText(null);
              if(command == exitButton) //sets exit button
                        System.exit(0);
         public static void main(String[] arguments) {
              MortgageCalculator mor = new MortgageCalculator();

    The OP already did this to both JComboBoxes.
    mochatay, here is a new actionPerformed method for you to use.
    I've improved a few things here and there...
    1) You can't just cast the ActionEvent's source into a JComboBox!
    What if it was a JButton that fired the event? Then you would get ClassCastExceptions (I'm sure you did)
    So check for all options, what the source of the ActionEvent actually was...
    2) You can't assume the user will always type in valid data.
    So enclose the Integer and Double parse methods in try-catch brakcets.
    Then you can do something when you know that the user has entered invalid input
    (like tell him/her what a clumsy idiot they are !)
    3) As soon as user presses an item in any JComboBox, just re-calculate.
    I did this here by programmatically clicking the 'Calculate' button.
    Alternatively, you could have a 'calculate' method, which does everything inside the
    if(command==calculateButton) if-block.
    This will be called when:
    a)calculateButton is pressed
    b)when either of the JComboBoxes are pressed.
    public void actionPerformed (ActionEvent event)
            Object command = event.getSource ();
            if (command == calculateButton) //calculates mortgage payment
                int year = 0;
                double rate = 0;
                double mortgage = 0;
                double interest = 0;
                /* If user has input invalid data, tell him so
                and return (Exit from this method back to where we were before */
                try
                    year = Integer.parseInt (mortgageTerm.getSelectedItem ().toString ());
                    rate = new Double (interestRate.getSelectedItem ().toString ()).doubleValue ();
                    mortgage = new Double (mortgageAmount.getText ()).doubleValue ();
                    interest = rate / 100.0 / 12.0;
                catch (NumberFormatException nfe)
                    /* Display a message Dialogue box with a message */
                    JOptionPane.showMessageDialog (this, "Error! Invalid input!");
                    return;
                double monthly = mortgage * (interest / (1 - Math.pow (interest + 1, -12.0 * year)));
                NumberFormat myCurrencyFormatter;
                myCurrencyFormatter = NumberFormat.getCurrencyInstance (Locale.US);
                monthlyPayment.setText (myCurrencyFormatter.format (monthly));
            else if (command == clearButton) //clears all text fields
                /* Better than setting it to null (I think) */
                mortgageAmount.setText ("");
                //mortgageTerm.setText(null);
                //interestRate.setText(null);
                monthlyPayment.setText ("");
            else if (command == exitButton) //sets exit button
                System.exit (0);
            else if (command == mortgageTerm)
                /* Programmatically 'clicks' the button,
                As is user had clicked it */
                calculateButton.doClick ();
            else if (command == interestRate)
                calculateButton.doClick ();
            //JComboBox mortgageTerm = (JComboBox) event.getSource ();
            //String termYear = (String) mortgageTerm.getSelectedItem ();
        }Hope this solves your problems.
    I also hope you'll be able to learn from what I've indicated, so you can use similar things yourself
    in future!
    Regards,
    lutha

  • Setting default value for a jcombobox based on the value not the index

    I am trying to set the default value for my combobox to the current year. One way I thought of doing it was to get the index of the value representing the current year and then use setSelectedInex to make it the default. Any ideas?
    The relevent section of code is below.
    GregorianCalendar gregorianCalendar = new GregorianCalendar();
    int year = gregorianCalendar.get(Calendar.YEAR);
    String currentyear = year + "";
    int startyears = 2000;
    int numyears = 25;
    JComboBox endyearcombobox = new JComboBox();
    endyearcombobox.setBorder( BorderFactory.createLineBorder(Color.DARK_GRAY));
    endyearcombobox.setFont(standardfont);
    endyearcombobox.addActionListener( new ActionListener() {
    public void actionPerformed( ActionEvent event ) {
    endyearcombobox = ( JComboBox )event.getSource();
    endyear = endyearcombobox.getSelectedItem();
    boolean same = endyear.equals(oldItem);
    oldItem = endyear;
    String[] endyearlist = new String[numyears];
    for(int i = startyears; i < startyears+numyears; i++){
    String item = new Integer(i).toString();
    endyearcombobox.addItem(item);
    Thanks
    Ged

    Thanks mate,
    That was what I was looking for. I still had a little more manipulation to do, but sent me on the right track and have got it working now. I don't know why I didn't think of it in the first place.
    Ged

  • Handling events in combo box

    Hello,
    I'm very much confused about the handling events of JComboBox with ActionListener and ItemListener. Both are seemed similar to me. If anyone can explain me the differences, it would be helpful for me. Thanks everybody.

    ActionEvents are fired each time any item is selected, ItemEvents are only fired, if the selection changes.

  • JComboBox focusLost sets Transaction dirty

    A JComboBox bound to a ViewObject in an ApplicationModule sets that ApplicationModule's transaction dirty even if no changes were made. The combobox list wasn't even opened, just focus in and out or tab-in and tab-out.
    This seems to be a side-effect of having a different column displayed to that bound to the JComboBox.
    This binding works correctly (VcVehicleRegistration is the bound column and the displayed column):
    mVcVehicleRegistration.setModel(JUComboBoxBinding.createLovBinding(panelBinding, mVcVehicleRegistration, "VehicleIncidents", null, "VehicleIncidentsIter", new String[] {"VcVehicleRegistration"}, "VehicleView", new String[] {"VcVehicleRegistration"}, new String[] {"VcVehicleRegistration"}, null, null));
    whereas this fails (VcCauseCode is the bound column, but VcDescription is displayed):
    mVcCauseCode.setModel(JUComboBoxBinding.createLovBinding(panelBinding, mVcCauseCode, "VehicleIncidents", null, "VehicleIncidentsIter", new String[] {"VcCauseCode"}, "CauseView", new String[] {"VcCauseCode"}, new String[] {"VcDescription"}, null, null));
    Tony.

    I'm doing more-or-less what you did.
    I've just reproduced it with a simple panel.
    Panel already exists with 5 attributes from a single ViewOject (which are from a single EntityObject) - PersonnelView.
    This operates fine and tabbing-through has no problems.
    Drop in a ComboBox and bind it to the Branch ViewObject (also single Entity) and display the Branch name:
    jComboBox1.setModel(JUComboBoxBinding.createLovBinding(panelBinding, jComboBox1, "PersonnelView", null, "PersonnelViewIter", new String[] {"VcBranch"}, "BranchView", new String[] {"VcBranch"}, new String[] {"VcBranchName"}, null, null));
    Tabbing out of this field sets transaction dirty.
    How can I check I really am using C:\JDeveloper\BC4J\jlib\FixForBug2632152.jar?
    I can e-mail the relevant SQL, BusinessComponents XML and JClient.java if you like.
    In the mean-time, I've sub-classed JUNavigationBar and dumped the stack when transactionStateChanged() is called (see below).
    Tony.
    java.lang.Exception: Stack trace
         void java.lang.Thread.dumpStack()
              Thread.java:997
         void com.lynx.cc.NavBar.transactionStateChanged(boolean)
              NavBar.java:106
         void oracle.jbo.uicli.binding.JUApplication.setTransactionModified()
              JUApplication.java:860
         void oracle.jbo.uicli.jui.JUPanelBinding.callBeforeSetAttribute(oracle.jbo.uicli.binding.JUControlBinding, oracle.jbo.Row, oracle.jbo.AttributeDef, java.lang.Object)
              JUPanelBinding.java:481
         void oracle.jbo.uicli.binding.JUCtrlValueBinding.setAttributeInRow(oracle.jbo.Row, oracle.jbo.AttributeDef, java.lang.Object, boolean)
              JUCtrlValueBinding.java:466
         void oracle.jbo.uicli.binding.JUCtrlValueBinding.setAttributeInRow(oracle.jbo.Row, oracle.jbo.AttributeDef, java.lang.Object)
              JUCtrlValueBinding.java:422
         void oracle.jbo.uicli.binding.JUCtrlListBinding.setTargetAttrsFromLovRow(oracle.jbo.Row, oracle.jbo.Row)
              JUCtrlListBinding.java:678
         void oracle.jbo.uicli.binding.JUCtrlListBinding.updateTargetFromSelectedValue(java.lang.Object)
              JUCtrlListBinding.java:748
         void oracle.jbo.uicli.jui.JUComboBoxBinding.actionPerformed(java.awt.event.ActionEvent)
              JUComboBoxBinding.java:430
         void javax.swing.JComboBox.fireActionEvent()
              JComboBox.java:870
         void javax.swing.JComboBox.selectedItemChanged()
              JComboBox.java:894
         void javax.swing.JComboBox.contentsChanged(javax.swing.event.ListDataEvent)
              JComboBox.java:950
         void javax.swing.AbstractListModel.fireContentsChanged(java.lang.Object, int, int)
              AbstractListModel.java:79
         void javax.swing.DefaultComboBoxModel.setSelectedItem(java.lang.Object)
              DefaultComboBoxModel.java:86
         void javax.swing.JComboBox.actionPerformed(java.awt.event.ActionEvent)
              JComboBox.java:925
         void javax.swing.plaf.basic.BasicComboBoxUI$EditorFocusListener.focusLost(java.awt.event.FocusEvent)
              BasicComboBoxUI.java:1399
         void java.awt.AWTEventMulticaster.focusLost(java.awt.event.FocusEvent)
              AWTEventMulticaster.java:171
         void java.awt.Component.processFocusEvent(java.awt.event.FocusEvent)
              Component.java:3642
         void javax.swing.JComponent.processFocusEvent(java.awt.event.FocusEvent)
              JComponent.java:1980
         void java.awt.Component.processEvent(java.awt.AWTEvent)
              Component.java:3535
         void java.awt.Container.processEvent(java.awt.AWTEvent)
              Container.java:1164
         void java.awt.Component.dispatchEventImpl(java.awt.AWTEvent)
              Component.java:2593
         void java.awt.Container.dispatchEventImpl(java.awt.AWTEvent)
              Container.java:1213
         void java.awt.Component.dispatchEvent(java.awt.AWTEvent)
              Component.java:2497
         boolean java.awt.LightweightDispatcher.setFocusRequest(java.awt.Component)
              Container.java:2076
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1335
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Container.proxyRequestFocus(java.awt.Component)
              Container.java:1330
         void java.awt.Component.requestFocus()
              Component.java:4174
         void javax.swing.JComponent.grabFocus()
              JComponent.java:915
         void javax.swing.DefaultFocusManager.focusNextComponent(java.awt.Component)
              DefaultFocusManager.java:93
         void javax.swing.DefaultFocusManager.processKeyEvent(java.awt.Component, java.awt.event.KeyEvent)
              DefaultFocusManager.java:71
         void javax.swing.JComponent.processKeyEvent(java.awt.event.KeyEvent)
              JComponent.java:2007
         void java.awt.Component.processEvent(java.awt.AWTEvent)
              Component.java:3553
         void java.awt.Container.processEvent(java.awt.AWTEvent)
              Container.java:1164
         void java.awt.Component.dispatchEventImpl(java.awt.AWTEvent)
              Component.java:2593
         void java.awt.Container.dispatchEventImpl(java.awt.AWTEvent)
              Container.java:1213
         void java.awt.Component.dispatchEvent(java.awt.AWTEvent)
              Component.java:2497
         boolean java.awt.LightweightDispatcher.processKeyEvent(java.awt.event.KeyEvent)
              Container.java:2155
         boolean java.awt.LightweightDispatcher.dispatchEvent(java.awt.AWTEvent)
              Container.java:2135
         void java.awt.Container.dispatchEventImpl(java.awt.AWTEvent)
              Container.java:1200
         void java.awt.Window.dispatchEventImpl(java.awt.AWTEvent)
              Window.java:926
         void java.awt.Component.dispatchEvent(java.awt.AWTEvent)
              Component.java:2497
         void java.awt.EventQueue.dispatchEvent(java.awt.AWTEvent)
              EventQueue.java:339
         boolean java.awt.EventDispatchThread.pumpOneEventForHierarchy(java.awt.Component)
              EventDispatchThread.java:131
         void java.awt.EventDispatchThread.pumpEventsForHierarchy(java.awt.Conditional, java.awt.Component)
              EventDispatchThread.java:98
         void java.awt.EventDispatchThread.pumpEvents(java.awt.Conditional)
              EventDispatchThread.java:93
         void java.awt.EventDispatchThread.run()
              EventDispatchThread.java:85

  • JComboBox in JTable not refresh automatically

    Hi folks,
    I put a JComboBox in a JTable cell as editor and with a GlassPane over the whole frame. Initially, I got lots of problems in dispatching events to JComboBox. Eventually, comboBox.setLightWeightPopupEnabled(false) seems solve many of them. However, after I called the said API to prevent light-weighted popup in JTable, when I move mouse on popup list or navigate with scroll bar, the UI does not refresh at all. I am pretty sure that all the models except UI has been updated because when I switch to another application and back, the UI repaints with expected appearance.
    Any idea ? Thanks a lot.!

    I think you might be doing this to yourself. This block here:
        private void tblContactFocusLost(java.awt.event.FocusEvent evt)
            if (tbl.isVisible())
                TableCellEditor tce = tbl.getCellEditor();
                if (tce != null) tce.stopCellEditing();
        }What purpose does it serve? It seems to muck up your table cell editing, including the combobox editing. If you comment out the tce.stopCellEditing() like so:
        private void tblContactFocusLost(java.awt.event.FocusEvent evt)
            if (tbl.isVisible())
                TableCellEditor tce = tbl.getCellEditor();
                if (tce != null) ; //tce.stopCellEditing();
        }Things work better.

  • 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;
    }

  • JComboBox is not opened

    Hi,
    I have a strange problem. My frame has BorderLayout - in the north I have JcomboBox, in the south I have button and the center is populated with rows of labels and textfields according the chosen item from the JComboBox.
    The problem is, that when there are more than 3 rows of labels and textfields displayed on the frame, the JComboBox is not opened.
    Has anybody faced this problem before? Any ideas what went wrong?
    Thanks, Lior

    Here is part of the code:
    public class ClarifyClient extends JPanel
    private static int m_NumOfParams = 0;
    private static String[] m_Token;
    private static JFrame jframe = new JFrame("ACM Events Builder");
    JComboBox jcombo = new JComboBox();
    Label eventLabel = new Label("Events: ");
    Label lblParam = new Label("Parameters: ");
    Button sendBtn = new Button("Send");
    Panel centerPanel = new Panel();
    Panel northPanel = new Panel(new FlowLayout());
    Panel southPanel = new Panel(new FlowLayout());
    TextField txtParamValue;
    public ClarifyClient()
    jframe.getContentPane().setLayout(new BorderLayout());
    try
    loadEventsFromFile();
    catch(Exception e)
    e.printStackTrace();
    populateComboBox();
    jcombo.setSelectedIndex(-1);
    FrameAction frameAction = new FrameAction();
              jcombo.addActionListener(frameAction);
              sendBtn.addActionListener(frameAction);
              MouseAction mouseAction = new MouseAction();
              jcombo.addMouseListener(mouseAction);
              northPanel.setLayout(new FlowLayout());
              northPanel.add(eventLabel);
    northPanel.add(jcombo);
    jframe.getContentPane().add(northPanel, "North");
    southPanel.setLayout(new FlowLayout());
    southPanel.add(sendBtn);
         jframe.getContentPane().add(southPanel, "South");
         sendBtn.setEnabled(false);
              jframe.pack();
              jframe.setSize(664, 280);
              jframe.setVisible(true);
    class FrameAction implements java.awt.event.ActionListener
         public void actionPerformed(java.awt.event.ActionEvent event)
              try
              Object object = event.getSource();
                   if (object == jcombo)
                        jcombo_actionPerformed(event);
                   else if (object == sendBtn)
                   sendBtn_actionPerformed(event);
              catch(Exception e)
              e.printStackTrace();
    void jcombo_actionPerformed(java.awt.event.ActionEvent event)
         int index = jcombo.getSelectedIndex();
         m_NumOfParams = Integer.parseInt((String)(((ArrayList)(eventDetails_V.get(index))).get(1)));
         centerPanel.removeAll();
         centerPanel.setLayout(new GridLayout(m_NumOfParams+1, 4));
         centerPanel.add(lblParam);
         centerPanel.add(new Label());
         centerPanel.add(new Label());
         centerPanel.add(new Label());
         m_Token = new String[m_NumOfParams];
         //inserting the ACM event parameters to the Panel container
         for (int i=0; i<m_NumOfParams; i++)
         txtParamValue = new TextField(20);
    Label lblName = new Label("Name: ");
    lblName.setAlignment(java.awt.Label.LEFT);
    Label lblValue = new Label("Value: ");
    lblValue.setAlignment(java.awt.Label.RIGHT);
    Label lblParamName = new Label();
    m_Token[i] = (String)((ArrayList)(eventDetails_V.get(index))).get(i+2);
         centerPanel.add(lblName);
         lblParamName.setText(m_Token);
         lblParamName.setAlignment(java.awt.Label.LEFT);
         centerPanel.add(lblParamName);
         centerPanel.add(lblValue);
         centerPanel.add(txtParamValue);
         jframe.getContentPane().remove(centerPanel);
         jframe.getContentPane().add(centerPanel, "Center");
         sendBtn.setEnabled(true);
         jframe.pack();
    public static void main(String[] args)
    ClarifyClient clfy = new ClarifyClient();

Maybe you are looking for