MAMEUI should do this automatically if in general options is marked "switch resolution to fit'. If not (auto detection is not good as in groovymame) then right click on game, properties, screen. First set display then change resolution, finally frequency.