United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4188128 : JComboBox drops its cursor after L&F change

Details
Type:
Bug
Submit Date:
1998-11-08
Status:
Closed
Updated Date:
1999-01-28
Project Name:
JDK
Resolved Date:
1999-01-28
Component:
client-libs
OS:
generic,windows_95
Sub-Component:
javax.swing
CPU:
x86,generic
Priority:
P4
Resolution:
Duplicate
Affected Versions:
1.1.6,1.2.0
Fixed Versions:

Related Reports
Duplicate:

Sub Tasks

Description

Name: krT82822			Date: 11/08/98


This JComboBox bug occurs with both JDK v1.2b4.1 *and* JDK v1.1.6
w/Swing v1.1b2.

I'm using WinNT v4.0, SP3.

I've included a minimal sample program to illustrate the buggy behavior.

The problem has to do with setting the cursor for a JComboBox's "edit
field" when setEditable(true) has been called on the JComboBox.  The
problem is that when the LaF changes, the cursor reverts back to the
standard arrow.

Not that if I replace the JComboBox with a JTextField, this problem does
not occur.


Follow these steps:

1.  Run the attached program.
2.  Move the cursor over the edit field of the JComboBox.  Note the
shape of the cursor.
3.  Change the LaF to any of the three available LaFs.
4.  Move the cursor over the edit field of the JComboBox.  Note the
shape of the cursor -- it is an arrow!


import com.sun.java.swing.*;
import java.awt.*;
import java.awt.event.*;

class Tester9
{
   private static final JComboBox comboBox = new JComboBox();

   public static void main(String[] args)
   {
      final JFrame    f = new JFrame();

      // WindowListener for closing progam.
      f.addWindowListener(new WindowAdapter()
      {
         public void windowClosing(WindowEvent evt)
         {
            evt.getWindow().dispose();
            System.exit(0);
         }
      });

      f.getContentPane().add(comboBox, BorderLayout.NORTH);
      
      comboBox.setEditable(true);
      
      Component editorComponent = comboBox.getEditor().getEditorComponent();
      editorComponent.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
      
      //--------------------
      // The remaining code simply allows for a change in the LaF....
      //--------------------
      JPanel LaFPanel = new JPanel();

      final JButton windowsLaF = new JButton("Windows"),
                    motifLaF   = new JButton("Motif"),
                    metalLaF   = new JButton("Metal");

      LaFPanel.add(windowsLaF);
      LaFPanel.add(motifLaF);
      LaFPanel.add(metalLaF);

      ActionListener LaFListener = new ActionListener()
      {
         public void actionPerformed(ActionEvent evt)
         {
            Object src = evt.getSource();

            try
            {
               if(src == windowsLaF)
                  UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
               else if(src == motifLaF)
      	    	   UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
               else
      	    	   UIManager.setLookAndFeel("com.sun.java.swing.plaf.metal.MetalLookAndFeel");

               SwingUtilities.updateComponentTreeUI(f);
            }
            catch(Exception e)
            {
               System.err.println("*** ERROR IN CHANGING LAF: " + e);
            }
         }
      };

      windowsLaF.addActionListener(LaFListener);
      motifLaF.addActionListener(LaFListener);
      metalLaF.addActionListener(LaFListener);

      f.getContentPane().add(LaFPanel, BorderLayout.SOUTH);
      f.setBounds(50, 50, 300, 300);
      f.setVisible(true);
   }
}
(Review ID: 38139)
======================================================================

                                    

Comments
EVALUATION

It is up to each look and feel to provide the subcomponents for JComboBox (like the edit field, for example).  When you switch L&Fs, the edit field that had your cursor on it goes away and a new editor is made for the new L&F.  This problem would be fixed if we had a fix for the compound component problem, so I'm marking this as a duplicate of bug 4144505.
tom.santos@eng 1999-01-28
                                     
1999-01-28
WORK AROUND



Name: krT82822			Date: 11/08/98


Explicit re-setting of text field's cursor after L&F change restores the expected behavior.
======================================================================
                                     
2004-06-11



Hardware and Software, Engineered to Work Together