-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
6
-
Cause Known
-
x86
-
linux
FULL PRODUCT VERSION :
1.6.0-b105
ADDITIONAL OS VERSION INFORMATION :
Linux hostname 2.6.17-5mdv #1 SMP Wed Sep 13 14:32:31 EST 2006 i686 AMD Ath1.6.0-b105lon(TM) XP 2200+ GNU/Linux
A DESCRIPTION OF THE PROBLEM :
When tabbing out of an editable JComboBox, focus goes to the default component specified in the focustraversal policy.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run this code, try to tab through to the 3rd textfield
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
tabbing from editable jcombobox should give the component defined in the focustraversalpolicy focus.
In this test case, jtextfield3.
ACTUAL -
Focus is given to the default component specified in the focustraversalpolicy. In this case jtextfield1.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package testingground;
import java.awt.Component;
import java.awt.Container;
import java.awt.FocusTraversalPolicy;
public class NewJFrame extends javax.swing.JFrame {
public NewJFrame() {
initComponents();
jTextField1.requestFocusInWindow();
}
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jComboBox1 = new javax.swing.JComboBox();
jTextField3 = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setFocusCycleRoot(true);
jPanel1.setFocusTraversalPolicy(new FTP());
jTextField1.setText("jTextField1");
jPanel1.add(jTextField1);
jTextField2.setText("jTextField2");
jPanel1.add(jTextField2);
jComboBox1.setEditable(true);
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jPanel1.add(jComboBox1);
jTextField3.setText("jTextField3");
jPanel1.add(jTextField3);
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
pack();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
private class FTP extends FocusTraversalPolicy {
public Component getComponentAfter(Container focusCycleRoot,Component aComponent) {
if (aComponent.equals(jTextField1)) {
return jTextField2;
}
else if (aComponent.equals(jTextField2)) {
return jComboBox1;
}
else if (aComponent.equals(jComboBox1)) {
return jTextField3;
}
else if (aComponent.equals(jTextField3)) {
return jTextField1;
}
return jTextField1;
}
public Component getComponentBefore(Container focusCycleRoot,Component aComponent) {
if (aComponent.equals(jTextField1)) {
return jTextField3;
}
else if (aComponent.equals(jTextField2)) {
return jTextField1;
}
else if (aComponent.equals(jComboBox1)) {
return jTextField2;
}
else if (aComponent.equals(jTextField3)) {
return jComboBox1;
}
return jTextField1;
}
public Component getDefaultComponent(Container focusCycleRoot) {
return jTextField1;
}
public Component getLastComponent(Container focusCycleRoot) {
return jTextField1;
}
public Component getFirstComponent(Container focusCycleRoot) {
return jTextField1;
}
}
private javax.swing.JComboBox jComboBox1;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
My guess is that when focus is given to the editable JComboBox, the JComboBox passes the focus to the editable textfield contained by the JComboBox.
This means that when defining the focustraversalpolicy, we have to cover the case for the editable field within the jcombobox.
1.6.0-b105
ADDITIONAL OS VERSION INFORMATION :
Linux hostname 2.6.17-5mdv #1 SMP Wed Sep 13 14:32:31 EST 2006 i686 AMD Ath1.6.0-b105lon(TM) XP 2200+ GNU/Linux
A DESCRIPTION OF THE PROBLEM :
When tabbing out of an editable JComboBox, focus goes to the default component specified in the focustraversal policy.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run this code, try to tab through to the 3rd textfield
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
tabbing from editable jcombobox should give the component defined in the focustraversalpolicy focus.
In this test case, jtextfield3.
ACTUAL -
Focus is given to the default component specified in the focustraversalpolicy. In this case jtextfield1.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package testingground;
import java.awt.Component;
import java.awt.Container;
import java.awt.FocusTraversalPolicy;
public class NewJFrame extends javax.swing.JFrame {
public NewJFrame() {
initComponents();
jTextField1.requestFocusInWindow();
}
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jComboBox1 = new javax.swing.JComboBox();
jTextField3 = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setFocusCycleRoot(true);
jPanel1.setFocusTraversalPolicy(new FTP());
jTextField1.setText("jTextField1");
jPanel1.add(jTextField1);
jTextField2.setText("jTextField2");
jPanel1.add(jTextField2);
jComboBox1.setEditable(true);
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jPanel1.add(jComboBox1);
jTextField3.setText("jTextField3");
jPanel1.add(jTextField3);
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
pack();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
private class FTP extends FocusTraversalPolicy {
public Component getComponentAfter(Container focusCycleRoot,Component aComponent) {
if (aComponent.equals(jTextField1)) {
return jTextField2;
}
else if (aComponent.equals(jTextField2)) {
return jComboBox1;
}
else if (aComponent.equals(jComboBox1)) {
return jTextField3;
}
else if (aComponent.equals(jTextField3)) {
return jTextField1;
}
return jTextField1;
}
public Component getComponentBefore(Container focusCycleRoot,Component aComponent) {
if (aComponent.equals(jTextField1)) {
return jTextField3;
}
else if (aComponent.equals(jTextField2)) {
return jTextField1;
}
else if (aComponent.equals(jComboBox1)) {
return jTextField2;
}
else if (aComponent.equals(jTextField3)) {
return jComboBox1;
}
return jTextField1;
}
public Component getDefaultComponent(Container focusCycleRoot) {
return jTextField1;
}
public Component getLastComponent(Container focusCycleRoot) {
return jTextField1;
}
public Component getFirstComponent(Container focusCycleRoot) {
return jTextField1;
}
}
private javax.swing.JComboBox jComboBox1;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
My guess is that when focus is given to the editable JComboBox, the JComboBox passes the focus to the editable textfield contained by the JComboBox.
This means that when defining the focustraversalpolicy, we have to cover the case for the editable field within the jcombobox.