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 / July 2006

Tip: Looking for answers? Try searching our database.

Arrow key functionality in the ButtonGroup

Thread view: 
srinivas.veeranki@gmail.com - 27 Jul 2006 06:54 GMT
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 - 27 Jul 2006 10:27 GMT
..
> 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.


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.