Hi Friends Could someone suggest me how to main tab order in an application? Regards Sriram
Renee Zhang
Ranch Hand
Joined: Sep 10, 2001
Posts: 72
posted
0
By default, TAB and CTRL-TAB move focus forward, and SHIFT-TAB and CTRL-SHIFT-TAB move focus backward.
Sri Ram
Greenhorn
Joined: Jul 27, 2001
Posts: 7
posted
0
should the ordering of the awt items be according to the tab? for eg. textfield 1 textfield 2 textfield 3 textfield 4 be like this what add(txtField1); add(txtField2); add(txtField3); add(txtField4); Do you mean to say that this would maintain tab order itself? How about for combobox then?
Renee Zhang
Ranch Hand
Joined: Sep 10, 2001
Posts: 72
posted
0
Your example works. But you may add jTextField1.setNextFocusableComponent(jTextField3) to change the order. And I found an example from a book for you. import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Test extends JFrame { private JButton button_1 = new NotFocusTraversableButton(), button_2 = new ButtonThatManagesFocus(), button_3 = new JButton("regular button"), button_4 = new JButton("regular button"), button_5 = new JButton("request focus disable"), button_6 = new JButton("next focusable component set to manages Focus button"); public Test () { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String[] args) { JFrame frame = new Test(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.pack(); frame.setVisible(true); } private void jbInit () { Container contentPane = getContentPane(); FocusCycleRootPanel panel = new FocusCycleRootPanel(); button_5.setRequestFocusEnabled(false); button_6.setNextFocusableComponent(button_2); panel.add(button_3); panel.add(button_4); panel.add(button_5); contentPane.setLayout(new FlowLayout()); contentPane.add(button_1); contentPane.add(button_2); contentPane.add(panel); contentPane.add(button_6); } } class ButtonThatManagesFocus extends JButton { public ButtonThatManagesFocus () { super("Manages Focus"); } public boolean isManagingFocus () { return true; } public void processComponentKeyEvent (KeyEvent e) { System.out.println(e); } } class NotFocusTraversableButton extends JButton { public NotFocusTraversableButton () { super ("Not Focus Traversable"); } public boolean isFocusTraversable () { return false; } } class FocusCycleRootPanel extends JPanel { public FocusCycleRootPanel () { setBorder(BorderFactory.createTitledBorder("FocusCycleRoot panel")); } public boolean isFocusCycleRoot () { return true; } }