Java examples for Swing:JCheckBox
Returns a check box with the specified text.
/*/* w ww. ja v a2 s. c o 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; import javax.swing.JCheckBox; public class Main { /** * Returns a check box with the specified text. If another property is * defined in the resource bundle with key * <code>key + ".Mnemonic"</code>, then it will be used for the mnemonic * of the check box. * * @param bundle The resource bundle for localizing the check box. * @param key The key into the bundle containing the string text value. * @return The check box. */ public static final JCheckBox newCheckBox(ResourceBundle bundle, String key) { JCheckBox cb = new JCheckBox(bundle.getString(key)); cb.setMnemonic(getMnemonic(bundle, mnemonicKey(key))); return cb; } /** * 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; } /** * Returns the default key for a button or menu item's mnemonic, based * on its root key. * * @param key The key. * @return The mnemonic key. */ private static final String mnemonicKey(String key) { return key + ".Mnemonic"; } }