Has JideToggleSplitButton ever worked for anybody?

This is the forum for JIDE Common Layer which is open sourced at https://github.com/jidesoft/jide-oss. Please note, JIDE technical support doesn't monitor this forum as often as other forums. Please consider subscribe for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Moderator: JIDE Support

Forum rules
Community driven forum for open source JIDE Common Layer. JIDE technical support doesn't monitor this forum as often as other forums. If you only use JIDE Common Layer, please consider subscribing for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Has JideToggleSplitButton ever worked for anybody?

Postby eiro7Xoo » Wed Dec 03, 2008 3:31 am

Today I tried JideToggleSplitButton (JIDE 1.9.3), and the toggle/untoggle functionality does not work. So I downloaded the most recent stable version 2.4, to see whether it has been fixed already. Apparently not.

Here's the code to reproduce, further down I have a (quick and dirty) fix. Just execute the main method and click the buttons, only one should be active at any time, as they are toggle buttons in a button group. If it looks weird for you, good! You reproduced the bug.

Code: Select all
package com.jidesoft.swing;

import javax.swing.*;
import java.awt.*;

public class JideToggleSplitButtonTest {


    public static void main(String[] args) throws Exception {

        JPanel panel = new JPanel();
        final ButtonGroup buttonGroup = new ButtonGroup();

        panel.add(t("b1", buttonGroup));
        panel.add(t("b2", buttonGroup));
        panel.add(t("b3", buttonGroup));

        JFrame frame = new JFrame("ToggleTest");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(panel, BorderLayout.NORTH);
        frame.pack();
        frame.setVisible(true);

    }

    private static AbstractButton t(String s, ButtonGroup bg) {
        JideToggleSplitButton b = new JideToggleSplitButton(s);
        b.setActionCommand(s);
        b.setFocusable(false);
        if (bg != null) bg.add(b);
        b.add(new JMenuItem(s + " menu"));
        return b;
    }

}


Add the following method to JideToggleSplitButton.ToggleSplitButtonModel and toggling/untoggling will work.

Code: Select all
/**
 * Calls from ButtonGroup will be redirected to setButtonSelected(boolean).
 * @param b true selects the menu (or toggle button if called from ButtonGroup), false deselects it
 */
@Override
public void setSelected(boolean b) {
    StackTraceElement[] stackFrame = Thread.currentThread().getStackTrace();
    for (int i = 0; i < 5 && i < stackFrame.length; i++) {
        if ("javax.swing.ButtonGroup".equals(stackFrame[i].getClassName())) {
            setButtonSelected(b);
            return;
        }
    }
    super.setSelected(b);
}


It's ugly, but due to the ambiguity of setSelected (MenuItem vs. Button) I don't know whether there's an easy cleaner fix. Neither did I do extensive tests for side effects and regression. Maybe someone familiar with Jide/Swing internals can share their view on this or propose a better solution.
eiro7Xoo
 
Posts: 4
Joined: Wed Dec 03, 2008 3:02 am

Re: Has JideToggleSplitButton ever worked for anybody?

Postby JIDE Support » Wed Dec 03, 2008 10:42 am

You need to use SplitButtonGroup instead of ButtonGroup for JideSplitButtons.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Has JideToggleSplitButton ever worked for anybody?

Postby eiro7Xoo » Wed Dec 03, 2008 5:40 pm

Now that was easy. Thanks.

Where is this documented? I guess it would make sense to add a little heads-up to the class documentation of JideToggleSplitButton so other people don't have to spend hours of head scratching, googling, checking out the most recent sources, debugging, work-arounding etc. Something like this would have done it for me:

Code: Select all
/**
 * An implementation of a two-state JideButton.
 * <p>
 * <strong>Warning:</strong>
 * {@code SplitButtonGroup} has to be used in place of {@code ButtonGroup} for {@code JideToggleSplitButton}s.
 */
eiro7Xoo
 
Posts: 4
Joined: Wed Dec 03, 2008 3:02 am

Re: Has JideToggleSplitButton ever worked for anybody?

Postby JIDE Support » Wed Dec 03, 2008 6:02 pm

The javadoc of SplitButtonGroup mentioned but we should add it to JideSplitButton. I will do that.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Has JideToggleSplitButton ever worked for anybody?

Postby eiro7Xoo » Wed Dec 03, 2008 6:19 pm

You mean "we should add it to JideToggleSplitButton", I guess.
eiro7Xoo
 
Posts: 4
Joined: Wed Dec 03, 2008 3:02 am

Re: Has JideToggleSplitButton ever worked for anybody?

Postby JIDE Support » Wed Dec 03, 2008 7:33 pm

That's correct.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Has JideToggleSplitButton ever worked for anybody?

Postby JIDE Support » Thu Dec 04, 2008 12:38 pm

Just so you know, the javadoc is added in 2.4.6 which is just released.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Has JideToggleSplitButton ever worked for anybody?

Postby eiro7Xoo » Thu Dec 04, 2008 5:04 pm

Thanks.
eiro7Xoo
 
Posts: 4
Joined: Wed Dec 03, 2008 3:02 am


Return to JIDE Common Layer Open Source Project Discussion (Community Driven)

Who is online

Users browsing this forum: No registered users and 9 guests