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
Dear Experts, I have this scenario. For example : Inspection stage is 40 Inspection severity is 6 We have 10 lots need to be passed to change to another stage and we tested 5 lots and it's ok. So do we have any report that can show us that we tested [More]
Hi All, I recently installed Oracle 9i Enterprise addition on Windows XP Pro. Everything went smoothly. However, I foolishly created a database with large space requirements in the default tablespace (SYSTEM) and this caused the datafile for the SYST [More]
If I create a view in db of Pub Schema to display some data related to some products do I need to have the asset version, workspace id et al. related columns in the view as well ?Thank you Shaik. However when you say versioned item-descriptor can we [More]
Hi,everyone. I have a problem in my development. now, I'm developing my own dialog program. And I need use my own GUI status. there are some buttons on application tool bar.when I click some buttons on the application tool bar,the program will do som [More]
I just got a iPod Touch and the photos aren't synching from the pictures folder on my computer (Vista). I had the same problem on my old ipod, once I switched to this computer/ Any suggestionsI have pretty much the same problem, 22Gb free on a brand- [More]
I have the 5th gen. ipod and i just bought the iplay ipod transmitter, so that i can play my ipod through the fm radio station in my car...but when i plugged it in my ipod and followewd instructions..nothing happened..i even took it back and traded a [More]
Hi Friends. In my pricing procedure, I used JCES and JCED  for Education Cess(  instead of using JECS and JECX ) I assigned AltCty 366 to JCES and 356 to JCED in my Pricing procedure. I assigned AltCty 366 to JCES and  in tax Pricing procedure. Now P [More]
I imported contacts into my wife's iCloud account. Now I see she has a few duplicates. I can clean up her contacts manually, of course-it's not a long list-but is there a slick trick I can use to make it easy to find, merge, or duplicate duplicates?N [More]
I have a form with a hierarchy like this: Action Survey Recommendation I do not want the Action or Recommendation visible until a radio button on the survey selecting yes is performed. Multiple Recommendations can be added by clicking an "Add" b [More]
Hello I can not register Apple id, because I do not have card. Can you help me?Contact iTunes support & ask: http://www.apple.com/support/itunes/Read other 2 answers [More]