// trim off the first charactor non-numeric input
  public void eraseNonNumeric(FocusEvent e) {
    TXLogger.logger.debug("eraseNonNumeric" + e.getComponent());
    // System.out.println("eraseNonNumeric" + e.getComponent());
    String txt = ((JTextField) (e.getComponent())).getText();

    if ((txt.charAt(txt.length() - 1) < '0' || txt.charAt(txt.length() - 1) > '9')
        && txt.charAt(txt.length() - 1) != '.') {
      txt = txt.substring(0, txt.length() - 2);
      ((JTextField) (e.getComponent())).setText(txt);
    }
  }
  public void focusGained(FocusEvent event) {
    QuaquaUtilities.repaintBorder((JComponent) event.getComponent());

    final JTextComponent tc = (JTextComponent) event.getSource();
    if (tc.isEditable() && tc.isEnabled()) {

      String uiProperty;
      if (tc instanceof JPasswordField) {
        uiProperty = "PasswordField.autoSelect";
      } else if (tc instanceof JFormattedTextField) {
        uiProperty = "FormattedTextField.autoSelect";
      } else {
        uiProperty = "TextField.autoSelect";
      }

      if (tc.getClientProperty("Quaqua.TextComponent.autoSelect") == Boolean.TRUE
          || tc.getClientProperty("Quaqua.TextComponent.autoSelect") == null
              && UIManager.getBoolean(uiProperty)) {
        if (event instanceof CausedFocusEvent) {
          CausedFocusEvent cfEvent = (CausedFocusEvent) event;
          if (cfEvent.getCause() == Cause.TRAVERSAL_FORWARD
              || cfEvent.getCause() == Cause.TRAVERSAL_BACKWARD) {
            tc.selectAll();
          }
        }
      }
    }
    if (KeyboardFocusManager.getCurrentKeyboardFocusManager()
        instanceof QuaquaKeyboardFocusManager) {
      QuaquaKeyboardFocusManager kfm =
          (QuaquaKeyboardFocusManager) KeyboardFocusManager.getCurrentKeyboardFocusManager();
      kfm.setLastKeyboardTraversingComponent(null);
    }
  }
  public void focusGained(FocusEvent e) {
    JFormattedTextField field = (JFormattedTextField) e.getComponent();

    // Save the current field value in case the user botches up the edit.
    // This allows us to restore the prior value upon field exit
    saveFocusString = field.getText();
  } // focusGained
Example #4
0
 public void focusGained(FocusEvent evt) {
   Component focusedComponent = evt.getComponent();
   Component parent = focusedComponent.getParent();
   if (parent instanceof JPanel) {
     ((JPanel) parent).scrollRectToVisible(focusedComponent.getBounds(null));
   }
 }
 /** Invoked when a component gains the keyboard focus. */
 public void focusGained(FocusEvent e) {
   java.awt.Component c = e.getComponent();
   if (c instanceof JTextField) {
     JTextField jt = (JTextField) c;
     jt.setSelectionStart(0);
     jt.setSelectionEnd(jt.getText().length());
   }
 }
Example #6
0
 public void focusGained(FocusEvent e) {
   e.getComponent().removeFocusListener(this);
   currentKeyboardFocusManager.removeKeyEventDispatcher(this);
   final Iterator iterator = events.iterator();
   while (iterator.hasNext()) {
     final KeyEvent ke = (KeyEvent) iterator.next();
     ke.setSource(textComponent);
     textComponent.dispatchEvent(ke);
   }
 }
 @Override
 public void focusLost(FocusEvent e) {
   if (!e.isTemporary()) {
     final JTextComponent textComponent = (JTextComponent) e.getComponent();
     SwingUtilities.invokeLater(
         new Runnable() {
           public void run() {
             textComponent.select(0, 0);
           }
         });
   }
 }
 public void focusGained(FocusEvent e) {
   if (!e.isTemporary()) {
     final JTextComponent textComponent = (JTextComponent) e.getComponent();
     // using invokeLater as fix for bug 4740914
     SwingUtilities.invokeLater(
         new Runnable() {
           public void run() {
             textComponent.selectAll();
           }
         });
   }
 }
 public void focusGained(final FocusEvent event) {
   final Component component = event.getComponent();
   if (component instanceof JTextComponent) {
     // select all of the component text whenever the component
     // gains focus - we use invokeLater to ensure that the focus is
     // grabbed after all other work is done, which allows
     // components like JFormattedTextField to work properly
     SwingUtilities.invokeLater(
         new Runnable() {
           public void run() {
             ((JTextComponent) component).selectAll();
           }
         });
   }
 }
