Sitemap

Amicuk Programming Answers

JComboBox - different behaviour in 1.3 and 1.4

-0001-11-30   Views:0

Advertisement

I have noticed that there is a difference in JCombobox behaviour in 1.3 and 1.4. I think it is better to give the program than explaining the issue. the below given program shows the difference. import javax.swing.* ; import java.awt.* ; import java.

I have noticed that there is a difference in JCombobox behaviour in 1.3 and 1.4.
I think it is better to give the program than explaining the issue.
the below given program shows the difference.
import javax.swing.* ;
import java.awt.* ;
import java.awt.event.* ;
import java.util.* ;
* Test program to show difference between
* Combo behaviour in java1.3 and 1.4
public class CTest extends JFrame
     private JComboBox combo1 ;
     private JComboBox combo2 ;
     public CTest()
          super() ;
     public void init()
     combo1 = new JComboBox() ;
          combo1.addItemListener( new ItemListener()
                    public void itemStateChanged( ItemEvent event )
                    if (null != combo1.getSelectedItem() && event.getStateChange() == ItemEvent.SELECTED)
                         loadCombo2(combo1.getSelectedIndex()+1) ;
     combo2 = new JComboBox() ;
          combo2.addItemListener( new ItemListener()
                    public void itemStateChanged( ItemEvent event )
                    if (null != combo2.getSelectedItem() && event.getStateChange() == ItemEvent.SELECTED)
                         System.out.println("Combo2 item selected : "+ combo2.getSelectedItem()) ;
          JPanel panel = new JPanel(new BorderLayout()) ;
          panel.add(combo1,BorderLayout.NORTH) ;
          panel.add(combo2,BorderLayout.SOUTH) ;
          getContentPane().add(panel) ;
     public void loadCombo1()
          combo1.removeAllItems() ;
          for (int iCount = 0 ; iCount <5 ; iCount++)
               String strItem = "Item : "+iCount ;
          combo1.addItem(strItem) ;
          try
               combo1.setSelectedIndex(0) ;
          catch(Exception e)
     private void loadCombo2(int itemCount)
          combo2.removeAllItems() ;
          for (int iCount = 0 ; iCount <itemCount ; iCount++)
               String strItem = "Item : "+iCount ;
          combo2.addItem(strItem) ;
          try
               combo2.setSelectedIndex(0) ;
          catch(Exception e)
     public static final void main(String args[])
          CTest app = new CTest() ;
          app.init() ;
          app.setSize(100,100) ;
          app.setVisible(true) ;
          app.loadCombo1() ;
In jdk1.3 every time you change the selection in combo 1 there will be selection change in combo 2 also. but not in jdk1.4.
i am not sure whether it is a bug. But surely te behaviour is different.
any comments on this issue???

The replay answer
Advertisement
Anil,
I've just noticed this as well, so I had a quick look at the 1.4 sources. Quite simply, adding and removing items in a JComboBox will never fire an ItemStateChangedEvent, even if the selected item does change.
The culprits are intervalAdded() and intervalRemoved() in JComboBox.java. Under 1.3 these methods called contentsChanged() which would then fire an ItemStateChangedEvent if necessary. Under 1.4, these methods are empty. Why? I have no idea. It seems like a bug to me, but can't see anything in the bug database about it. Hope someone from Sun can explain it.
Regards,
Peter

Go to See the other 8 answers

JComboBox - different behaviour in 1.3 and 1.4

Category:DefaultRelease time:-0001-11-30Views:130

I have noticed that there is a difference in JCombobox behaviour in 1.3 and 1.4. I think it is better to give the program than explaining the issue. the below given program shows the difference. import javax.swing.* ; import java.awt.* ; import java.[More]

How to use JComboBox as VB DataCombo?

Category:DefaultRelease time:-0001-11-30Views:130

I wan't to know if it is possible to use a JComboBox as VB6 DataCombo. There are 3 main properties of the VB6 DataCombo component: BoundColumn, ListField and RowSource. For example I can set the rowsource of this component to be a recordset containin[More]

JComboBox Disable key action

Category:DefaultRelease time:-0001-11-30Views:130

I am using a combo box to let clients to choose two options. I got some other jTextFields in front of or follow it. I am told to use up and down arrow key to travel through these fields (including combo box). For example, after clients finished input[More]

Jcombobox as cell editor behaviour !

Category:DefaultRelease time:-0001-11-30Views:130

1. on a normal combobox, when it got focus & i pressed up/down, the display will change depending on the selected item... but it's not when it used as jtable cell editor. is it possible to change that behaviour ? i want a normal combobox behaviour ev[More]

JComboBox popup list remains open after losing keyboard focus

Category:DefaultRelease time:2015-10-11Views:130

Hi, I have noticed a strange JComboBox behavior. When you click on the drop down arrow to show the popup list, and then press the Tab key, the keyboard focus moves to the next focusable component, but the popup list remains visible. I have included a[More]

Need image to update with JComboBox selection

Category:DefaultRelease time:2015-10-11Views:130

hello, i have code here that loads an image from a JFileChooser dialog when "Add Image" is clicked, the images name and path is stored in a JComboBox, and the image name is displayed. As more images are added to the JComboBox, I would like to be[More]

Recursive background color working except for jcombobox & jbutton

Category:DefaultRelease time:2015-10-11Views:130

I'll start this as I usually do: I probably missing somethign obvious but... I am trying to setup a gui where all of a JFrames child components change background and foreground color. It seems to be working fine except for my JCombobox (the currently[More]

JComboBox.removeAllItems event in 1.4.2

Category:DefaultRelease time:2015-10-11Views:130

I've just installed 1.4.2 and noticed that JComboBox.removeAllItems now fires an ActionEvent which it didn't do in 1.4.1. This was a little inconvenient for me as I was using this event to update another field when a new selection was made in the com[More]

Exception raised using JComboBox with JUComboBoxBinding in a JTable

Category:DefaultRelease time:-0001-11-30Views:130

Hello, I am using JDeveloper 9.0.3.1035. I have a JTable bound to a bc4j view object. Now I want to use a JComboBox to select the value for a foreign key column in that Table. For this I have followed the HOWTO posted by Arno van der Kolk in Thread J[More]

JComboBox in JTable to activate when double-click instead of single-click

Category:DefaultRelease time:-0001-11-30Views:130

I like to know if it is possible to change the default behaviour of JComboBox within the JTable, such that instead of single click on the JTable cell for the combo box's popup to appear, I double click on it instead. If it is possible please give som[More]

JTable JComboBox setEditable(true) does what?

Category:DefaultRelease time:-0001-11-30Views:130

The JTable column uses JComboBox. What is expected of combo.setEditable(true)? Here is the relevant code. Thanks for (int k = 0; k < m_data.getColumnCount (); k++)         TableCellRenderer renderer = null;         TableCellEditor editor = null;     [More]

Hot
Hi, I've been using wireless access for a year and never had a problem connecting. But starting yesterday I get a +*An Error Occurred while trying to join "my wireless access point", Please try again.+* Message. I have 2 Mac's and have no proble [More]
I have a 1st Generation Apple TV. In the last two days I have purchased a movie and TV episode on my computer. When I have tried to play them through Apple TV it comes up with 'Not authorised to play this title'. No other titles are affected and play [More]
Hi All, I have question regarding Analysis Authorization. Our system has old authorization concept and as part of our project we decided to go for Analysis authorization for Cost Center object. We activated analysis authorization for cost center, ass [More]
Hi, I am working on a form created in JSP that gets the date from the user, just in case the user wants to modify the date (default is current date), i wish to provide an option for that. Is there any other way apart from using list boxes asking for [More]
Hi All, In my requirement in smart form, the standard text and values to be printed should appear both in english and chinese language. When my login language is EN(English), I cannot able to see the chinese text , but only the english text. If login [More]
My powerbook goes through phases where it puts itself to sleep over and over again. I may get a few seconds to maybe a minute before it goes back to sleep. I'll be working or using the trackpad or whatever and it will do it anyways. I usually have to [More]
Hi, While working on my project I have to create large mesh (grid). To do it I am using QuadArray and using BY_REFERENCE mode. After I close the module, the float array that is used as the coordinates array for above QuadArray geometry, is not freed. [More]
Hey all, After the iPod screen turns off automatically after the preset idle time, pressing the "Home" button does not wake the device up from the first press; on some occasions it has to be pressed twice before the "Slide to unlock" s [More]
Hi All, My client is asking the process flow for the following scenarios can any one help me by providing the procees flow 1.Depot Import Material Return Process 2. Depot FOC process. 3.Depot purchase return process. 4. High sea Sales Config (if anyt [More]
What I want to do is monitor an Abort button and when it goes true I want to stop/close the current VI and return control to the parent VI.  I tried using an Application Stop function, but this stops the entire execution and I only want to stop the c [More]