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
I know that there are a lot of similar posts out here, but they all seem to die out without a straight answer. But anyways, my problem is that about halfway through a sync, an error message pops up and says "Device _ cannot sync: disk cannot be read [More]
I'm sure that I have done something terribly stupid, so here goes: I decided to decrypt my vault file (hoping to save memory), which took about an hour. The computer asked for my Mac OSX sign in. I inserted the short form of my administrator's name a [More]
Not finding my answer after looking through this forum I am posting question. I have successfully bridged a Sony Digital8 TRV330 through my SonyTRV50 to capture analog Hi8 video but cannot get capture to work in FCP 7.0.2 I have set to non controllab [More]
I have a Macbook Pro but I don't play any games, I've never downloaded movies, but I do download music approx. 16GB and pictures...though not sure how to see how much memory these take up. Recently I've had trouble because my computer keeps notifying [More]
I have a Late 2012 Imac that is exeprincing an extreme graphical glitch on my system. First the screen might tear a bit then jitter but eventually my whole screen in turn a solid colour of what's predominantly being displayed. For example my screen w [More]
The instance is ECC 6.0 Can we roll back the material master posting period. We had some issue that the material master was rolled over by 2-3 periods accidentally which is corrected now. OSS note 1082841 was applied so the periods can not be rolled [More]
Last week i bought 30GB iPOD. I am not able to add videos in it. In iPOD setting, in Video tab all the options are in disabled mode with the default selection as no need to add videos. i think if i am able to enable "Manually maintain my own video&qu [More]
I know this is a very basic question but how do you redirect port 80?  I have an option to port forward or port trigger. What I am trying to do is use a program called Remote Administrator.  It works locally on my network but as soon as I try to conn [More]
Hi experts, Here is my issue created a value contract for services with a target value and unplanned services while creating release order agnst the contract, system asking to enter limit or flag unlimited even I flag "no limits" system throwing [More]
Revision: 15277 Revision: 15277 Author:   [email protected] Date:     2010-04-08 06:46:15 -0700 (Thu, 08 Apr 2010) Log Message: -Maven: Add ModuleId to metadata section. -Navigation: Parsley migration: ScopeManager retrieval via Context. -Navigation: [More]