Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Arrow key functionality in the ButtonGroup

24 views
Skip to first unread message

srinivas...@gmail.com

unread,
Jul 27, 2006, 1:54:37 AM7/27/06
to
Hi All,

I added 4 JRadio buttons to ButtonGroup. For these radio buttons i am
unable to achieve the arrow key functionality. here i am attaching the
code

rateList = theController.getDeleteOptionList();
for (int i = 0, j = 1; i < rateList.size(); i++) {
ListElement listRb = (ListElement) rateList.get(i);
JRadioButton radioBtn = new JRadioButton(listRb.getTextValue());
radioBtn.setActionCommand(listRb.getTextValue());
radioBtn.addActionListener(actionclass);
deleteButtonGrp.add(radioBtn);
}

Thanks for ur help in advance...

Srinivas.

Andrew Thompson

unread,
Jul 27, 2006, 5:27:05 AM7/27/06
to
srinivas...@gmail.com wrote:
..

> I added 4 JRadio buttons to ButtonGroup. For these radio buttons i am
> unable to achieve the arrow key functionality. here i am attaching the
> code

Here is compilable code..

<sscce>
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

public class ArrowKeyNavigation {

public static void main(String[] args) {
JFrame f = new JFrame("ButtonGroupNavigation");
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

/* from
http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html
*/
Set forwardKeys = f.getFocusTraversalKeys(
KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
Set newForwardKeys = new HashSet(forwardKeys);
newForwardKeys.add(
KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));
f.setFocusTraversalKeys(
KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
newForwardKeys);

Set backwardKeys = f.getFocusTraversalKeys(
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
Set newBackwardKeys = new HashSet(backwardKeys);
newBackwardKeys.add(
KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0));
f.setFocusTraversalKeys(
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
newBackwardKeys);

Container c = f.getContentPane();
c.setLayout(new GridLayout(1,0));

ButtonGroup bg = new ButtonGroup();
for (int ii=0; ii<4; ii++) {
JRadioButton b = new JRadioButton("Btn " + ii);
bg.add( b );
c.add( b );
}

f.pack();
f.setVisible(true);
}
}
</sscce>

HTH

Andrew T.

0 new messages