/** * Habilita un componente de la barra de herramientas. * * @param posicion posición del elemento de la barra de herramientas que se quiere * habilitar.Entero del 0 al número de elementos. */ public static void habilitarComponenteBarraHerramientas(int posicion) { if (posicion < toolBar.getComponentCount()) { toolBar.getComponentAtIndex(posicion).setEnabled(true); toolBar.repaint(); } else { System.out.println("Te has salido del rango de componentes de la barra de herramientas"); } } // habilitarComponeneteBarraHerramientas
public void doEffect(JToolBar tb) { Component component; int idx = 0; do { component = tb.getComponentAtIndex(idx); if (component instanceof JButton) { doEffect((JButton) component); } idx++; } while (component != null); }
/** * This method navigates in the given direction giving focus to the next component in the given * direction. * * @param direction The direction to give focus to. */ protected void navigateFocusedComp(int direction) { int count = toolBar.getComponentCount(); switch (direction) { case EAST: case SOUTH: if (focusedCompIndex >= 0 && focusedCompIndex < count) { int i = focusedCompIndex + 1; boolean focusRequested = false; // Find component to focus and request focus on it. while (i != focusedCompIndex && !focusRequested) { if (i >= count) i = 0; Component comp = toolBar.getComponentAtIndex(i++); if (comp != null && comp.isFocusable() && comp.isEnabled()) { comp.requestFocus(); focusRequested = true; } } } break; case WEST: case NORTH: if (focusedCompIndex >= 0 && focusedCompIndex < count) { int i = focusedCompIndex - 1; boolean focusRequested = false; // Find component to focus and request focus on it. while (i != focusedCompIndex && !focusRequested) { if (i < 0) i = count - 1; Component comp = toolBar.getComponentAtIndex(i--); if (comp != null && comp.isFocusable() && comp.isEnabled()) { comp.requestFocus(); focusRequested = true; } } } break; default: break; } }