1 package org.columba.core.gui.base; 17 18 import javax.swing.AbstractButton ; 19 import javax.swing.JLabel ; 20 21 32 public class MnemonicSetter { 33 43 public static void setTextWithMnemonic(AbstractButton component, String text) { 44 int index = text.indexOf("&"); 46 47 if ((index != -1) && ((index + 1) < text.length())) { 48 char mnemonic = text.charAt(index + 1); 51 52 StringBuffer buf = new StringBuffer (); 53 54 if (index == 0) { 56 buf.append(text.substring(1)); 57 } else { 58 buf.append(text.substring(0, index)); 59 buf.append(text.substring(index + 1)); 60 } 61 62 component.setText(buf.toString()); 64 65 component.setMnemonic(mnemonic); 67 component.setDisplayedMnemonicIndex(index); 68 } else { 69 component.setText(text); 71 } 72 } 73 74 85 public static void setTextWithMnemonic(JLabel label, String text) { 86 int index = text.indexOf("&"); 88 89 if ((index != -1) && ((index + 1) < text.length())) { 90 char mnemonic = text.charAt(index + 1); 93 94 StringBuffer buf = new StringBuffer (); 95 96 if (index == 0) { 98 buf.append(text.substring(1)); 99 } else { 100 buf.append(text.substring(0, index)); 101 buf.append(text.substring(index + 1)); 102 } 103 104 label.setText(buf.toString()); 106 107 label.setDisplayedMnemonic(mnemonic); 109 label.setDisplayedMnemonicIndex(index); 110 } else { 111 label.setText(text); 113 } 114 } 115 } 116 | Popular Tags |