Returns the mnemonic specified by the given key in a resource bundle. - Java Swing

Java examples for Swing:Key Event

Description

Returns the mnemonic specified by the given key in a resource bundle.

Demo Code

/*//from   w w  w  .  ja  v a2s .co  m
 * 09/08/2005
 *
 * UIUtil.java - Utility methods for org.fife.ui classes.
 * Copyright (C) 2005 Robert Futrell
 * http://fifesoft.com/rtext
 * Licensed under a modified BSD license.
 * See the included license file for details.
 */
//package com.java2s;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

public class Main {
    /**
     * Returns the mnemonic specified by the given key in a resource bundle.
     * 
     * @param msg The resource bundle.
     * @param key The key for the mnemonic.
     * @return The mnemonic, or <code>0</code> if not found.
     */
    public static final int getMnemonic(ResourceBundle msg, String key) {
        int mnemonic = 0;
        try {
            Object value = msg.getObject(key);
            if (value instanceof String) {
                mnemonic = ((String) value).charAt(0);
            }
        } catch (MissingResourceException mre) {
            // Swallow.  TODO: When we drop 1.4/1.5 support, use containsKey().
        }
        return mnemonic;
    }
}

Related Tutorials