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 recently purchased some music.  Then I realized that I hadn't heard some other music for a long time.  I checked the iPod and the music isn't there.  On my PC in the iTunes library it is there but it won't copy to the iPod.  I went to my local Appl [More]
Hi All.. I am trying to use the dbms_parallel_execute package to insert into my target table. But at the end of execution, the rows not getting inserted into the target table. Could any one please help on this? Below are the statements.... create tab [More]
Hi! There is a table name that is decided dynamically. the name is: someNameYYY where YYY denotes the client number. I get the client number by sy-mandt and concatenate it with someNameYYY to lc_table_name but then comes the problem: I cannot do SELE [More]
Hi Experts Due to deviation of supply quality by vendor, there will be additional costs incurred in the project execution phase. This need to be recorded in system for re-evluating vendor price comparion. And client does not want to charge the vendor [More]
Hi, I am creating a dynamic selection screen ,it is having the default PF_status .But now i want to give a different PF_status in that dynamic selection screen. Like if i press the back button it should take me to the previous screen,but now it is go [More]
When hitting saving for web and devices, Photoshop starts to render images but before it's done, it crashes. I get an error-popup with no text and the screen where normally the animation is shown is red. Then Windows comes with a crash report and I c [More]
can you use fw400 from old mac book to fw 800 external drivers i have seen adapters the other way around but not this wayYes, here's some on Amazon http://www.amazon.com/s/ref=nb_sb_ss_i_0_19?url=search-alias%3Delectronics&field -keywords=firewire+40 [More]
  Hi guys,  Just bought my first SSD drive (240GIG)and are about to set it up for the purpose of doing any Adobe CC work the fastest I can. Obviously I have to install the Windows 7 Pro system onto the drive and Adobe files, I imagine that any work A [More]
Hi, We have re-engineered the current Position and Job Flexfield set-up, basically an additional segment in the Position FF and hiding a segment in Job FF. Adn the employee will be assigned to a one level high in the organization. So basically, emplo [More]
I want to be able to create a file in ID5.5 that can be opened by PM7 so that I can use PM's automatic indexing.You might find something useful over at http://www.indiscripts.com/ for producing an index in ID without using the index module.Read other [More]