This is a JPanel subclass which provides a special functionality for its children buttons components. It makes it possible to transfer focus from button to button with help of arrows keys.
The following example shows how to enable cyclic focus transferimport org.jdesktop.swinghelper.buttonpanel.*; import javax.swing.*; public class SimpleDemo { public static void main( String[] args ) throws Exception { SwingUtilities.invokeLater( new Runnable() { public void run() { final JFrame frame = new JFrame(); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); JXButtonPanel panel = new JXButtonPanel(); panel.setCyclic( true ); panel.add( new JButton( "One" ) ); panel.add( new JButton( "Two" ) ); panel.add( new JButton( "Three" ) ); frame.add( panel ); frame.setSize( 200, 200 ); frame.setLocationRelativeTo( null ); frame.setVisible( true ); } } ); } }If your buttons inside JXButtonPanel are added to one ButtonGroup arrow keys will transfer selection between them as well as they do it for focus Note: you can control this behaviour with setGroupSelectionFollowFocus(boolean)
import org.jdesktop.swinghelper.buttonpanel.*; import javax.swing.*; public class RadioButtonDemo { public static void main( String[] args ) throws Exception { SwingUtilities.invokeLater( new Runnable() { public void run() { final JFrame frame = new JFrame(); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); JXButtonPanel panel = new JXButtonPanel(); ButtonGroup group = new ButtonGroup(); JRadioButton rb1 = new JRadioButton( "One" ); panel.add( rb1 ); group.add( rb1 ); JRadioButton rb2 = new JRadioButton( "Two" ); panel.add( rb2 ); group.add( rb2 ); JRadioButton rb3 = new JRadioButton( "Three" ); panel.add( rb3 ); group.add( rb3 ); rb1.setSelected( true ); frame.add( panel ); frame.setSize( 200, 200 ); frame.setLocationRelativeTo( null ); frame.setVisible( true ); } } ); } }
Fields inherited from class | Fields |
---|---|
class javax.swing.JPanel |
WHEN_FOCUSED, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_IN_FOCUSED_WINDOW, UNDEFINED_CONDITION, TOOL_TIP_TEXT_KEY, TOP_ALIGNMENT, CENTER_ALIGNMENT, BOTTOM_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, WIDTH, HEIGHT, PROPERTIES, SOMEBITS, FRAMEBITS, ALLBITS, ERROR, ABORT |
Constructor and description |
---|
JXButtonPanel
() {@inheritDoc} |
JXButtonPanel
(java.awt.LayoutManager layout) {@inheritDoc} |
JXButtonPanel
(boolean isDoubleBuffered) {@inheritDoc} |
JXButtonPanel
(java.awt.LayoutManager layout, boolean isDoubleBuffered) {@inheritDoc} |
Type Params | Return Type | Name and description |
---|---|---|
|
boolean |
isCyclic() Returns whether arrow keys should support cyclic focus traversal ordering for for this JXButtonPanel. |
|
boolean |
isGroupSelectionFollowFocus() Returns whether arrow keys should transfer button's selection as well as focus for this JXButtonPanel. |
|
void |
setCyclic(boolean isCyclic) Sets whether arrow keys should support cyclic focus traversal ordering for this JXButtonPanel. |
|
void |
setGroupSelectionFollowFocus(boolean groupSelectionFollowFocus) Sets whether arrow keys should transfer button's selection as well as focus for this JXButtonPanel. |
Methods inherited from class | Name |
---|---|
class javax.swing.JPanel |
javax.swing.JPanel#setUI(javax.swing.plaf.PanelUI), javax.swing.JPanel#updateUI(), javax.swing.JPanel#getUIClassID(), javax.swing.JPanel#getUI(), javax.swing.JPanel#getUI(), javax.swing.JPanel#getAccessibleContext(), javax.swing.JPanel#update(java.awt.Graphics), javax.swing.JPanel#contains(int, int), javax.swing.JPanel#getBounds(java.awt.Rectangle), javax.swing.JPanel#getLocation(java.awt.Point), javax.swing.JPanel#print(java.awt.Graphics), javax.swing.JPanel#getSize(java.awt.Dimension), javax.swing.JPanel#setOpaque(boolean), javax.swing.JPanel#isOpaque(), javax.swing.JPanel#enable(), javax.swing.JPanel#setEnabled(boolean), javax.swing.JPanel#addAncestorListener(javax.swing.event.AncestorListener), javax.swing.JPanel#firePropertyChange(java.lang.String, boolean, boolean), javax.swing.JPanel#firePropertyChange(java.lang.String, char, char), javax.swing.JPanel#firePropertyChange(java.lang.String, int, int), javax.swing.JPanel#getListeners(java.lang.Class), javax.swing.JPanel#getClientProperty(java.lang.Object), javax.swing.JPanel#setInheritsPopupMenu(boolean), javax.swing.JPanel#getInheritsPopupMenu(), javax.swing.JPanel#setComponentPopupMenu(javax.swing.JPopupMenu), javax.swing.JPanel#getComponentPopupMenu(), javax.swing.JPanel#paint(java.awt.Graphics), javax.swing.JPanel#printAll(java.awt.Graphics), javax.swing.JPanel#isPaintingTile(), javax.swing.JPanel#isPaintingForPrint(), javax.swing.JPanel#isManagingFocus(), javax.swing.JPanel#setNextFocusableComponent(java.awt.Component), javax.swing.JPanel#getNextFocusableComponent(), javax.swing.JPanel#setRequestFocusEnabled(boolean), javax.swing.JPanel#isRequestFocusEnabled(), javax.swing.JPanel#requestFocus(), javax.swing.JPanel#requestFocus(boolean), javax.swing.JPanel#requestFocusInWindow(), javax.swing.JPanel#grabFocus(), javax.swing.JPanel#setVerifyInputWhenFocusTarget(boolean), javax.swing.JPanel#getVerifyInputWhenFocusTarget(), javax.swing.JPanel#getFontMetrics(java.awt.Font), javax.swing.JPanel#setPreferredSize(java.awt.Dimension), javax.swing.JPanel#getPreferredSize(), javax.swing.JPanel#setMaximumSize(java.awt.Dimension), javax.swing.JPanel#getMaximumSize(), javax.swing.JPanel#setMinimumSize(java.awt.Dimension), javax.swing.JPanel#getMinimumSize(), javax.swing.JPanel#setBorder(javax.swing.border.Border), javax.swing.JPanel#getBorder(), javax.swing.JPanel#getInsets(), javax.swing.JPanel#getInsets(java.awt.Insets), javax.swing.JPanel#getAlignmentY(), javax.swing.JPanel#setAlignmentY(float), javax.swing.JPanel#getAlignmentX(), javax.swing.JPanel#setAlignmentX(float), javax.swing.JPanel#setInputVerifier(javax.swing.InputVerifier), javax.swing.JPanel#getInputVerifier(), javax.swing.JPanel#getGraphics(), javax.swing.JPanel#setDebugGraphicsOptions(int), javax.swing.JPanel#getDebugGraphicsOptions(), javax.swing.JPanel#registerKeyboardAction(java.awt.event.ActionListener, javax.swing.KeyStroke, int), javax.swing.JPanel#registerKeyboardAction(java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int), javax.swing.JPanel#unregisterKeyboardAction(javax.swing.KeyStroke), javax.swing.JPanel#getRegisteredKeyStrokes(), javax.swing.JPanel#getConditionForKeyStroke(javax.swing.KeyStroke), javax.swing.JPanel#getActionForKeyStroke(javax.swing.KeyStroke), javax.swing.JPanel#resetKeyboardActions(), javax.swing.JPanel#setInputMap(int, javax.swing.InputMap), javax.swing.JPanel#getInputMap(), javax.swing.JPanel#getInputMap(int), javax.swing.JPanel#setActionMap(javax.swing.ActionMap), javax.swing.JPanel#getActionMap(), javax.swing.JPanel#getBaseline(int, int), javax.swing.JPanel#getBaselineResizeBehavior(), javax.swing.JPanel#requestDefaultFocus(), javax.swing.JPanel#setVisible(boolean), javax.swing.JPanel#setForeground(java.awt.Color), javax.swing.JPanel#setBackground(java.awt.Color), javax.swing.JPanel#setFont(java.awt.Font), javax.swing.JPanel#getDefaultLocale(), javax.swing.JPanel#setDefaultLocale(java.util.Locale), javax.swing.JPanel#setToolTipText(java.lang.String), javax.swing.JPanel#getToolTipText(java.awt.event.MouseEvent), javax.swing.JPanel#getToolTipText(), javax.swing.JPanel#getToolTipLocation(java.awt.event.MouseEvent), javax.swing.JPanel#getPopupLocation(java.awt.event.MouseEvent), javax.swing.JPanel#createToolTip(), javax.swing.JPanel#scrollRectToVisible(java.awt.Rectangle), javax.swing.JPanel#setAutoscrolls(boolean), javax.swing.JPanel#getAutoscrolls(), javax.swing.JPanel#setTransferHandler(javax.swing.TransferHandler), javax.swing.JPanel#getTransferHandler(), javax.swing.JPanel#disable(), javax.swing.JPanel#putClientProperty(java.lang.Object, java.lang.Object), javax.swing.JPanel#setFocusTraversalKeys(int, java.util.Set), javax.swing.JPanel#isLightweightComponent(java.awt.Component), javax.swing.JPanel#reshape(int, int, int, int), javax.swing.JPanel#getX(), javax.swing.JPanel#getY(), javax.swing.JPanel#getWidth(), javax.swing.JPanel#getHeight(), javax.swing.JPanel#computeVisibleRect(java.awt.Rectangle), javax.swing.JPanel#getVisibleRect(), javax.swing.JPanel#addVetoableChangeListener(java.beans.VetoableChangeListener), javax.swing.JPanel#removeVetoableChangeListener(java.beans.VetoableChangeListener), javax.swing.JPanel#getVetoableChangeListeners(), javax.swing.JPanel#getTopLevelAncestor(), javax.swing.JPanel#removeAncestorListener(javax.swing.event.AncestorListener), javax.swing.JPanel#getAncestorListeners(), javax.swing.JPanel#addNotify(), javax.swing.JPanel#removeNotify(), javax.swing.JPanel#repaint(java.awt.Rectangle), javax.swing.JPanel#repaint(long, int, int, int, int), javax.swing.JPanel#revalidate(), javax.swing.JPanel#isValidateRoot(), javax.swing.JPanel#isOptimizedDrawingEnabled(), javax.swing.JPanel#paintImmediately(java.awt.Rectangle), javax.swing.JPanel#paintImmediately(int, int, int, int), javax.swing.JPanel#setDoubleBuffered(boolean), javax.swing.JPanel#isDoubleBuffered(), javax.swing.JPanel#getRootPane(), javax.swing.JPanel#hide(), javax.swing.JPanel#add(java.awt.Component), javax.swing.JPanel#add(java.lang.String, java.awt.Component), javax.swing.JPanel#add(java.awt.Component, java.lang.Object), javax.swing.JPanel#add(java.awt.Component, int), javax.swing.JPanel#add(java.awt.Component, java.lang.Object, int), javax.swing.JPanel#remove(java.awt.Component), javax.swing.JPanel#remove(int), javax.swing.JPanel#list(java.io.PrintWriter, int), javax.swing.JPanel#list(java.io.PrintStream, int), javax.swing.JPanel#validate(), javax.swing.JPanel#removeAll(), javax.swing.JPanel#invalidate(), javax.swing.JPanel#addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener), javax.swing.JPanel#addPropertyChangeListener(java.beans.PropertyChangeListener), javax.swing.JPanel#preferredSize(), javax.swing.JPanel#minimumSize(), javax.swing.JPanel#insets(), javax.swing.JPanel#isFocusCycleRoot(java.awt.Container), javax.swing.JPanel#isFocusCycleRoot(), javax.swing.JPanel#getFocusTraversalPolicy(), javax.swing.JPanel#setFocusTraversalPolicy(java.awt.FocusTraversalPolicy), javax.swing.JPanel#countComponents(), javax.swing.JPanel#setComponentZOrder(java.awt.Component, int), javax.swing.JPanel#getComponentZOrder(java.awt.Component), javax.swing.JPanel#getLayout(), javax.swing.JPanel#setLayout(java.awt.LayoutManager), javax.swing.JPanel#doLayout(), javax.swing.JPanel#layout(), javax.swing.JPanel#paintComponents(java.awt.Graphics), javax.swing.JPanel#printComponents(java.awt.Graphics), javax.swing.JPanel#addContainerListener(java.awt.event.ContainerListener), javax.swing.JPanel#removeContainerListener(java.awt.event.ContainerListener), javax.swing.JPanel#getContainerListeners(), javax.swing.JPanel#deliverEvent(java.awt.Event), javax.swing.JPanel#locate(int, int), javax.swing.JPanel#getMousePosition(boolean), javax.swing.JPanel#findComponentAt(java.awt.Point), javax.swing.JPanel#findComponentAt(int, int), javax.swing.JPanel#isAncestorOf(java.awt.Component), javax.swing.JPanel#getFocusTraversalKeys(int), javax.swing.JPanel#areFocusTraversalKeysSet(int), javax.swing.JPanel#isFocusTraversalPolicySet(), javax.swing.JPanel#setFocusCycleRoot(boolean), javax.swing.JPanel#setFocusTraversalPolicyProvider(boolean), javax.swing.JPanel#isFocusTraversalPolicyProvider(), javax.swing.JPanel#transferFocusDownCycle(), javax.swing.JPanel#applyComponentOrientation(java.awt.ComponentOrientation), javax.swing.JPanel#getComponentCount(), javax.swing.JPanel#getComponent(int), javax.swing.JPanel#getComponents(), javax.swing.JPanel#getComponentAt(java.awt.Point), javax.swing.JPanel#getComponentAt(int, int), javax.swing.JPanel#add(java.awt.PopupMenu), javax.swing.JPanel#remove(java.awt.MenuComponent), javax.swing.JPanel#toString(), javax.swing.JPanel#getName(), javax.swing.JPanel#contains(java.awt.Point), javax.swing.JPanel#list(), javax.swing.JPanel#list(java.io.PrintStream), javax.swing.JPanel#list(java.io.PrintWriter), javax.swing.JPanel#size(), javax.swing.JPanel#bounds(), javax.swing.JPanel#getBounds(), javax.swing.JPanel#getParent(), javax.swing.JPanel#getLocation(), javax.swing.JPanel#action(java.awt.Event, java.lang.Object), javax.swing.JPanel#setName(java.lang.String), javax.swing.JPanel#location(), javax.swing.JPanel#getSize(), javax.swing.JPanel#resize(int, int), javax.swing.JPanel#resize(java.awt.Dimension), javax.swing.JPanel#setSize(java.awt.Dimension), javax.swing.JPanel#setSize(int, int), javax.swing.JPanel#move(int, int), javax.swing.JPanel#setLocale(java.util.Locale), javax.swing.JPanel#getLocale(), javax.swing.JPanel#isEnabled(), javax.swing.JPanel#enable(boolean), javax.swing.JPanel#isValid(), javax.swing.JPanel#firePropertyChange(java.lang.String, float, float), javax.swing.JPanel#firePropertyChange(java.lang.String, double, double), javax.swing.JPanel#firePropertyChange(java.lang.String, short, short), javax.swing.JPanel#firePropertyChange(java.lang.String, byte, byte), javax.swing.JPanel#firePropertyChange(java.lang.String, long, long), javax.swing.JPanel#removePropertyChangeListener(java.beans.PropertyChangeListener), javax.swing.JPanel#removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener), javax.swing.JPanel#requestFocus(java.awt.event.FocusEvent$Cause), javax.swing.JPanel#requestFocusInWindow(java.awt.event.FocusEvent$Cause), javax.swing.JPanel#repaint(int, int, int, int), javax.swing.JPanel#repaint(), javax.swing.JPanel#repaint(long), javax.swing.JPanel#nextFocus(), javax.swing.JPanel#getForeground(), javax.swing.JPanel#getFont(), javax.swing.JPanel#getTreeLock(), javax.swing.JPanel#isVisible(), javax.swing.JPanel#getFocusCycleRootAncestor(), javax.swing.JPanel#isDisplayable(), javax.swing.JPanel#isPreferredSizeSet(), javax.swing.JPanel#isMaximumSizeSet(), javax.swing.JPanel#isMinimumSizeSet(), javax.swing.JPanel#getBackground(), javax.swing.JPanel#isLightweight(), javax.swing.JPanel#setBounds(int, int, int, int), javax.swing.JPanel#setBounds(java.awt.Rectangle), javax.swing.JPanel#setLocation(java.awt.Point), javax.swing.JPanel#setLocation(int, int), javax.swing.JPanel#getPropertyChangeListeners(java.lang.String), javax.swing.JPanel#getPropertyChangeListeners(), javax.swing.JPanel#isShowing(), javax.swing.JPanel#getMousePosition(), javax.swing.JPanel#getGraphicsConfiguration(), javax.swing.JPanel#dispatchEvent(java.awt.AWTEvent), javax.swing.JPanel#isFocusable(), javax.swing.JPanel#isFocusOwner(), javax.swing.JPanel#transferFocus(), javax.swing.JPanel#postEvent(java.awt.Event), javax.swing.JPanel#transferFocusBackward(), javax.swing.JPanel#setDropTarget(java.awt.dnd.DropTarget), javax.swing.JPanel#getDropTarget(), javax.swing.JPanel#getToolkit(), javax.swing.JPanel#enableInputMethods(boolean), javax.swing.JPanel#show(boolean), javax.swing.JPanel#show(), javax.swing.JPanel#isForegroundSet(), javax.swing.JPanel#isBackgroundSet(), javax.swing.JPanel#isFontSet(), javax.swing.JPanel#getColorModel(), javax.swing.JPanel#getLocationOnScreen(), javax.swing.JPanel#setCursor(java.awt.Cursor), javax.swing.JPanel#getCursor(), javax.swing.JPanel#isCursorSet(), javax.swing.JPanel#paintAll(java.awt.Graphics), javax.swing.JPanel#imageUpdate(java.awt.Image, int, int, int, int, int), javax.swing.JPanel#createImage(java.awt.image.ImageProducer), javax.swing.JPanel#createImage(int, int), javax.swing.JPanel#createVolatileImage(int, int), javax.swing.JPanel#createVolatileImage(int, int, java.awt.ImageCapabilities), javax.swing.JPanel#prepareImage(java.awt.Image, int, int, java.awt.image.ImageObserver), javax.swing.JPanel#prepareImage(java.awt.Image, java.awt.image.ImageObserver), javax.swing.JPanel#checkImage(java.awt.Image, int, int, java.awt.image.ImageObserver), javax.swing.JPanel#checkImage(java.awt.Image, java.awt.image.ImageObserver), javax.swing.JPanel#setIgnoreRepaint(boolean), javax.swing.JPanel#getIgnoreRepaint(), javax.swing.JPanel#inside(int, int), javax.swing.JPanel#addComponentListener(java.awt.event.ComponentListener), javax.swing.JPanel#removeComponentListener(java.awt.event.ComponentListener), javax.swing.JPanel#getComponentListeners(), javax.swing.JPanel#addFocusListener(java.awt.event.FocusListener), javax.swing.JPanel#removeFocusListener(java.awt.event.FocusListener), javax.swing.JPanel#getFocusListeners(), javax.swing.JPanel#addHierarchyListener(java.awt.event.HierarchyListener), javax.swing.JPanel#removeHierarchyListener(java.awt.event.HierarchyListener), javax.swing.JPanel#getHierarchyListeners(), javax.swing.JPanel#addHierarchyBoundsListener(java.awt.event.HierarchyBoundsListener), javax.swing.JPanel#removeHierarchyBoundsListener(java.awt.event.HierarchyBoundsListener), javax.swing.JPanel#getHierarchyBoundsListeners(), javax.swing.JPanel#addKeyListener(java.awt.event.KeyListener), javax.swing.JPanel#removeKeyListener(java.awt.event.KeyListener), javax.swing.JPanel#getKeyListeners(), javax.swing.JPanel#addMouseListener(java.awt.event.MouseListener), javax.swing.JPanel#removeMouseListener(java.awt.event.MouseListener), javax.swing.JPanel#getMouseListeners(), javax.swing.JPanel#addMouseMotionListener(java.awt.event.MouseMotionListener), javax.swing.JPanel#removeMouseMotionListener(java.awt.event.MouseMotionListener), javax.swing.JPanel#getMouseMotionListeners(), javax.swing.JPanel#addMouseWheelListener(java.awt.event.MouseWheelListener), javax.swing.JPanel#removeMouseWheelListener(java.awt.event.MouseWheelListener), javax.swing.JPanel#getMouseWheelListeners(), javax.swing.JPanel#addInputMethodListener(java.awt.event.InputMethodListener), javax.swing.JPanel#removeInputMethodListener(java.awt.event.InputMethodListener), javax.swing.JPanel#getInputMethodListeners(), javax.swing.JPanel#getInputMethodRequests(), javax.swing.JPanel#getInputContext(), javax.swing.JPanel#mouseDown(java.awt.Event, int, int), javax.swing.JPanel#mouseDrag(java.awt.Event, int, int), javax.swing.JPanel#mouseUp(java.awt.Event, int, int), javax.swing.JPanel#mouseMove(java.awt.Event, int, int), javax.swing.JPanel#mouseEnter(java.awt.Event, int, int), javax.swing.JPanel#mouseExit(java.awt.Event, int, int), javax.swing.JPanel#keyDown(java.awt.Event, int), javax.swing.JPanel#keyUp(java.awt.Event, int), javax.swing.JPanel#gotFocus(java.awt.Event, java.lang.Object), javax.swing.JPanel#lostFocus(java.awt.Event, java.lang.Object), javax.swing.JPanel#isFocusTraversable(), javax.swing.JPanel#setFocusable(boolean), javax.swing.JPanel#setFocusTraversalKeysEnabled(boolean), javax.swing.JPanel#getFocusTraversalKeysEnabled(), javax.swing.JPanel#transferFocusUpCycle(), javax.swing.JPanel#hasFocus(), javax.swing.JPanel#setComponentOrientation(java.awt.ComponentOrientation), javax.swing.JPanel#getComponentOrientation(), javax.swing.JPanel#setMixingCutoutShape(java.awt.Shape), javax.swing.JPanel#handleEvent(java.awt.Event), javax.swing.JPanel#wait(long), javax.swing.JPanel#wait(long, int), javax.swing.JPanel#wait(), javax.swing.JPanel#equals(java.lang.Object), javax.swing.JPanel#hashCode(), javax.swing.JPanel#getClass(), javax.swing.JPanel#notify(), javax.swing.JPanel#notifyAll() |
{@inheritDoc}
{@inheritDoc}
{@inheritDoc}
{@inheritDoc}
Returns whether arrow keys should support cyclic focus traversal ordering for for this JXButtonPanel.
Returns whether arrow keys should transfer button's selection as well as focus for this JXButtonPanel.
Note: this property affects buttons which are added to a ButtonGroupSets whether arrow keys should support cyclic focus traversal ordering for this JXButtonPanel.
Sets whether arrow keys should transfer button's selection as well as focus for this JXButtonPanel.
Note: this property affects buttons which are added to a ButtonGroup