CheckBoxListComboBox with custom keystroke

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.

CheckBoxListComboBox with custom keystroke

Postby td84 » Wed Sep 07, 2016 7:54 am

Hello,

i'm trying to extend the class CheckBoxListComboBox, so if someone opens the list and presses CTRL+A, then all of the items in the list gets selected:
i mean all of the items will have a blue background and all of the checkboxes gets selected like on the picture.
The functionality with the whitespace should not change: after pressing CTRL+A pressing the whitespace should select/deselect all of the items.

My try was the following code fragment, but this doesn't even reacts to CTRL+A:

Code: Select all
      String[] _content = new String[]{"One", "Two", "Three", "Four", "Five"};
      Action action = new AbstractAction("selectall") {
         private static final long serialVersionUID = 1L;
         
         @Override public void actionPerformed(ActionEvent evt) {
            System.out.format("\n-->CBoxListComboBox: selecting all...\n");
            setSelectedObjects(_content);
          }
      };
      
      String key = "select_all";
      this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_A,  InputEvent.CTRL_DOWN_MASK), key);
      this.getActionMap().put(key, action);


Can you help me to implement this?

Thanx in advance,
Daniel
Attachments
cbox.jpg
cbox.jpg (5.02 KiB) Viewed 31862 times
td84
 
Posts: 32
Joined: Tue Dec 08, 2015 4:02 pm

Re: CheckBoxListComboBox with custom keystroke

Postby JIDE Support » Wed Sep 07, 2016 9:20 am

What exactly is the problem? I tried in CheckBoxListExComboBox. I can Ctrl-A to select all items and press SPACE to check all of them.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: CheckBoxListComboBox with custom keystroke

Postby td84 » Wed Sep 07, 2016 1:18 pm

Yes you've right. But what i would like to have is to select AND check all of them by pressing CTRL+A without to pressing the SPACE.
And a subsequent SPACE unchecks all of them.

Thanx,
Daniel
td84
 
Posts: 32
Joined: Tue Dec 08, 2015 4:02 pm

Re: CheckBoxListComboBox with custom keystroke

Postby JIDE Support » Wed Sep 07, 2016 1:28 pm

If you modify the action map on on the CheckBoxList directly, it should work. There is already an entry for Ctrl-A on InputMap so you don't need to change anything. Add an action listener for "selectAll" should be good enough to modify this behavior.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: CheckBoxListComboBox with custom keystroke

Postby td84 » Thu Sep 08, 2016 3:08 am

JIDE Support wrote:If you modify the action map on on the CheckBoxList directly, it should work. There is already an entry for Ctrl-A on InputMap so you don't need to change anything. Add an action listener for "selectAll" should be good enough to modify this behavior.


I wrote the following, but it reacts only to actions, if cmd=comboBoxChanged.
It seems, that InputMap and ActionMap hold no mappings (see System.out.format).

Code: Select all
public class MyCheckBoxListComboBox extends CheckBoxListComboBox {
   private String[] _content;


   public MyCheckBoxListComboBox(String[] content) {
      super(content, String[].class);
      _content = content;
      
      Action action = new AbstractAction("selectall") {
         @Override public void actionPerformed(ActionEvent evt) {
            System.out.format("\n-->CBoxListComboBox:  [%s]\n", evt);
            //only this action is catched here:
            //  [java.awt.event.ActionEvent[ACTION_PERFORMED,cmd=comboBoxChanged,when=1473328412049,modifiers=]
            setSelectedObjects(_content);
          }
      };
      this.addActionListener( action );
      System.out.format("\n-->InputMap - keys:\n[%s]\n\n",  (Object[])this.getInputMap().allKeys());  //no mapping
      System.out.format("\n-->ActionMap - keys:\n[%s]\n\n",  (Object[])this.getActionMap().allKeys()); //no mapping
   }
}


Could you give some hint?

Thank you in advance,
Daniel

EDIT: i tryed also with this.addKeyListener() and to override processKeyEvent() but i can't catch CTRL+A.
td84
 
Posts: 32
Joined: Tue Dec 08, 2015 4:02 pm

Re: CheckBoxListComboBox with custom keystroke

Postby JIDE Support » Thu Sep 08, 2016 8:38 am

I refer to the CheckBoxList, not CheckBoxListExComboBox, which will has the InputMap.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: CheckBoxListComboBox with custom keystroke

Postby td84 » Thu Sep 08, 2016 8:50 am

JIDE Support wrote:I refer to the CheckBoxList, not CheckBoxListExComboBox, which will has the InputMap.


Ok, thanx. But how can i realize this with CheckBoxListExComboBox?
td84
 
Posts: 32
Joined: Tue Dec 08, 2015 4:02 pm

Re: CheckBoxListComboBox with custom keystroke

Postby JIDE Support » Thu Sep 08, 2016 12:23 pm

You can override setupList method on CheckBoxListExComboBox to get access to the CheckBoxList.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am


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

Who is online

Users browsing this forum: No registered users and 10 guests