I have a problem when i want insert a separator with JSeparator for Java Swing application. In point of fact, I have this problem just when i run my program on Mac, i haven't it on windows or linux. The separator is incorrectly placed, the text is strikethrough. Does anyone know why?
My code :
JMenuItem fileItem = new JMenuItem("Close");
KeyStroke ...
fileItem.add(new JSeparator(JSeparator.HORIZONTAL),BorderLayout.LINE_START);
Screenshot :
Basically your code right now shows that you are assuming
JMenuItem
has a defaultBorderLayout
, which could be true (but I dont think so).Though the root problem is you are adding the
JSeparator
to theJMenuItem
when in fact you should add it to theJMenu
which contains the variousJMenuItem
s viaJMenu#addSeparator()
. See How to Use Separators for more.You should be doing something like:
giving you something like:
UPDATE:
Here is an example: