JDK-4587678 : Unable to select an item in the combo popup
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2001-12-10
  • Updated: 2001-12-12
  • Resolved: 2001-12-12
Related Reports
Duplicate :  
Description

Name: rmT116609			Date: 12/10/2001


java version "1.3.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)

Using Windows LAF, I noticed this behaviour, I have a combo editor for a table that is within a Frame
when editing a value, if the combo pop up goes further than the Frame, the selection is lost, no value
can be selected. This bug is very annoying to customers, since my product includes an editor that  they
 use, and I can't change the screen sizes to be able to avoid the bug...

With JDK1.4.0-beta3, the bug is reproducible even if the combo popup falls within the Frame.

In Metal LAF, with 1.3.1_01 the test case works fine but with 1.4.0-beta3 the problem is reproducible if the combo popup goes outside the Frame.

import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;

public class TableRenderDemo extends JFrame {

    public TableRenderDemo() {
        super("TableRenderDemo");

        MyTableModel myModel = new MyTableModel();
        JTable table = new JTable(myModel);
        table.setPreferredScrollableViewportSize(new Dimension(500, 70));

        //Create the scroll pane and add the table to it.
        JScrollPane scrollPane = new JScrollPane(table);


        //Fiddle with the Sport column's cell editors/renderers.
        setUpSportColumn(table.getColumnModel().getColumn(0));

        //Add the scroll pane to this window.
        getContentPane().add(scrollPane, BorderLayout.CENTER);

        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }

    public void setUpSportColumn(TableColumn sportColumn) {
        //Set up the editor for the sport cells.
        JComboBox comboBox = new JComboBox();
        comboBox.addItem("Snowboarding");
        comboBox.addItem("Rowing");
        comboBox.addItem("Chasing toddlers");
        comboBox.addItem("Speed reading");
        comboBox.addItem("Teaching high school");
        comboBox.addItem("None");
        MyEditor ed = new MyEditor(comboBox);
        sportColumn.setCellEditor(ed);
    }

    class MyTableModel extends AbstractTableModel {
        final String[] columnNames = {"Sport"};
        final Object[][] data = {
            {"Snowboarding"},
            {"Rowing"},
            {"Chasing toddlers"},
            {"Speed reading"},
            {"Teaching high school"}
        };

        public int getColumnCount() {
            return columnNames.length;
        }

        public int getRowCount() {
            return data.length;
        }

        public String getColumnName(int col) {
            return columnNames[col];
        }

        public Object getValueAt(int row, int col) {
            return data[row][col];
        }

        /*
         * Don't need to implement this method unless your table's
         * editable.
         */
        public boolean isCellEditable(int row, int col) {
                return true;
        }

        /*
         * Don't need to implement this method unless your table's
         * data can change.
         */
        public void setValueAt(Object value, int row, int col) {
            data[row][col] = value;
            fireTableCellUpdated(row, col);
        }

    }
    private class MyEditor extends DefaultCellEditor{
        public MyEditor(JComboBox c){
            super(c);
        }
        public void fireEditingStopped(){
                super.fireEditingStopped();
                }
                public java.awt.Component getTableCellEditorComponent(JTable table, Object value,
                                                                                                    boolean isSelected, final int row,
                                                                                                    final int column)
                {

            java.awt.Component comp =  super.getTableCellEditorComponent(table, value, isSelected, row, column);
            comp.addFocusListener(new FocusAdapter()
            {
                public void focusLost(FocusEvent e)
                {
                    fireEditingStopped();
                }

            });
            return comp;
        }
    }
    public static void main(String[] args) {
        try{
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        }catch(Throwable t){
                t.printStackTrace();
        }
        TableRenderDemo frame = new TableRenderDemo();
        frame.pack();
        frame.setVisible(true);

    }
}
(Review ID: 131682) 
======================================================================

Comments
EVALUATION Name: pzR10082 Date: 12/11/2001 JComboBox receives a bogus FOCUS_LOST event when user clicks on heavyweight popup. Upon receiving this event FocusListener added by the test code calls fireEditingStopped(), thus hiding the popup. This bug is especially noticeable using WinLAF because WinLAF always uses heavyweight popups, even when the combo popup falls within the frame. The problem of bogus focus events is described under #4452384. ###@###.### 2001-12-11 ====================================================================== Closing as a duplicate of 4452384. ###@###.### 2001-12-12
11-12-2001