1 package org.ozoneDB.adminGui.widget; 9 10 import javax.swing.*; 11 import java.awt.event.ActionListener ; 12 13 17 public class QuickButton extends JButton { 18 19 public QuickButton(String text) { 20 super(); 21 this.setText(text); 22 } 23 24 public QuickButton(String text, ActionListener ae) { 25 this(text); 26 addActionListener(ae); 27 } 28 29 public void setText(String text) { 30 text = extractMnemonic(text); 31 super.setText(text); 32 } 33 34 private String extractMnemonic(String text) { 35 int ampersandIndex = text.indexOf("&"); 37 38 if (ampersandIndex == -1) { 40 return text; 41 } 42 43 text = text.substring(0, ampersandIndex) + text.substring(ampersandIndex + 1); 45 46 setMnemonic(text.charAt(ampersandIndex)); 48 49 return text; 51 } 52 } | Popular Tags |