Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9231035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:58:13+00:00 2026-06-18T05:58:13+00:00

I have a problem when i want insert a separator with JSeparator for Java

  • 0

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 :
enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:58:15+00:00Added an answer on June 18, 2026 at 5:58 am

    Basically your code right now shows that you are assuming JMenuItem has a default BorderLayout, which could be true (but I dont think so).

    Though the root problem is you are adding the JSeparator to the JMenuItem when in fact you should add it to the JMenu which contains the various JMenuItems via JMenu#addSeparator(). See How to Use Separators for more.

    You should be doing something like:

    JMenu menu=new JMenu();
    
    JMenuItem item1=new JMenuItem("something 1");
    JMenuItem item2=new JMenuItem("something 1");
    
    menu.add(item1);
    menu.addSeparator();//lets add that separator
    menu.add(item2);
    

    giving you something like:

    enter image description here

    UPDATE:

    Here is an example:

    enter image description here

    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.SwingUtilities;
    
    public class Test {
    
        public Test() {
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    
            JMenuBar menuBar=new JMenuBar();
    
            JMenu menu = new JMenu("File");
            JMenu menu2 = new JMenu("Else");
    
            JMenuItem item1 = new JMenuItem("something 1");
            JMenuItem item2 = new JMenuItem("something 2");
            JMenuItem item3 = new JMenuItem("else 1");
            JMenuItem item4 = new JMenuItem("else 2");
    
            menu2.add(item3);
            menu2.addSeparator();//lets add that separator
            menu2.add(item4);
    
            menu.add(menu2);
            menu.add(item1);
            menu.addSeparator();//lets add that separator
            menu.add(item2);
    
            menuBar.add(menu);
    
            frame.setJMenuBar(menuBar);
            frame.pack();
            frame.setVisible(true);
        }
    
        public static void main(String args[]) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    new Test();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem if i want to insert this json test into my
I have this problem: I want to generate a new source code file from
I am using GWT/JAVA for development. I have following problem: I want to remove
I have problem with fancybox. I want to write a function that will run
with my RCP program I have the problem that I want to have more
I have a problem that when we want to Insert a data into a
I want to insert some data to mydatabase.sqlite but I have a problem. There
Hi currently have the problem, that I want to insert values in a postgres
I have problem with this. I have one arrayList, and I want to copy
I have problem with php's preg_match.I want to make something like this : When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.