Results 1 to 5 of 5

Thread: How to use Menu Separators in Java?

  1. #1
    Join Date
    Jul 2006
    Posts
    128

    How to use Menu Separators in Java?

    I have created a menu in Java. I want to group some of the options in a Menu, and i an unable to do it.!! This is much common in Menus. The options that are having similar purpose are grouped in one side. Like you can see on your computer menus. I think that somebody would have got my point .!! Please explain me how to use Menu Separators in Java.?? It would be grateful if someone can provide me the coding for the same.!
    Last edited by PsYcHo 1; 11-02-2010 at 03:39 AM.
    "Every man is guilty of all the good he did not do". - Voltaire

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How to use Menu Separators in Java?

    You want the Menu Separator so that you can group the menus.?! This is also seen in Windows operating system. For that purpose you can use the JSeparator class. A horizontal or vertical dividing line or empty space is being provided by the JSeparator. As you said it is most commonly used in menus and tool bars. Separators are somewhat similar to borders even though they are genuine components. Hope you got some useful points from this.!!

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: How to use Menu Separators in Java?

    The code for the menu separators is very simple. If you want to add the menu items and separators to the menu, you can glance the following example, in which I explained the same :
    Code:
    menu.add(menuItem1);
    menu.add(menuItem2);
    menu.addSeparator();
    menu.add(rbMenuItem1);
    menu.add(rbMenuItem2);
    menu.add(menuItem3);
    menu.addSeparator();
    menu.add(cbMenuItem1);
    menu.add(cbMenuItem2);
    menu.add(menuItem3);
    menu.addSeparator();
    menu.add(submenu);

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: How to use Menu Separators in Java?

    You can use the JSeparator class directly to provide a dividing line in any container. I think that using the separators is very easy task because it does not have API (mostly). You will have to set the preferred size or put it in under the control of a layout manager, so that you can view the separator. Otherwise, it is visible unless you set that. You can do that in layout manager like BorderLayout or BoxLayout. Because these layouts easily gets stretched to fill its available display area.

  5. #5
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to use Menu Separators in Java?

    You can also put the ListDemo with the Panel containing the vertical separator. You can have a look at the following code snippet that shows the same :
    Code:
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane,
                                       BoxLayout.LINE_AXIS));
    buttonPane.add(fireButton);
    buttonPane.add(Box.createHorizontalStrut(7));
    buttonPane.add(new JSeparator(SwingConstants.VERTICAL));
    buttonPane.add(Box.createHorizontalStrut(7));
    buttonPane.add(employeeName);
    buttonPane.add(hireButton);
    buttonPane.setBorder(BorderFactory.createEmptyBorder(7,7,7,7));

Similar Threads

  1. Replies: 3
    Last Post: 17-08-2012, 05:43 PM
  2. Creating a Popup Menu in java
    By Adrina_g in forum Software Development
    Replies: 4
    Last Post: 25-02-2010, 10:29 PM
  3. Split a string using separators
    By Aaliya Seth in forum Software Development
    Replies: 5
    Last Post: 04-02-2010, 01:10 AM
  4. Java drop down menu
    By Ameeryan in forum Software Development
    Replies: 3
    Last Post: 05-11-2009, 01:33 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,422,509.98339 seconds with 16 queries