Example #10
0
  @Override
  public void focusLost(FocusEvent arg0) {

    Component c = arg0.getComponent();
    String source = c.getName();

    if (source == "jtf_ican") {
      JTextField jtf = (JTextField) c;
      try {
        ican = Integer.parseInt(jtf.getText());
      } catch (NumberFormatException e) {
        ican = DEF_ICAN;
        jtf.setText(Integer.toString(ican));
      }
    }
  }
    public void eventDispatched(AWTEvent event) {
      if (event instanceof FocusEvent) {
        FocusEvent focusEvent = (FocusEvent) event;
        Component fromComponent = focusEvent.getComponent();
        Component oppositeComponent = focusEvent.getOppositeComponent();

        paintFocusBorders(true);

        switch (event.getID()) {
          case FocusEvent.FOCUS_GAINED:
            myCurrent = fromComponent;
            myPrevious = oppositeComponent;
            myTemporary = focusEvent.isTemporary();
            break;
          case FocusEvent.FOCUS_LOST:
            myTemporary = focusEvent.isTemporary();
          default:
            break;
        }
      }
    }
Example #12
0
 // =========== Les listeners
 public void focusGained(FocusEvent e) {
   e.getComponent().setBackground(UiConfig.getThemeColor(ThemeColor.TABLE_CELL_FOCUSED));
 }
Example #13
0
 private void lengthFocus(java.awt.event.FocusEvent evt) { // GEN-FIRST:event_lengthFocus
   // Clears the textfield when focused at the start of the program.
   JTextField selected = (JTextField) evt.getComponent();
   selected.setText("");
   // selected.removeFocusListener((FocusListener) this);
 } // GEN-LAST:event_lengthFocus
Example #14
0
  @Override
  public void focusGained(FocusEvent arg0) {

    Component c = arg0.getComponent();
    ((JTextField) c).selectAll();
  }
 /**
  * Receives notification when the toolbar or one of it's component receives the keyboard input
  * focus.
  *
  * @param e the focus event
  */
 public void focusGained(FocusEvent e) {
   Component c = e.getComponent();
   focusedCompIndex = toolBar.getComponentIndex(c);
 }
Example #16
0
 public void focusLost(FocusEvent e) {
   Component c = e.getComponent();
   if (c instanceof TextField) ((TextField) c).select(0, 0);
 }
Example #17
0
 public void focusLost(FocusEvent e) {
   e.getComponent().setBackground(UiConfig.getThemeColor(ThemeColor.BACKGROUND));
 }
 public void focusLost(FocusEvent event) {
   QuaquaUtilities.repaintBorder((JComponent) event.getComponent());
 }
  public void focusLost(FocusEvent e) {
    JComponent field = (JComponent) e.getComponent();

    if (field.getName().compareTo("portField") == 0) {
      try {
        if (Integer.parseInt(portField.getText()) < 1) {
          portField.setText("1");
          msgBox.append("Reset port to minimum value of 1\n");
          Toolkit.getDefaultToolkit().beep();
        }

        if (Integer.parseInt(portField.getText()) > 65535) {
          portField.setText(Integer.toString(65535));
          msgBox.append("Reset port to maximum value of 65535\n");
          Toolkit.getDefaultToolkit().beep();
        }
      } catch (NumberFormatException e1) {
        msgBox.append(
            "Non integer '" + portField.getText() + "' in port field, restoring former value\n");
        portField.setText(saveFocusString);
        Toolkit.getDefaultToolkit().beep();
      }
    } // if portField
    else if (field.getName().compareTo("maxRecordField") == 0) {
      try {
        if (Integer.parseInt(maxRecordField.getText()) < 1) {
          msgBox.append("Reset Max Record to minimum value of 1\n");
          maxRecordField.setText("1");
          Toolkit.getDefaultToolkit().beep();
        }

        if (Integer.parseInt(maxRecordField.getText()) > SeedSocket.MAX_RECORDS) {
          maxRecordField.setText(Integer.toString(SeedSocket.MAX_RECORDS));
          msgBox.append("Reset Max Record to maximum value of " + SeedSocket.MAX_RECORDS + "\n");
          Toolkit.getDefaultToolkit().beep();
        }
      } catch (NumberFormatException e1) {
        msgBox.append(
            "Non integer '"
                + maxRecordField.getText()
                + "' in Max Record field, restoring former value\n");
        maxRecordField.setText(saveFocusString);
        Toolkit.getDefaultToolkit().beep();
      }
    } // if maxRecordField
    else if (field.getName().compareTo("stationField") == 0) {
      if (stationField.getText().length() < 1 || stationField.getText().length() > 5) {
        msgBox.append(
            "Station name '"
                + stationField.getText()
                + "' must be between 1 and 5 characters, restoring prior name.\n");
        stationField.setText(saveFocusString);
        Toolkit.getDefaultToolkit().beep();
      }
    } // if stationField
    else if (field.getName().compareTo("channelField") == 0) {
      if (channelField.getText().length() < 1 || channelField.getText().length() > 3) {
        msgBox.append(
            "Channel name '"
                + channelField.getText()
                + "' must be between 1 and 3 characters, restoring prior name.\n");
        channelField.setText(saveFocusString);
        Toolkit.getDefaultToolkit().beep();
      }
    } // if channelField
    else if (field.getName().compareTo("locationField") == 0) {
      if (locationField.getText().length() < 1 || locationField.getText().length() > 2) {
        msgBox.append(
            "Location name '"
                + locationField.getText()
                + "' must be between 1 and 2 characters, restoring prior name.\n");
        locationField.setText(saveFocusString);
        Toolkit.getDefaultToolkit().beep();
      }
    } // if locationField
    else if (field.getName().compareTo("startDateField") == 0) {
      if (startDateField.getText().length() != 10
          || startDateField.getText().charAt(4) != '/'
          || startDateField.getText().charAt(7) != '/'
          || !Character.isDigit(startDateField.getText().charAt(0))
          || !Character.isDigit(startDateField.getText().charAt(1))
          || !Character.isDigit(startDateField.getText().charAt(2))
          || !Character.isDigit(startDateField.getText().charAt(3))
          || !Character.isDigit(startDateField.getText().charAt(5))
          || !Character.isDigit(startDateField.getText().charAt(6))
          || !Character.isDigit(startDateField.getText().charAt(8))
          || !Character.isDigit(startDateField.getText().charAt(9))) {
        msgBox.append(
            "Invalid start date '"
                + startDateField.getText()
                + "', format is yyyy/mm/dd, restoring prior date.\n");
        startDateField.setText(saveFocusString);
        Toolkit.getDefaultToolkit().beep();
      }
    } // if startDateField
    else if (field.getName().compareTo("startTimeField") == 0) {
      if (startTimeField.getText().length() != 8
          || startTimeField.getText().charAt(2) != ':'
          || startTimeField.getText().charAt(5) != ':'
          || !Character.isDigit(startTimeField.getText().charAt(0))
          || !Character.isDigit(startTimeField.getText().charAt(1))
          || !Character.isDigit(startTimeField.getText().charAt(3))
          || !Character.isDigit(startTimeField.getText().charAt(4))
          || !Character.isDigit(startTimeField.getText().charAt(6))
          || !Character.isDigit(startTimeField.getText().charAt(7))) {
        msgBox.append(
            "Invalid start time '"
                + startTimeField.getText()
                + "', format is HH:MM:SS, restoring prior time.\n");
        startTimeField.setText(saveFocusString);
        Toolkit.getDefaultToolkit().beep();
      }
    } // if startTimeField
    else if (field.getName().compareTo("finishDateField") == 0) {
      if (finishDateField.getText().length() != 10
          || finishDateField.getText().charAt(4) != '/'
          || finishDateField.getText().charAt(7) != '/'
          || !Character.isDigit(finishDateField.getText().charAt(0))
          || !Character.isDigit(finishDateField.getText().charAt(1))
          || !Character.isDigit(finishDateField.getText().charAt(2))
          || !Character.isDigit(finishDateField.getText().charAt(3))
          || !Character.isDigit(finishDateField.getText().charAt(5))
          || !Character.isDigit(finishDateField.getText().charAt(6))
          || !Character.isDigit(finishDateField.getText().charAt(8))
          || !Character.isDigit(finishDateField.getText().charAt(9))) {
        msgBox.append(
            "Invalid finish date '"
                + finishDateField.getText()
                + "', format is yyyy/mm/dd, restoring prior date.\n");
        finishDateField.setText(saveFocusString);
        Toolkit.getDefaultToolkit().beep();
      }
    } // if finishDateField
    else if (field.getName().compareTo("finishTimeField") == 0) {
      if (finishTimeField.getText().length() != 8
          || finishTimeField.getText().charAt(2) != ':'
          || finishTimeField.getText().charAt(5) != ':'
          || !Character.isDigit(finishTimeField.getText().charAt(0))
          || !Character.isDigit(finishTimeField.getText().charAt(1))
          || !Character.isDigit(finishTimeField.getText().charAt(3))
          || !Character.isDigit(finishTimeField.getText().charAt(4))
          || !Character.isDigit(finishTimeField.getText().charAt(6))
          || !Character.isDigit(finishTimeField.getText().charAt(7))) {
        msgBox.append(
            "Invalid finish time '"
                + finishTimeField.getText()
                + "', format is HH:MM:SS, restoring prior time.\n");
        finishTimeField.setText(saveFocusString);
        Toolkit.getDefaultToolkit().beep();
      }
    } // if finishTimeField
  } // focusLost()
 private void txtImporteFocusLost(
     java.awt.event.FocusEvent evt) { // GEN-FIRST:event_txtImporteFocusLost
   // TODO add your handling code here:
   evt.getComponent().setBackground(null);
 } // GEN-LAST:event_txtImporteFocusLost
 private void txtImporteFocusGained(
     java.awt.event.FocusEvent evt) { // GEN-FIRST:event_txtImporteFocusGained
   // TODO add your handling code here:
   evt.getComponent().setBackground(new Color(150, 150, 255));
 } // GEN-LAST:event_txtImporteFocusGained
Example #22
0
 public void focusGained(FocusEvent e) {
   Component c = e.getComponent();
   if (c instanceof TextField) ((TextField) c).selectAll();
 }
Example #23
0
 /**
  * Set scroll pane position when in focus
  *
  * @param e focus event
  */
 @Override
 public void focusGained(FocusEvent e) {
   Rectangle newFocusBox = e.getComponent().getBounds();
   newFocusBox.y += kBufferHeight;
   this.scrollRectToVisible(newFocusBox);
 }