public void keyPressed(KeyEvent e) {

    if (e.getKeyCode() == KeyEvent.VK_TAB) {
      if (selComp == text || selComp == text2) {
        selComp.setBackground(Color.WHITE);
        ((JTextField) selComp).setEditable(false);
        ((JTextField) selComp).getCaret().setVisible(false);
      }

      text2.setBackground(Color.WHITE);
      // list.setSelectedIndex(-1);
      cBox.repaint();
      // if (saveAs)
      // text2.setBackground(Color.WHITE);

      if (selComp == cBox) cBox.setRequestFocusEnabled(false);
      if (selComp instanceof MyButton) {
        ((MyButton) selComp).setSelected(false);
      }
      // selComp.setRequestFocusEnabled(false);
      selComp.setFocusable(false);

      // list.setSelectedIndex(-1);

      if (!shift) selComp = (JComponent) mtp.getComponentAfter(dialog, selComp);
      else selComp = (JComponent) mtp.getComponentBefore(dialog, selComp);

      if (selComp == butCopy && !saveAs)
        if (!shift) selComp = (JComponent) mtp.getComponentAfter(dialog, selComp);
        else selComp = (JComponent) mtp.getComponentBefore(dialog, selComp);

      if (selComp == text || selComp == text2) {
        selComp.setBackground(vLightBlue);
        ((JTextField) selComp).getCaret().setVisible(true);
        ((JTextField) selComp).setEditable(true);
      }

      if (selComp == null) {
        selComp = list;
      } else if (selComp instanceof MyButton) ((MyButton) selComp).setSelected(true);

      if (selComp instanceof MyComboBox) {

        cBox.setBackground(vLightBlue);
      }

      selComp.setFocusable(true);
      selComp.requestFocusInWindow();

    } else if (e.getKeyCode() == KeyEvent.VK_SHIFT) {
      shift = true;
    } else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
      // if (selComp instanceof JList || selComp == text || selComp ==
      // text2) {

      enterAction.actionPerformed(new ActionEvent(e, 0, ""));
      // }
    } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
      // if (selComp instanceof JList) {

      cancelAction.actionPerformed(new ActionEvent(e, 0, ""));
      // }
    } else if (e.getKeyCode() == KeyEvent.VK_DELETE) {
      if (selComp instanceof JList) {

        deleteAction.actionPerformed(new ActionEvent(e, 0, ""));
      }
    } else if (selComp == cBox
        && ((e.getKeyCode() == KeyEvent.VK_UP) && driver.allFiles
            || (e.getKeyCode() == KeyEvent.VK_DOWN) && !driver.allFiles)) {

      driver.allFiles = !driver.allFiles;
      cBox.setSelectedIndex(driver.allFiles ? 1 : 0);

      return;
    }
    // else if (selComp == text || selComp == text2) {
    //	selComp = (Component) e.getSource();
    // }

    // repaint();
    // String u = list.getSelectedValue(); // force selection
    // list.setSelectedValue(u, false);
    paintList();
    list.repaint();
    repaint();
  }
  public void mouseClicked(MouseEvent e) {

    list.setSelectedIndex(-1);
    list.setRequestFocusEnabled(false);
    // changedField = null;

    if (selComp == text || selComp == text2) {
      selComp.setBackground(Color.WHITE);
      ((JTextField) selComp).setEditable(false);
      ((JTextField) selComp).getCaret().setVisible(false);
    }

    text2.setBackground(Color.WHITE);
    // cBox.repaint();

    if (selComp instanceof MyButton) {
      ((MyButton) selComp).setSelected(false);
      ((MyButton) selComp).setFocusable(false);
    }

    selComp = (Component) e.getSource();

    if (selComp == text || selComp == text2) {

      ((JTextField) selComp).setRequestFocusEnabled(true);

      selComp.setBackground(vLightBlue);
      ((JTextField) selComp).getCaret().setVisible(true);
      ((JTextField) selComp).setEditable(true);
      // ((JTextField) selComp).requestFocusInWindow();

    }

    if (e.getSource() instanceof JList) {
      selComp = list;
      int rowNo = list.locationToIndex(e.getPoint());
      if (rowNo == -1) return;

      list.setRequestFocusEnabled(true);

      list.setSelectedIndex(rowNo);
      text.setBackground(Color.WHITE);
      // text2.setBackground(textBackground);

      // http://stackoverflow.com/questions/16392212/unable-to-type-or-delete-text-in-jtextfield
      // http://stackoverflow.com/questions/13415150/java-swing-form-and-cannot-type-text-in-newly-added-jtextfield
      // (this says don't use keylistener!)
      //		http://stackoverflow.com/questions/22642401/jtextfield-and-keylistener-java-swing?rq=1
      //		textField.getDocument().addDocumentListener(...);
      // new code

      // text2.requestFocusInWindow();
      // text2.setBackground(vLightBlue);
      // text2.getCaret().setVisible(true);

      // String fn = listHead + File.separator + nodeNames[rowNo];

      if (e.getClickCount() == 1) {
        mLoc = e.getLocationOnScreen();

        if (nodeNames[rowNo].equals("(empty folder")) return;

      } else if (e.getClickCount() == 2) {

        Point p = e.getLocationOnScreen();

        if (mLoc != null && Math.abs(p.x - mLoc.x) < 6 && Math.abs(p.y - mLoc.y) < 6) {

          enterAction.actionPerformed(new ActionEvent(e, 0, ""));
        }
      }
    }

    if (selComp == cBox) {
      selComp.setFocusable(true);
      cBox.requestFocusInWindow();
      cBox.setEnabled(true);
      cBox.setBackground(vLightBlue);
    }

    if (selComp instanceof MyButton) {
      ((MyButton) selComp).setSelected(false);
    }
    paintList();
    list.repaint();
  }