Java Code Examples for javax.swing.AbstractButton#setDisplayedMnemonicIndex()
The following examples show how to use
javax.swing.AbstractButton#setDisplayedMnemonicIndex() .
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: ProxySettingsForm.java From azure-devops-intellij with MIT License | 6 votes |
/** * @noinspection ALL */ private void $$$loadButtonText$$$(AbstractButton component, String text) { StringBuffer result = new StringBuffer(); boolean haveMnemonic = false; char mnemonic = '\0'; int mnemonicIndex = -1; for (int i = 0; i < text.length(); i++) { if (text.charAt(i) == '&') { i++; if (i == text.length()) break; if (!haveMnemonic && text.charAt(i) != '&') { haveMnemonic = true; mnemonic = text.charAt(i); mnemonicIndex = result.length(); } } result.append(text.charAt(i)); } component.setText(result.toString()); if (haveMnemonic) { component.setMnemonic(mnemonic); component.setDisplayedMnemonicIndex(mnemonicIndex); } }
Example 2
Source File: ApplyLabelForm.java From azure-devops-intellij with MIT License | 6 votes |
/** * @noinspection ALL */ private void $$$loadButtonText$$$(AbstractButton component, String text) { StringBuffer result = new StringBuffer(); boolean haveMnemonic = false; char mnemonic = '\0'; int mnemonicIndex = -1; for (int i = 0; i < text.length(); i++) { if (text.charAt(i) == '&') { i++; if (i == text.length()) break; if (!haveMnemonic && text.charAt(i) != '&') { haveMnemonic = true; mnemonic = text.charAt(i); mnemonicIndex = result.length(); } } result.append(text.charAt(i)); } component.setText(result.toString()); if (haveMnemonic) { component.setMnemonic(mnemonic); component.setDisplayedMnemonicIndex(mnemonicIndex); } }
Example 3
Source File: LockItemsForm.java From azure-devops-intellij with MIT License | 6 votes |
/** * @noinspection ALL */ private void $$$loadButtonText$$$(AbstractButton component, String text) { StringBuffer result = new StringBuffer(); boolean haveMnemonic = false; char mnemonic = '\0'; int mnemonicIndex = -1; for (int i = 0; i < text.length(); i++) { if (text.charAt(i) == '&') { i++; if (i == text.length()) break; if (!haveMnemonic && text.charAt(i) != '&') { haveMnemonic = true; mnemonic = text.charAt(i); mnemonicIndex = result.length(); } } result.append(text.charAt(i)); } component.setText(result.toString()); if (haveMnemonic) { component.setMnemonic(mnemonic); component.setDisplayedMnemonicIndex(mnemonicIndex); } }
Example 4
Source File: TFSVersionFilterComponent.java From azure-devops-intellij with MIT License | 6 votes |
/** * @noinspection ALL */ private void $$$loadButtonText$$$(AbstractButton component, String text) { StringBuffer result = new StringBuffer(); boolean haveMnemonic = false; char mnemonic = '\0'; int mnemonicIndex = -1; for (int i = 0; i < text.length(); i++) { if (text.charAt(i) == '&') { i++; if (i == text.length()) break; if (!haveMnemonic && text.charAt(i) != '&') { haveMnemonic = true; mnemonic = text.charAt(i); mnemonicIndex = result.length(); } } result.append(text.charAt(i)); } component.setText(result.toString()); if (haveMnemonic) { component.setMnemonic(mnemonic); component.setDisplayedMnemonicIndex(mnemonicIndex); } }
Example 5
Source File: ManageWorkspacesForm.java From azure-devops-intellij with MIT License | 6 votes |
/** * @noinspection ALL */ private void $$$loadButtonText$$$(AbstractButton component, String text) { StringBuffer result = new StringBuffer(); boolean haveMnemonic = false; char mnemonic = '\0'; int mnemonicIndex = -1; for (int i = 0; i < text.length(); i++) { if (text.charAt(i) == '&') { i++; if (i == text.length()) break; if (!haveMnemonic && text.charAt(i) != '&') { haveMnemonic = true; mnemonic = text.charAt(i); mnemonicIndex = result.length(); } } result.append(text.charAt(i)); } component.setText(result.toString()); if (haveMnemonic) { component.setMnemonic(mnemonic); component.setDisplayedMnemonicIndex(mnemonicIndex); } }
Example 6
Source File: CreateBranchForm.java From azure-devops-intellij with MIT License | 6 votes |
/** * @noinspection ALL */ private void $$$loadButtonText$$$(AbstractButton component, String text) { StringBuffer result = new StringBuffer(); boolean haveMnemonic = false; char mnemonic = '\0'; int mnemonicIndex = -1; for (int i = 0; i < text.length(); i++) { if (text.charAt(i) == '&') { i++; if (i == text.length()) break; if (!haveMnemonic && text.charAt(i) != '&') { haveMnemonic = true; mnemonic = text.charAt(i); mnemonicIndex = result.length(); } } result.append(text.charAt(i)); } component.setText(result.toString()); if (haveMnemonic) { component.setMnemonic(mnemonic); component.setDisplayedMnemonicIndex(mnemonicIndex); } }
Example 7
Source File: CreateBranchForm.java From azure-devops-intellij with MIT License | 6 votes |
/** * @noinspection ALL */ private void $$$loadButtonText$$$(AbstractButton component, String text) { StringBuffer result = new StringBuffer(); boolean haveMnemonic = false; char mnemonic = '\0'; int mnemonicIndex = -1; for (int i = 0; i < text.length(); i++) { if (text.charAt(i) == '&') { i++; if (i == text.length()) break; if (!haveMnemonic && text.charAt(i) != '&') { haveMnemonic = true; mnemonic = text.charAt(i); mnemonicIndex = result.length(); } } result.append(text.charAt(i)); } component.setText(result.toString()); if (haveMnemonic) { component.setMnemonic(mnemonic); component.setDisplayedMnemonicIndex(mnemonicIndex); } }
Example 8
Source File: TeamServicesSettingsForm.java From azure-devops-intellij with MIT License | 6 votes |
/** * @noinspection ALL */ private void $$$loadButtonText$$$(AbstractButton component, String text) { StringBuffer result = new StringBuffer(); boolean haveMnemonic = false; char mnemonic = '\0'; int mnemonicIndex = -1; for (int i = 0; i < text.length(); i++) { if (text.charAt(i) == '&') { i++; if (i == text.length()) break; if (!haveMnemonic && text.charAt(i) != '&') { haveMnemonic = true; mnemonic = text.charAt(i); mnemonicIndex = result.length(); } } result.append(text.charAt(i)); } component.setText(result.toString()); if (haveMnemonic) { component.setMnemonic(mnemonic); component.setDisplayedMnemonicIndex(mnemonicIndex); } }
Example 9
Source File: Utilities.java From wpcleaner with Apache License 2.0 | 6 votes |
/** * Apply a shortcut to a button. * * @param button Button. * @param shortcut Shortcut. * @param message Related message. */ private static void setShortcut( AbstractButton button, ShortcutProperties shortcut, String message) { if ((shortcut == null) || (shortcut.useMnemonic())) { int mnemonic = getMnemonic(message); if ((mnemonic == -1) && (shortcut != null)) { mnemonic = shortcut.getKey(); } if (mnemonic != -1) { button.setMnemonic(mnemonic); } } else if (shortcut.getEnabled()) { String actionName = "action_" + shortcut.getName(); InputMap inputMap = button.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); inputMap.put(KeyStroke.getKeyStroke(shortcut.getKey(), shortcut.getModifiers()), actionName); button.getActionMap().put(actionName, new ActionClick(button)); if (message != null) { int index = message.indexOf(shortcut.getKey()); if ((index >= 0) && (index < button.getText().length())) { button.setDisplayedMnemonicIndex(index); } } } }
Example 10
Source File: GuiUtil.java From FancyBing with GNU General Public License v3.0 | 5 votes |
/** Parse text that has the mnemonic marked with a preceding'&' (like in Qt) and set the text and mnemonic of the button. */ public static void setTextAndMnemonic(AbstractButton button, String text) { int pos = text.indexOf('&'); text = text.replace("&", ""); button.setText(text); if (pos >= 0 && pos < text.length()) { String mnemonic = text.substring(pos, pos + 1).toUpperCase(); KeyStroke keyStroke = KeyStroke.getKeyStroke(mnemonic); int code = keyStroke.getKeyCode(); button.setMnemonic(code); button.setDisplayedMnemonicIndex(pos); } }
Example 11
Source File: Mnemonics.java From netbeans with Apache License 2.0 | 5 votes |
/** * Wrapper for the * <code>AbstractButton.setMnemonicIndex</code> or * <code>JLabel.setDisplayedMnemonicIndex</code> method. * @param item AbstractButton/JLabel or subclasses * @param index Index of the Character to underline under JDK1.4 * @param latinCode Latin Character Keycode to underline under JDK1.3 */ private static void setMnemonicIndex(Object item, int index) { if (item instanceof AbstractButton) { AbstractButton b = (AbstractButton) item; b.putClientProperty(PROP_DISPLAYED_MNEMONIC_INDEX, index); b.removePropertyChangeListener(PROP_DISPLAYED_MNEMONIC_INDEX, MNEMONIC_INDEX_LISTENER); b.setDisplayedMnemonicIndex(index); b.addPropertyChangeListener(PROP_DISPLAYED_MNEMONIC_INDEX, MNEMONIC_INDEX_LISTENER); } else if (item instanceof JLabel) { ((JLabel) item).setDisplayedMnemonicIndex(index); } }
Example 12
Source File: Mnemonics.java From netbeans with Apache License 2.0 | 5 votes |
public void propertyChange(PropertyChangeEvent evt) { AbstractButton b = (AbstractButton) evt.getSource(); if (b.getDisplayedMnemonicIndex() == -1) { Integer mnemonic = (Integer) b.getClientProperty(PROP_MNEMONIC); Integer index = (Integer) b.getClientProperty(PROP_DISPLAYED_MNEMONIC_INDEX); if (mnemonic != null && index != null && Utilities.compareObjects(b.getText(), b.getClientProperty(PROP_TEXT))) { b.setMnemonic(mnemonic); b.setDisplayedMnemonicIndex(index); } } }
Example 13
Source File: Utils.java From visualvm with GNU General Public License v2.0 | 5 votes |
/** * Actual setter of the text & mnemonics for the AbstractButton or * their subclasses. We must copy necessary code from org.openide.awt.Mnemonics * because org.openide.awt module is not available yet when this code is called. * @param item AbstractButton * @param text new label */ static void setLocalizedText (AbstractButton button, String text) { if (text == null) { button.setText(null); return; } int i = findMnemonicAmpersand(text); if (i < 0) { // no '&' - don't set the mnemonic button.setText(text); button.setMnemonic(0); } else { button.setText(text.substring(0, i) + text.substring(i + 1)); if (Utilities.isMac()) { // there shall be no mnemonics on macosx. //#55864 return; } char ch = text.charAt(i + 1); // it's latin character or arabic digit, // setting it as mnemonics button.setMnemonic(ch); // If it's something like "Save &As", we need to set another // mnemonic index (at least under 1.4 or later) // see #29676 button.setDisplayedMnemonicIndex(i); } }
Example 14
Source File: PlatformUtil.java From keystore-explorer with GNU General Public License v3.0 | 5 votes |
/** * Set mnemonic on button in a platform dependant manner. * * @param button * Button * @param mnemonic * Mnemonic * @param index * Index of string to underline */ public static void setMnemonic(AbstractButton button, char mnemonic, int index) { /* * Only set mnemonic if not using macOS - they are not recommended by * the style guidelines there and clash with established commands */ if (!OperatingSystem.isMacOs()) { button.setMnemonic(mnemonic); if (index >= 0) { button.setDisplayedMnemonicIndex(index); } } }
Example 15
Source File: ServiceConfigurationPane.java From attic-polygene-java with Apache License 2.0 | 5 votes |
private void $$$loadButtonText$$$( AbstractButton component, String text ) { StringBuffer result = new StringBuffer(); boolean haveMnemonic = false; char mnemonic = '\0'; int mnemonicIndex = -1; for( int i = 0; i < text.length(); i++ ) { if( text.charAt( i ) == '&' ) { i++; if( i == text.length() ) { break; } if( !haveMnemonic && text.charAt( i ) != '&' ) { haveMnemonic = true; mnemonic = text.charAt( i ); mnemonicIndex = result.length(); } } result.append( text.charAt( i ) ); } component.setText( result.toString() ); if( haveMnemonic ) { component.setMnemonic( mnemonic ); component.setDisplayedMnemonicIndex( mnemonicIndex ); } }
Example 16
Source File: AnnotatedString.java From spotbugs with GNU Lesser General Public License v2.1 | 3 votes |
/** * Localise the given AbstractButton, setting the text and optionally * mnemonic Note that AbstractButton includes menus and menu items. * * @param button * The button to localise * @param key * The key to look up in resource bundle * @param defaultString * default String to use if key not found * @param setMnemonic * whether or not to set the mnemonic. According to Sun's * guidelines, default/cancel buttons should not have mnemonics * but instead should use Return/Escape */ public static void localiseButton(AbstractButton button, String key, String defaultString, boolean setMnemonic) { AnnotatedString as = new AnnotatedString(L10N.getLocalString(key, defaultString)); button.setText(as.toString()); int mnemonic; if (setMnemonic && (mnemonic = as.getMnemonic()) != KeyEvent.VK_UNDEFINED) { button.setMnemonic(mnemonic); button.setDisplayedMnemonicIndex(as.getMnemonicIndex()); } }