The exact process(es) that generate(s) dense filaments which then form prestellar cores within them is unclear. Here we study the formation of a dense filament using a relatively simple set-up of a pressure-confined, uniform-density cylinder. We examine if its propensity to form a dense filament and further, to the formation of prestellar cores along this filament, bears on the gravitational state of the initial volume of gas. We report a radial collapse leading to the formation of a dense filamentary cloud is likely when the initial volume of gas is at least critically stable (characterised by the approximate equality between the mass line-density for this volume and its maximum value). Though self-gravitating, this volume of gas, however, is not seen to be in free-fall. This post-collapse filament then fragments along its length due to the growth of a Jeans-like instability to form prestellar cores. We suggest dense filaments in typical star-forming clouds classified as gravitationally super-critical under the assumption of: (i) isothermality when in fact, they are not, and (ii) extended radial profiles as against pressure-truncated, that significantly over-estimates their mass line-density, are unlikely to experience gravitational free-fall. The radial density and temperature profile derived for this post-collapse filament is consistent with that deduced for typical filamentary clouds mapped in recent surveys of nearby star-forming regions.