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

MAWT: Textarea not regaining focus in CDE

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 5.0
    • Fix Version/s: None
    • Component/s: client-libs
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_9

      Description

      FULL PRODUCT VERSION :
      java version "1.5.0_04"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)
      Java HotSpot(TM) Server VM (build 1.5.0_04-b05, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      SunOS ssd1 5.9 Generic_118558-19 sun4u sparc SUNW,Sun-Fire-V240

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Problem happens with default settings for Window's Style Manager.

      Doesn't happen if Window's style is changed so that "Point In Window To Make Active" is set.

      A DESCRIPTION OF THE PROBLEM :
      Textarea does not regain focus after bringing up File Dialog.

      Before bringing up a FileDialog, we can type in the textarea.
      After the FileDialog, clicking in the TextArea region does not properly set the focus. The window frame shows that it has the focus, but keystrokes are ignored. Text can, however, be highlighted using the mouse, but cannot be affected by the keyboard.

      Focus is returned by any of the following actions:
      1) resizing
      2) giving some other window the focus and returning
      3) giving some other component (such as checkbox) the focus and returning.

      Problem can be circumvented by using setVisible(true) on the Frame when returning from the dialog.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Log into CDE.
      Ensure Window's Style Manager is set to "Click in Window to Make Active".

      Run the following program.
      Select File>Open.
      Click on Cancel (or anything)
      Try to type in TextArea.



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      TextArea is typeable.

      This is how Windows and Linux (Gnome) work.
      It is also how it works if the CDE Window's Style is set to "Point in Window to Make Active".
      ACTUAL -
      TextArea is not typeable

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      No messages

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;
      import java.io.*;

      public class TextEditor {
        private Frame f;
        private MenuBar mb;
        private Menu m1, m2;
        private MenuItem mi1, mi2, mi3;
        private TextArea ta;

        private FileDialog fileD;

        private Dialog existsD;
        private Label dl;
        private Button db1, db2;
        private Panel pan;
        private boolean overwrite;

      public TextEditor() {
        f = new Frame("Text Editor");
        ta = new TextArea();
        mb = new MenuBar();
        m1 = new Menu("File");
        m2 = new Menu("Help");
        mi1 = new MenuItem("Open");
        mi2 = new MenuItem("Save as");
        mi3 = new MenuItem("Quit");

        fileD = new FileDialog(f, "File...");

        existsD = new Dialog(f, "File exists!", true);
        dl = new Label("File exists. Overwrite?");
        db1 = new Button("OK");
        db2 = new Button("Cancel");
        pan = new Panel();

        overwrite = false;
      }

      public void LaunchFrame() {

        // Add and configure menu bar
        mb.add(m1);
        mb.setHelpMenu(m2);
        m1.add(mi1);
        m1.add(mi2);
        m1.addSeparator();
        m1.add(mi3);
        f.setMenuBar(mb);

        // Add buttons to panel
        pan.add(db1);
        pan.add(db2);

        // Add panel to 'File exists' dialog
        existsD.setLayout(new GridLayout(2,1));
        existsD.add(dl);
        existsD.add(pan);
        existsD.pack();

        // Add text area to the center
        f.add(ta, BorderLayout.CENTER);

        // Action listeners
        f.addWindowListener(new CloseHandler());
        mi1.addActionListener(new OpenHandler());
        mi2.addActionListener(new SaveAsHandler());
        mi3.addActionListener(new QuitHandler());
        
        db1.addActionListener(new OKClickHandler());
        db2.addActionListener(new CancelClickHandler());

        // Set frame size, make it visible
        f.setSize(440, 350);
        f.setVisible(true);
      }

      // Handler for File/Quit
      class QuitHandler implements ActionListener{
        public void actionPerformed(ActionEvent e){
          System.exit(0);}
        }

      // Handler for Window close
      class CloseHandler extends WindowAdapter {
        public void windowClosing(WindowEvent e){
          System.exit(0);}
       }

      // Handler for opening a file
      class OpenHandler implements ActionListener {
        public void actionPerformed(ActionEvent e){
          //open file dialog
          fileD.setVisible(true);
          String fName = fileD.getDirectory() + fileD.getFile();

          if (fileD.getFile() != null){
            //clear ta, and stream selected file text to ta
            ta.setText("");
          
            try{
              FileReader input = new FileReader(fName);
              BufferedReader bufInput = new BufferedReader(input);
              String line;

              line = bufInput.readLine();

              while (line != null){
                ta.append(line + '\n');
                line = bufInput.readLine();}
            
              bufInput.close();
            }catch (IOException ioErr) {} //ignore it, for now
          }
        }
      }

      // Handler for save as
      class SaveAsHandler implements ActionListener{
        public void actionPerformed(ActionEvent e){
          String fName = "";

          // loop while overwrite = false
          while( !overwrite ){
            // bring up the file dialog, get a file name & location
            fileD.setVisible(true);
            fName = fileD.getDirectory() + fileD.getFile();
         
            File file = new File(fName); // create a file object of the name

            // if the file exists, show dialog to see if they wish to overwrite
            if (file.exists() ){
              existsD.setVisible(true);
              continue;}

            // else, file is original, break the while loop
            else{
              break;}
            }

          try{
            FileWriter output = new FileWriter(fName);
            BufferedWriter bufOutput = new BufferedWriter(output);
          
            // write everything in ta to fName
            bufOutput.write(ta.getText() );

            // flush and close the buffer
            bufOutput.flush();
            bufOutput.close();
          }catch(IOException ioErr) {} // ignore
        }
      }

      class OKClickHandler implements ActionListener{
        public void actionPerformed(ActionEvent e){
          overwrite = true;
          existsD.setVisible(false);}
      }

      class CancelClickHandler implements ActionListener{
        public void actionPerformed(ActionEvent e){
          existsD.setVisible(false);}
      }


      public static void main(String args[]){
        TextEditor gui = new TextEditor();
        gui.LaunchFrame();
        }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      setVisible(true) on Frame after displaying Dialog

        Attachments

          Activity

            People

            • Assignee:
              son Oleg Sukhodolsky (Inactive)
              Reporter:
              ndcosta Nelson Dcosta (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: