Пример #1
0
  // This method is called when a cell value is edited by the user.
  public Component getTableCellEditorComponent(
      JTable table, Object value, boolean isSelected, int row, int column) {
    // Configure the component with the specified value
    if (!mitMaus) {
      ((JFormattedTextField) component).setText(String.valueOf(value));
      ((JFormattedTextField) component).selectAll();
      ((JFormattedTextField) component).setHorizontalAlignment(SwingConstants.RIGHT);
      ((JFormattedTextField) component).setBackground(Color.YELLOW);

    } else {
      final String xvalue = String.valueOf(value);
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              ((JFormattedTextField) component).setText(String.valueOf(xvalue).replace(".", ","));
              ((JFormattedTextField) component).selectAll();
              ((JFormattedTextField) component).setBackground(Color.YELLOW);
              ((JFormattedTextField) component).setHorizontalAlignment(SwingConstants.RIGHT);
              ((JFormattedTextField) component).setCaretPosition(0);
            }
          });
    }

    // Return the configured component
    //// System.out.println("I've been Called!!");
    return component;
  }
Пример #2
0
  /**
   * Lets the user know that the text they entered is bad. Returns true if the user elects to revert
   * to the last good value. Otherwise, returns false, indicating that the user wants to continue
   * editing.
   */
  protected boolean userSaysRevert() {
    Toolkit.getDefaultToolkit().beep();
    ftf.selectAll();
    Object[] options = {"Editar", "Revertir"};
    String mensaje = "El valor debe ser ";
    if (minimum != null && maximum != null)
      mensaje += "mayor a " + minimum + " y menor a " + maximum;
    else {
      if (minimum != null) mensaje += "mayor a " + minimum;
      if (maximum != null) mensaje += "menor a " + maximum;
    }
    int answer =
        JOptionPane.showOptionDialog(
            SwingUtilities.getWindowAncestor(ftf),
            mensaje + ".\n" + "¿Deseas editar el número " + "o revertir los cambios?",
            "Valor ingresado no válido",
            JOptionPane.YES_NO_OPTION,
            JOptionPane.ERROR_MESSAGE,
            null,
            options,
            options[1]);

    if (answer == 1) { // Revert!
      ftf.setValue(ftf.getValue());
      return true;
    }
    return false;
  }