Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4109871
Votes 40
Synopsis JComboBox is not fully accessible in JTable.
Category java:classes_swing
Reported Against 5 , 1.1.7 , 4_fcs , swing1.0fcs
Release Fixed
State 6-Fix Understood, request for enhancement
Priority: 4-Low
Related Bugs 4528436 , 4690232 , 4838566 , 4838574
Submit Date 05-FEB-1998
Description
Swing-pre-1.0, jdk1.1.5, Solaris.

When using a JComboBox as a JTable cell editor, keyboard navigation doesn't work properly. Alt+Down arrow doesn't post menu of the JComboBox. 






Steps to reproduce:
1. Select the table (Note that on my system the table was
not visible until I actually clicked on it. This may be another bug.)
2. Use the arrow keys to select a cell in the first column
3. Type a letter

Note that the editor appears, but no changes can be made to the cell
If the combo box arrow is selected with the mouse, then changes can be
made with the keyboard.

import javax.swing.*;
import java.util.*;
import javax.swing.table.*;

public class JTableTest
{
	public static void main(String [] args)
	{
		//allow changing of look and feel from command line
		UIManager.LookAndFeelInfo[] lfi=UIManager.getInstalledLookAndFeels();
		try
		{
			if(args.length >0)
			{
				int i=new Integer(args[0]).intValue();
				if(i<lfi.length)
					UIManager.setLookAndFeel(lfi[i].getClassName());
			}
		}
		catch(Exception e)
		{
			//System.out.println(e);
		}
		//set up a frame
		JFrame jf=new JFrame();
		jf.setVisible(true);
		jf.setSize(640,480);
		Vector columnNames=new Vector(5,5);
		//set up some data
		for(int i=0;i<5;i++)
		{
			columnNames.addElement("Column "+i);
		}

		Vector data=new Vector(5,5);
		Vector d=new Vector(5,5);
		for(int i=0; i<5; i++)
		{
			Vector p=new Vector(5,5);
			p.addElement("A");
			for(int j=1; j<5; j++)
			{
				p.addElement("Cell "+i+", "+j);
			}
			data.addElement(p);
		}
		DefaultTableModel dt=new DefaultTableModel(data,columnNames);		
		//create a table
		JTable jt=new JTable(dt);
		jt.setSize(640,480);
		jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		//create a cell editor
		Vector letters=new Vector(5,1);
		letters.addElement("A");
		letters.addElement("B");
		letters.addElement("C");
		letters.addElement("D");
		letters.addElement("E");
		JComboBox jb=new JComboBox(letters);
		jb.setLightWeightPopupEnabled(true);
		jb.setEnabled(true);
		jb.setEditable(true);
		DefaultCellEditor dce=new DefaultCellEditor(jb);
		//set the cell editor for the column
		TableColumn tc = jt.getColumn(jt.getColumnName(0));
		tc.setCellEditor(dce);
		
		jf.getContentPane().add(jt);
	}
}
(Review ID: 41128)
======================================================================</TEXTAREA>
		      </td>
                    </tr>
                    <TR>
                      <TD colspan="2" bgcolor="#BFBFBF"> </td>
                    </tr>

<a name="comments"></a>
                    <!-- COMMENTS -->
                    <TR>
                      <TD bgcolor="#BFBFBF" align="left" valign="bottom" height="24"> 
		        <img src="/bugz/images/dot.gif" width="10">Comments
		      </td>
                      <TD bgcolor="#BFBFBF" align="left" valign="bottom" height="24"> 
			<!-- BEGIN:TBR Mohan
 			<A href="javascript:doDateStampSubmit(document.editbug_general, 'comments');"><font size="-1">[ Date Stamp ]</font></A> 
			<img src="/bugz/images/dot.gif" width="18">
			END:TBR -->
			<A href="javascript:doFullPageSubmit(document.editbug_general, 'comments');"><font size="-1">[ Full Page ]</font></a>
		        <img src="/bugz/images/dot.gif" width="22">
		        <FONT size="-1" color="darkblue">---  Enter SUN Proprietary data here  ---</font>
	              </td>
                    </tr>

                    <TR>
                      <TD bgcolor="#BFBFBF" colspan="2" nowrap align="left">
			<img src="/bugz/images/dot.gif" width="5">
                        <TEXTAREA rows="6" cols="95" wrap="virtual" name="comments" align="left" bgcolor="white">
  xxxxx@xxxxx   2003-09-09
Work Around



Possible solutions:
Write custom cell editor
Process events manually
(Review ID: 41128)
======================================================================

Custom cell editor developed as workaround is attached.
  xxxxx@xxxxx   2001-10-15
Evaluation
Yes, there is currently no equivalent of mousePressed which is availible from 
the keyboard. 
Contribution-Forum:https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?messageID=12159&forumID=1463
Posted Date : 2006-03-21 02:41:45.0
Comments
  
  Include a link with my name & email   

Submitted On 11-MAY-1999
callmanager
This problem still exists with Swing 1.1 final.
Keyboard events are not passed on to JComboBox
when positioned in a table (as CellEditor).
Also, navigation events (Arrow up, down, Enter) 
that are used by the table conflict with the
JComboBox.


Submitted On 08-MAY-2002
srinitemb
Hi,

I want to try the Custom Cell cell editor for this problem. 
where can i find it.


Submitted On 11-DEC-2002
Kleopatra
Basically it's a problem with the focus transferal: 
editorComponent.requestFocus is simply the wrong method 
to call if the editor has a child that should receive the 
keyboard input.

For 1.4.1 I put some (hopefully working) example at:
http://www.mycgiserver.com/~Kleopatra/swing/table/focuscy
cle.html

Any feedback is highly welcome

Jeanette


Submitted On 29-DEC-2003
crumhorn
Still not fixed in 1.4.2-b28. This has been open since 
Feb 05, 1998, and numerous "duplicates" filed in years 
after. What's the word? It's been almost 6 years now... 


Submitted On 11-JAN-2008
gracklemann
Let's make this one 9 years old now.. This particular bug is stated sort of poorly, perhaps that's part of the problem. Bug 4528436 part B does a better job and has a good example.  Kleopatra had some good workarounds, but things changes in 1.6 and those workarounds don't work anymore. What's the word on this one? 


Submitted On 24-MAR-2008
gracklemann
Found a workaround that seems to work under 1.6 here: 
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=5187832

You can override JTable's changeSelection method, ie:

public void changeSelection(int row, int column, boolean toggle, boolean extend)
{
	super.changeSelection(row, column, toggle, extend);
	if (column == yourComboBoxColumn)
		editCellAt(row, column);
}



PLEASE NOTE: JDK6 is formerly known as Project Mustang