I am trying to add a JSeparator
across a Panel
in GridBagLayout
, but it's not showing up.
I tried options like
panel.add(new JSeparator());
and
panel.add(new JSeparator(SwingConstants.HORIZONTAL));
None of them are giving a visible separator.
Read the section from the Swing tutorial on How to Use Separators where you will find the statement:
So if you use it with a
GridBagLayout
, then you will need to specify proper constraints so that the separator fills all the columns for the given row. Read the section from the Swing tutorial on How to Use GridBagLayout for more information on the constraints and working examples. The tutorial demonstrates how to have a button fill 3 columns, so try replacing the button with your separator.