Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2005

Tip: Looking for answers? Try searching our database.

JOptionPane custom options - button mnemonics

Thread view: 
Stanimir Stamenkov - 22 Mar 2005 13:13 GMT
I've searched the archives but I haven't found anything particular
dealing with this issue.

I want to set mnemonics for the buttons representing custom supplied
options when creating a JOptionPane, like:

    String options = { "Abort", "Continue" };
    JOptionPane.showOptionDialog(parentComponent,
            message, title, JOptionPane.YES_NO_OPTION,
            JOptionPane.WARNING, null, options, options[0]);

I've though of supplying JButton option instances for the options
but then I'm loosing the default button action handling and the
default button look&feel is different from the one seen in a default
JOptionPane.

Is there more convenient way than supplying custom buttons as
options to achieve setting mnemonics on the rendered default buttons?

Signature

Stanimir

Stanimir Stamenkov - 22 Mar 2005 13:41 GMT
/Stanimir Stamenkov/:

> I want to set mnemonics for the buttons representing custom supplied
> options when creating a JOptionPane, like:
[quoted text clipped - 3 lines]
>             message, title, JOptionPane.YES_NO_OPTION,
>             JOptionPane.WARNING, null, options, options[0]);

O.k. I've just found interesting article:

"Add Mnemonics to Inaccessible Buttons Within a Component"
<http://www.devx.com/tips/Tip/13718>

Other suggestions/pointers are welcome. :-)

Signature

Stanimir

Stanimir Stamenkov - 22 Mar 2005 14:08 GMT
/Stanimir Stamenkov/:

> O.k. I've just found interesting article:
>
> "Add Mnemonics to Inaccessible Buttons Within a Component"
> <http://www.devx.com/tips/Tip/13718>

I've made somewhat tidier variant:

    /**
     * @param  mnemonics  Mappings between button labels and the
     *         corresponding key codes representing the mnemonics.
     */
    static void addMnemonicsToButtons(Container parentComponent,
                                      Map mnemonics)
    {
        Component[] components = parentComponent.getComponents();
        for (int i = 0; i < components.length; i++) {
            if (components[i] instanceof AbstractButton) {
                AbstractButton button =
                        (AbstractButton) components[i];
                String label = button.getText();
                if (mnemonics.containsKey(label)) {
                    int m = ((Integer) mnemonics.get(label))
                            .intValue();
                    button.setMnemonic(m);
                }
            } else if (components[i] instanceof Container) {
                addMnemonicsToButtons((Container) components[i],
                                      mnemonics);
            }
        }
    }

Signature

Stanimir



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.