Here you can find the source of removeExtraSeparators(JPopupMenu popup)
Parameter | Description |
---|---|
popup | the popup menu. |
public static void removeExtraSeparators(JPopupMenu popup)
//package com.java2s; import javax.swing.*; import java.awt.*; public class Main { /**//from www . java2 s .co m * Removes extra separators, if any. This can be used when you remove some menu items and leave extra separators on * the UI. * * @param popup the popup menu. */ public static void removeExtraSeparators(JPopupMenu popup) { Component[] components = popup.getComponents(); if (components.length <= 1) { return; } for (int i = 0; i < components.length; i++) { Component component = components[i]; if (component instanceof JSeparator) { if (i == 0 || i == components.length - 1) { // if the separator is the first one or the last one, remove it because the separator is not necessary here popup.remove(component); } else if (components[i - 1] instanceof JSeparator) { popup.remove(component); } } } } }