KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > adminGui > widget > QuickButton


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: QuickButton.java,v 1.1 2003/03/24 08:36:56 per_nyfelt Exp $
8
package org.ozoneDB.adminGui.widget;
9
10 import javax.swing.*;
11 import java.awt.event.ActionListener JavaDoc;
12
13 /**
14  *
15  * A JButton with some extra constructors making usage more easier
16  */

17 public class QuickButton extends JButton {
18
19     public QuickButton(String JavaDoc text) {
20         super();
21         this.setText(text);
22     }
23
24     public QuickButton(String JavaDoc text, ActionListener JavaDoc ae) {
25         this(text);
26         addActionListener(ae);
27     }
28
29     public void setText(String JavaDoc text) {
30         text = extractMnemonic(text);
31         super.setText(text);
32     }
33
34     private String JavaDoc extractMnemonic(String JavaDoc text) {
35         //Locate the '&' character
36
int ampersandIndex = text.indexOf("&");
37
38         //If mnemonic indicator return same localized text
39
if (ampersandIndex == -1) {
40             return text;
41         }
42
43         //Delete the '&' character
44
text = text.substring(0, ampersandIndex) + text.substring(ampersandIndex + 1);
45
46         //Set the mnemonic with the char after the ampersand
47
setMnemonic(text.charAt(ampersandIndex));
48
49         //return the text without the ampersand
50
return text;
51     }
52 }
Popular Tags