public int showInputDialogForPositiveIntegerInput(final String message,final String suggestedInput){
  String lineWidth=suggestedInput;
  while (1 > 0) {
    lineWidth=JOptionPane.showInputDialog(null,message,lineWidth);
    if (lineWidth == null) {
      return 0;
    }
    try {
      return Integer.parseInt(lineWidth);
    }
 catch (    final NumberFormatException ex) {
      JOptionPane.showMessageDialog(null,"'" + lineWidth + "' is not a valid positive integer value.","Invalid Input",JOptionPane.ERROR_MESSAGE);
    }
  }
}

public int showInputDialogForPositiveIntegerInput ( final String message , final String suggestedInput ) { String lineWidth = suggestedInput ; while ( 1 > 0 ) { lineWidth = JOptionPane . showInputDialog ( null , message , lineWidth ) ; if ( lineWidth == null ) { return 0 ; } try { return Integer . parseInt ( lineWidth ) ; } catch ( final NumberFormatException ex ) { JOptionPane . showMessageDialog ( null , "'" + lineWidth + "' is not a valid positive integer value." , "Invalid Input" , JOptionPane . ERROR_MESSAGE ) ; } } }
forces the user to either enter nothing or a positive integer
