Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4587678

Unable to select an item in the combo popup

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.4.0
    • client-libs



      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)
      ======================================================================

            peterz Peter Zhelezniakov
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: