Just replace new JSeparator(...)
with the following lines (you can put them in a method if you want):
JSeparator separator = new JSeparator(JSeparator.VERTICAL); Dimension size = new Dimension( separator.getPreferredSize().width, separator.getMaximumSize().height); separator.setMaximumSize(size);
As @kleopatra explained, JSeparator has an unlimited maximum size (in both directions), so here you need to limit the maximum width to the preferred width, but keep the maximum height unchanged (because the preferred height is 0
).
source share