swingx
  1. swingx
  2. SWINGX-1404

Problem with stateful bound actions (StackOverFlow)

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.6.2
    • Fix Version/s: 1.6.6
    • Component/s: Action
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      6

      Description

      //Click twice on "Refresh" button (it will refresh the tool bar twice)
      //Click on one of the tool bar button (eg "ChoiceA")
      //It will throw the exception

      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.util.Arrays;

      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JToolBar;

      import org.jdesktop.swingx.action.ActionManager;
      import org.jdesktop.swingx.action.BoundAction;

      public class DynamicToolBarTest {

      public static void main(String[] args) {
      new DynamicToolBarTest().start();
      }

      ActionManager am = new ActionManager();
      JToolBar bar = null;

      DynamicToolBarTest(){
      initActionManager();

      bar = am.getFactory().createToolBar(
      Arrays.asList(new String []

      {"ba", "bb"}

      ));
      }

      private void initActionManager(){
      BoundAction ba = new BoundAction("ChoiceA");
      BoundAction bb = new BoundAction("ChoiceB");
      ba.registerCallback(this, "test");
      bb.registerCallback(this, "test");
      ba.setStateAction();
      ba.setSelected(true);
      bb.setStateAction();
      String group = "agroup";

      ba.setGroup(group);
      bb.setGroup(group);

      am.addAction("ba", ba);
      am.addAction("bb", bb);
      }

      public void test(){}

      private void start(){
      JFrame f = createFrame();
      f.getContentPane().add(bar, "North");
      JButton brefresh = new JButton("Refresh");
      brefresh.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e) {
      refreshToolBar();
      }
      });
      f.getContentPane().add(brefresh, "South");
      f.setVisible(true);
      }

      private void refreshToolBar(){
      bar.removeAll();
      bar.add(am.getFactory().createButton(am.getAction("ba")));
      bar.add(am.getFactory().createButton(am.getAction("bb")));
      }

      private static JFrame createFrame(){
      JFrame f = new JFrame();
      f.setSize(400, 400);
      f.setLocationRelativeTo(null);
      return f;
      }
      }

        Activity

        Hide
        kleopatra added a comment -

        just want to add a link to the related forum thread:
        http://forums.java.net/jive/thread.jspa?threadID=13327

        and copy my initial evaluation from there (so I don't forget that it -
        "Hmm, weird ... additionally, the selected isn't updated reliably after a
        refreshToolBar(). Seems to be related to grouping the actions - which is not yet
        tested"

        Thanks
        Jeanette

        Show
        kleopatra added a comment - just want to add a link to the related forum thread: http://forums.java.net/jive/thread.jspa?threadID=13327 and copy my initial evaluation from there (so I don't forget that it - "Hmm, weird ... additionally, the selected isn't updated reliably after a refreshToolBar(). Seems to be related to grouping the actions - which is not yet tested" Thanks Jeanette
        Hide
        Karl Schaefer added a comment -

        The problem is that we do not evict components from the button group, when they are removed from their container. We also never test to see if the same action is already listed in that container (probably only necessary for state actions).

        Show
        Karl Schaefer added a comment - The problem is that we do not evict components from the button group, when they are removed from their container. We also never test to see if the same action is already listed in that container (probably only necessary for state actions).

          People

          • Assignee:
            Karl Schaefer
            Reporter:
            elbedr
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: