-
Enhancement
-
Resolution: Duplicate
-
P4
-
None
-
1.1.6, 1.2.0
-
x86, sparc
-
solaris_2.6, windows_nt
In JComboBox, the FOCUS_GAINED event is not fired if the combobopx is editable. This happens if the focus is set by tabbing into the component with the keyboard and not when the mouse is used to set focus to the combobox. This happens on both Solaris and Win NT
Steps to reproduce the same,
1. Run the application for which the sample code is given below.
2. Set focus to the first dummy button
3. Press <TAB> - focus shifts to the next dummy button.
4. Press <TAB> - focus shifts to the Combobox - Observe in the output that the FOCUS_GAINED event which is supposed to be fired in not fired.
5. Press <TAB> 3 times. - Ths focus is now set to the second combo box which has setEditable --> false.
6. Now the FOCUS_GAINED event is fired.
-- Sample Code --
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
public class TestJCombo01 extends JFrame implements FocusListener {
/*************************************** Bug Description ***************************************/
String[] strBugDesc = { "",
"",
"",
"",
"This TestCase tests the JComboBox Component",
"**Problem** : FocusEvent not fired when JComboBox is editable.",
"",
"Steps to reproduce :",
"1. Set focus to the first dummy button",
"2. Press <TAB> - focus shifts to the next dummy button",
"3. Press <TAB> - focus shifts to the Combobox - Observe in the output that the FOCUS_GAINED event which ",
" is supposed to be fired in not fired.",
"4. Press <TAB> 3 times. - Ths focus is now set to the second combo box which has setEditable --> false.",
"5. Now the FOCUS_GAINED event is fired.",
"",
"Pass/Fail Criteria : ",
"Pass -- FOCUS_GAINED event should be fired even when the JComboBox is editable..",
"",
"",
"",
""};
/*************************************** Bug Description ***************************************/
Container content;
JPanel panel;
JComboBox combo;
JButton label;
String[] data = {"one", "two", "free", "four", "five", "six", "seven", "eight", "nine", "ten"};
TestJCombo01(String[] args) {
displayBugDesc();
content = getContentPane();
content.setLayout(new BorderLayout());
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event){
System.exit(0);
}
}
);
panel = new JPanel();
panel.setLayout(new GridLayout(0, 2, 10, 10));
panel.add(new JButton("Dummy Button"));
panel.add(new JButton("Dummy Button"));
panel.add(new JLabel("ComboBox with setEditable --> true"));
combo = new JComboBox();
combo.setEditable(true);
combo.addFocusListener(this);
for(int i =0; i < data.length; i ++) {
combo.addItem(data[i]);
}
panel.add(combo);
panel.add(new JButton("Dummy Button"));
panel.add(new JButton("Dummy Button"));
panel.add(new JLabel("ComboBox with setEditable --> false"));
combo = new JComboBox();
combo.setEditable(false);
combo.addFocusListener(this);
for(int i =0; i < data.length; i ++) {
combo.addItem(data[i]);
}
panel.add(combo);
content.add("Center", panel);
pack();
show();
}
public void displayBugDesc() {
int n = strBugDesc.length;
System.out.println("/******************************* Bug Description and Comments *******************************/");
System.out.println();
for(int i = 0; i < n; i ++) {
System.out.println(strBugDesc[i]);
}
System.out.println();
System.out.println("/******************************* Bug Description and Comments *******************************/");
}
public void focusGained(FocusEvent e) {
System.out.println(e.paramString());
}
public void focusLost(FocusEvent e) {
System.out.println(e.paramString());
}
// Main funtion
public static void main(String[] args) {
TestJCombo01 test = new TestJCombo01(args);
}
}
-- Sample Code --
Steps to reproduce the same,
1. Run the application for which the sample code is given below.
2. Set focus to the first dummy button
3. Press <TAB> - focus shifts to the next dummy button.
4. Press <TAB> - focus shifts to the Combobox - Observe in the output that the FOCUS_GAINED event which is supposed to be fired in not fired.
5. Press <TAB> 3 times. - Ths focus is now set to the second combo box which has setEditable --> false.
6. Now the FOCUS_GAINED event is fired.
-- Sample Code --
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
public class TestJCombo01 extends JFrame implements FocusListener {
/*************************************** Bug Description ***************************************/
String[] strBugDesc = { "",
"",
"",
"",
"This TestCase tests the JComboBox Component",
"**Problem** : FocusEvent not fired when JComboBox is editable.",
"",
"Steps to reproduce :",
"1. Set focus to the first dummy button",
"2. Press <TAB> - focus shifts to the next dummy button",
"3. Press <TAB> - focus shifts to the Combobox - Observe in the output that the FOCUS_GAINED event which ",
" is supposed to be fired in not fired.",
"4. Press <TAB> 3 times. - Ths focus is now set to the second combo box which has setEditable --> false.",
"5. Now the FOCUS_GAINED event is fired.",
"",
"Pass/Fail Criteria : ",
"Pass -- FOCUS_GAINED event should be fired even when the JComboBox is editable..",
"",
"",
"",
""};
/*************************************** Bug Description ***************************************/
Container content;
JPanel panel;
JComboBox combo;
JButton label;
String[] data = {"one", "two", "free", "four", "five", "six", "seven", "eight", "nine", "ten"};
TestJCombo01(String[] args) {
displayBugDesc();
content = getContentPane();
content.setLayout(new BorderLayout());
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event){
System.exit(0);
}
}
);
panel = new JPanel();
panel.setLayout(new GridLayout(0, 2, 10, 10));
panel.add(new JButton("Dummy Button"));
panel.add(new JButton("Dummy Button"));
panel.add(new JLabel("ComboBox with setEditable --> true"));
combo = new JComboBox();
combo.setEditable(true);
combo.addFocusListener(this);
for(int i =0; i < data.length; i ++) {
combo.addItem(data[i]);
}
panel.add(combo);
panel.add(new JButton("Dummy Button"));
panel.add(new JButton("Dummy Button"));
panel.add(new JLabel("ComboBox with setEditable --> false"));
combo = new JComboBox();
combo.setEditable(false);
combo.addFocusListener(this);
for(int i =0; i < data.length; i ++) {
combo.addItem(data[i]);
}
panel.add(combo);
content.add("Center", panel);
pack();
show();
}
public void displayBugDesc() {
int n = strBugDesc.length;
System.out.println("/******************************* Bug Description and Comments *******************************/");
System.out.println();
for(int i = 0; i < n; i ++) {
System.out.println(strBugDesc[i]);
}
System.out.println();
System.out.println("/******************************* Bug Description and Comments *******************************/");
}
public void focusGained(FocusEvent e) {
System.out.println(e.paramString());
}
public void focusLost(FocusEvent e) {
System.out.println(e.paramString());
}
// Main funtion
public static void main(String[] args) {
TestJCombo01 test = new TestJCombo01(args);
}
}
-- Sample Code --
- duplicates
-
JDK-4144505 Compound components don't behave properly
-
- Closed
-