List of usage examples for javax.swing SortingFocusTraversalPolicy SortingFocusTraversalPolicy
public SortingFocusTraversalPolicy(Comparator<? super Component> comparator)
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Reverse Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(3, 3)); for (int i = 0; i < 9; i++) { JButton button = new JButton(Integer.toString(i)); frame.add(button);/*from w w w . j ava2 s .c om*/ } final Container contentPane = frame.getContentPane(); Comparator<Component> comp = new Comparator<Component>() { public int compare(Component c1, Component c2) { Component comps[] = contentPane.getComponents(); List list = Arrays.asList(comps); int first = list.indexOf(c1); int second = list.indexOf(c2); return second - first; } }; FocusTraversalPolicy policy = new SortingFocusTraversalPolicy(comp); frame.setFocusTraversalPolicy(policy); frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Reverse Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(3, 3)); for (int i = 9; i > 0; i--) { JButton button = new JButton(Integer.toString(i)); frame.add(button, 0);//from www . jav a 2 s . co m } final Container contentPane = frame.getContentPane(); Comparator<Component> comp = new Comparator<Component>() { public int compare(Component c1, Component c2) { Component comps[] = contentPane.getComponents(); List list = Arrays.asList(comps); int first = list.indexOf(c1); int second = list.indexOf(c2); return second - first; } }; FocusTraversalPolicy policy = new SortingFocusTraversalPolicy(comp); frame.setFocusTraversalPolicy(policy); frame.setSize(300, 200); frame.setVisible(true); }