Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2009
    Posts
    21
    Rep Power
    0

    Post Focusing on the next JTextField

    i just present the code

    while pressing the TAB key from the keyboard
    i want the foucs should be moved form one textbox to checkbox and so on
    Java Code:
    public class FocusTest extends javax.swing.JFrame {
    
    
    
        /** Creates new form FocusTest */
    
        public FocusTest() {
    
            initComponents();
    
        }
    
    
    
        /** This method is called from within the constructor to
    
         * initialize the form.
    
         * WARNING: Do NOT modify this code. The content of this method is
    
         * always regenerated by the Form Editor.
    
         */
    
        @SuppressWarnings("unchecked")
    
        // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    
        private void initComponents() {
    
    
    
            jPanel8 = new javax.swing.JPanel();
    
            jlblVideo_Mos2 = new javax.swing.JLabel();
    
            txtMOS_AV = new javax.swing.JTextField();
    
            jlblVideo_Mos12 = new javax.swing.JLabel();
    
            txtAudio_MOS = new javax.swing.JTextField();
    
            jlblVideo_Mos13 = new javax.swing.JLabel();
    
            txtVideo_MOS = new javax.swing.JTextField();
    
            btnRestore = new javax.swing.JButton();
    
            btnSave = new javax.swing.JButton();
    
            btnThresholdClear = new javax.swing.JButton();
    
            chbxMOS_AV = new javax.swing.JCheckBox();
    
            chbxAudio_MOS = new javax.swing.JCheckBox();
    
            chbxVideo_MOS = new javax.swing.JCheckBox();
    
    
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
            setName("Form"); // NOI18N
    
    
    
            org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(mcq_model.MCQ_ModelApp.class).getContext().getResourceMap(FocusTest.class);
    
            jPanel8.setBackground(resourceMap.getColor("jPanel8.background")); // NOI18N
    
            jPanel8.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
    
            jPanel8.setToolTipText(resourceMap.getString("jPanel8.toolTipText")); // NOI18N
    
            jPanel8.setName("jPanel8"); // NOI18N
    
    
    
            jlblVideo_Mos2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    
            jlblVideo_Mos2.setText("MOS-AV"); // NOI18N
    
            jlblVideo_Mos2.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
    
            jlblVideo_Mos2.setName("jlblVideo_Mos2"); // NOI18N
    
    
    
            txtMOS_AV.setColumns(2);
    
            txtMOS_AV.setFont(resourceMap.getFont("txtMOS_AV.font")); // NOI18N
    
            txtMOS_AV.setHorizontalAlignment(javax.swing.JTextField.LEFT);
    
            txtMOS_AV.setToolTipText(resourceMap.getString("txtMOS_AV.toolTipText")); // NOI18N
    
            txtMOS_AV.setAlignmentX(1.0F);
    
            txtMOS_AV.setAlignmentY(1.0F);
    
            txtMOS_AV.setDoubleBuffered(true);
    
            txtMOS_AV.setFocusCycleRoot(true);
    
            txtMOS_AV.setFocusTraversalPolicyProvider(true);
    
            txtMOS_AV.setInheritsPopupMenu(true);
    
            txtMOS_AV.setName("txtMOS_AV"); // NOI18N
    
    
    
            jlblVideo_Mos12.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    
            jlblVideo_Mos12.setText("Audio-MOS"); // NOI18N
    
            jlblVideo_Mos12.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
    
            jlblVideo_Mos12.setName("jlblVideo_Mos12"); // NOI18N
    
    
    
            txtAudio_MOS.setColumns(2);
    
            txtAudio_MOS.setFont(resourceMap.getFont("txtAudio_MOS.font")); // NOI18N
    
            txtAudio_MOS.setHorizontalAlignment(javax.swing.JTextField.LEFT);
    
            txtAudio_MOS.setToolTipText(resourceMap.getString("txtAudio_MOS.toolTipText")); // NOI18N
    
            txtAudio_MOS.setAlignmentX(1.0F);
    
            txtAudio_MOS.setAlignmentY(1.0F);
    
            txtAudio_MOS.setDoubleBuffered(true);
    
            txtAudio_MOS.setFocusCycleRoot(true);
    
            txtAudio_MOS.setFocusTraversalPolicyProvider(true);
    
            txtAudio_MOS.setInheritsPopupMenu(true);
    
     txtAudio_MOS.setName("txtAudio_MOS"); // NOI18N
    
    
    
            jlblVideo_Mos13.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    
            jlblVideo_Mos13.setText("Video-MOS"); // NOI18N
    
            jlblVideo_Mos13.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
    
            jlblVideo_Mos13.setName("jlblVideo_Mos13"); // NOI18N
    
    
    
            txtVideo_MOS.setColumns(2);
    
            txtVideo_MOS.setFont(resourceMap.getFont("txtVideo_MOS.font")); // NOI18N
    
            txtVideo_MOS.setToolTipText(resourceMap.getString("txtVideo_MOS.toolTipText")); // NOI18N
    
            txtVideo_MOS.setAlignmentX(1.0F);
    
            txtVideo_MOS.setAlignmentY(1.0F);
    
            txtVideo_MOS.setDoubleBuffered(true);
    
            txtVideo_MOS.setFocusCycleRoot(true);
    
            txtVideo_MOS.setFocusTraversalPolicyProvider(true);
    
            txtVideo_MOS.setInheritsPopupMenu(true);
    
            txtVideo_MOS.setName("txtVideo_MOS"); // NOI18N
    
    
    
            btnRestore.setText("Restore"); // NOI18N
    
            btnRestore.setName("btnRestore"); // NOI18N
    
    
    
            btnSave.setText("Save"); // NOI18N
    
            btnSave.setName("btnSave"); // NOI18N
    
    
    
            btnThresholdClear.setText("Clear"); // NOI18N
    
            btnThresholdClear.setName("btnThresholdClear"); // NOI18N
    
    
    
            chbxMOS_AV.setBackground(resourceMap.getColor("chbxMOS_AV.background")); // NOI18N
    
            chbxMOS_AV.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    
            chbxMOS_AV.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    
            chbxMOS_AV.setName("chbxMOS_AV"); // NOI18N
    
    
    
            chbxAudio_MOS.setBackground(resourceMap.getColor("chbxAudio_MOS.background")); // NOI18N
    
            chbxAudio_MOS.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    
            chbxAudio_MOS.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    
            chbxAudio_MOS.setName("chbxAudio_MOS"); // NOI18N
    
    
    
            chbxVideo_MOS.setBackground(resourceMap.getColor("chbxVideo_MOS.background")); // NOI18N
    
    chbxVideo_MOS.setToolTipText(resourceMap.getString("chbxVideo_MOS.toolTipText")); // NOI18N
    
            chbxVideo_MOS.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    
            chbxVideo_MOS.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    
            chbxVideo_MOS.setName("chbxVideo_MOS"); // NOI18N
    
    
    
            javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
    
            jPanel8.setLayout(jPanel8Layout);
    
            jPanel8Layout.setHorizontalGroup(
    
                jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    
                .addGroup(jPanel8Layout.createSequentialGroup()
    
                    .addGap(26, 26, 26)
    
                    .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
    
                        .addComponent(btnRestore)
    
                        .addComponent(jlblVideo_Mos2)
    
                        .addComponent(jlblVideo_Mos12)
    
                        .addComponent(jlblVideo_Mos13))
    
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    
                    .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    
                        .addGroup(jPanel8Layout.createSequentialGroup()
    
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    
                                .addComponent(txtMOS_AV, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
    
                                .addComponent(txtAudio_MOS, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
    
                                .addComponent(txtVideo_MOS, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
    
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
    
                                .addComponent(chbxMOS_AV, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    
                                .addComponent(chbxAudio_MOS, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    
                                .addComponent(chbxVideo_MOS, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
    
                        .addGroup(jPanel8Layout.createSequentialGroup()
    
                            .addComponent(btnSave)
    
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    
                            .addComponent(btnThresholdClear)))
    
               .addGap(22, 22, 22))
    
            );
    
            jPanel8Layout.setVerticalGroup(
    
                jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    
                .addGroup(jPanel8Layout.createSequentialGroup()
    
                    .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    
                        .addGroup(jPanel8Layout.createSequentialGroup()
    
                            .addGap(11, 11, 11)
    
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    
                                .addComponent(jlblVideo_Mos13, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
    
                                .addComponent(txtVideo_MOS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    
                                .addComponent(jlblVideo_Mos12, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
    
                                .addComponent(txtAudio_MOS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    
                                .addComponent(jlblVideo_Mos2, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
    
                                .addComponent(txtMOS_AV, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    
                            .addGap(18, 18, 18)
    
                            .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
    
                                .addComponent(btnRestore)
    
                                .addComponent(btnSave)
    
                                .addComponent(btnThresholdClear)))
    
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel8Layout.createSequentialGroup()
    
                            .addContainerGap()
    
                            .addComponent(chbxVideo_MOS, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
    
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
    
                            .addComponent(chbxAudio_MOS)
    
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
    
     .addComponent(chbxMOS_AV, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
    
                            .addGap(228, 228, 228)))
    
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    
            );
    
    
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    
            getContentPane().setLayout(layout);
    
            layout.setHorizontalGroup(
    
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    
                .addGap(0, 400, Short.MAX_VALUE)
    
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    
                    .addGroup(layout.createSequentialGroup()
    
                        .addGap(76, 76, 76)
    
                        .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
    
                        .addContainerGap(77, Short.MAX_VALUE)))
    
            );
    
            layout.setVerticalGroup(
    
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    
                .addGap(0, 190, Short.MAX_VALUE)
    
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    
                    .addGroup(layout.createSequentialGroup()
    
                        .addContainerGap()
    
                        .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
    
                        .addContainerGap(41, Short.MAX_VALUE)))
    
            );
    
    
    
            pack();
    
        }// </editor-fold>//GEN-END:initComponents
    
    
    
        /**
    
        * @param args the command line arguments
    
        */
    
        public static void main(String args[]) {
    
            java.awt.EventQueue.invokeLater(new Runnable() {
    
     
                public void run() {
    
                    new FocusTest().setVisible(true);
    
                }
    
            });
    
        }
    
    
    
        // Variables declaration - do not modify//GEN-BEGIN:variables
    
        private javax.swing.JButton btnRestore;
    
        private javax.swing.JButton btnSave;
    
        private javax.swing.JButton btnThresholdClear;
    
        private javax.swing.JCheckBox chbxAudio_MOS;
    
        private javax.swing.JCheckBox chbxMOS_AV;
    
        private javax.swing.JCheckBox chbxVideo_MOS;
    
        private javax.swing.JPanel jPanel8;
    
        private javax.swing.JLabel jlblVideo_Mos12;
    
        private javax.swing.JLabel jlblVideo_Mos13;
    
        private javax.swing.JLabel jlblVideo_Mos2;
    
        private javax.swing.JTextField txtAudio_MOS;
    
        private javax.swing.JTextField txtMOS_AV;
    
        private javax.swing.JTextField txtVideo_MOS;
    
        // End of variables declaration//GEN-END:variables
    
    
    
    }
    Solutions are neede immediately
    Last edited by britto_bicsjohn; 08-27-2009 at 03:08 PM. Reason: clear Code
    :) javadeveloper

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Isn't that already the default behavior if you have only two text fields?

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    ... unless another component is in the way. To the OP, please post a small compilable program that demonstrates your problem and perhaps go into a little more detail on just what is happening that's not supposed to be happening. If posting code, please use code tags. Thanks

Similar Threads

  1. JTextField
    By gancio in forum AWT / Swing
    Replies: 20
    Last Post: 08-26-2009, 03:11 PM
  2. JTextField not visible?
    By McChill in forum New To Java
    Replies: 2
    Last Post: 05-20-2009, 12:17 AM
  3. Replies: 1
    Last Post: 01-30-2009, 06:44 PM
  4. JtextField
    By kashifu in forum Advanced Java
    Replies: 2
    Last Post: 06-27-2008, 04:25 PM
  5. help with JTextfield
    By gary in forum New To Java
    Replies: 4
    Last Post: 07-11-2007, 01:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •