Java Code Examples for javax.swing.JMenuItem#setBorder()

The following examples show how to use javax.swing.JMenuItem#setBorder() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MenuEditLayer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static void installAcceleratorPreview(JMenuItem item) {
    if(item instanceof JMenu) return;
    //detect accelerator key
    boolean already_has_accel = false;
    if(item.getAccelerator() != null) already_has_accel = true;
    if(item.getAction() != null && item.getAction().getValue(Action.ACCELERATOR_KEY) != null) already_has_accel = true;

    
    
    boolean already_has_accel_border = false;
    if(item.getBorder() == accel_border) {
        already_has_accel_border = true;
        //uninstall if needed
        if(already_has_accel) {
            item.setBorder(null);
            return;
        }
    }
    
    if(item.getBorder() instanceof CompoundBorder) {
        CompoundBorder comp = (CompoundBorder)item.getBorder();
        if(comp.getInsideBorder() == accel_border) {
            already_has_accel_border = true;
            //uninstall if needed
            if(already_has_accel) {
                item.setBorder(comp.getOutsideBorder());
                return;
            }
        }
    }
    
    if(already_has_accel_border) return;
    if(already_has_accel) return;
    
    
    if(item.getBorder() == null) {
        item.setBorder(accel_border);
        return;
    }
    
    item.setBorder(BorderFactory.createCompoundBorder(
                item.getBorder(),accel_border));
}
 
Example 2
Source File: SettingsPanel.java    From stendhal with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a menu item.
 *
 * @param name title of the menu item
 * @param action SlashAction name
 * @return menu item
 */
private JMenuItem createMenuItem(String name, String action) {
	JMenuItem item = new VariableWidthMenuItem(name);
	item.addActionListener(new CommandActionListener(action));
	item.setBorder(null);
	return item;
}