how to make jtextfield text disappear when tabbed into (Netbeans)

16,481

Solution 1

right click on your textfield component and goto Events then goto Focus then select focus gained and the code will appear to you as private void

    jTextField1FocusGained(java.awt.event.FocusEvent evt) {                                        
    // TODO add your handling code here:
    }   

now edit the // TODO add your handling code here: and make it as:

    jTextField1FocusGained(java.awt.event.FocusEvent evt) {                                        
     jtextField.setText(""); 
    }   

so when you will press tab it will gain focus (if you will press from another tab)

Solution 2

then its simple you should use an actionListener

   private void textfieldFocusGained(java.awt.event.FocusEvent evt) {                               
   textfield.setText("");
   }   

this will allow you when you press tab the control goes to next field and empty it try this (you may use this as it is in your class constructor)

yourtextField.addFocusListener(new FocusListener() {


public void focusGained(FocusEvent e) {
    yourtextField.setText(""); 
}


public void focusLost(FocusEvent e) {

}

});      

now if you are in a textfield and will press the tab button your control will go to the next field and clear its text

Solution 3

I have the instructions for what the user is supposed to enter

See Text Prompt. It allows you to customize when the prompt is displayed.

Solution 4

You can use a FocusListener to determine when your JTextField receives focus (i.e. becomes the "active" component), regardless of whether this occurred due to a mouse click or a tab.

textField.addFocusListener(new FocusListener() {

    @Override
    public void focusGained(FocusEvent e) {
        textField.setText(null); // Empty the text field when it receives focus
    }

    @Override
    public void focusLost(FocusEvent e) {
        // You could do something here when the field loses focus, if you like
    }

});
Share:
16,481
howlowworld
Author by

howlowworld

Updated on June 04, 2022

Comments

  • howlowworld
    howlowworld almost 2 years

    I'm working on a gui that has multiple textfields that the user enters data into. When the program opens, I have the instructions for what the user is supposed to enter into the textfield set as the "text". I have it set to when user clicks textfield, the text will disappear, but I can't figure out how to get it to disappear when tabbed over into the next jtextfield. I want the user to be able to click on the first textfield, and never have to use the mouse again, but also without having to go crazy on the backspace or del. Thanks

        /*
     * ArcheryProgramView.java
     */
    
    package archeryprogram;
    
    import org.jdesktop.application.Action;
    import org.jdesktop.application.ResourceMap;
    import org.jdesktop.application.SingleFrameApplication;
    import org.jdesktop.application.FrameView;
    import org.jdesktop.application.TaskMonitor;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.FocusEvent;
    import java.awt.event.FocusListener;
    import java.awt.event.KeyEvent;
    
    import javax.swing.Timer;
    import javax.swing.Icon;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    
    
    
    
    /**
     * The application's main frame.
     */
    public class ArcheryProgramView extends FrameView {
    
        public ArcheryProgramView(SingleFrameApplication app) {
            super(app);
    
            initComponents();
    
            // status bar initialization - message timeout, idle icon and busy animation, etc
            ResourceMap resourceMap = getResourceMap();
            int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
            messageTimer = new Timer(messageTimeout, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    statusMessageLabel.setText("");
                }
            });
            messageTimer.setRepeats(false);
            int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
            for (int i = 0; i < busyIcons.length; i++) {
                busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
            }
            busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                    statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
                }
            });
            idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
            statusAnimationLabel.setIcon(idleIcon);
            progressBar.setVisible(false);
    
            // connecting action tasks to status bar via TaskMonitor
            TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
            taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
                public void propertyChange(java.beans.PropertyChangeEvent evt) {
                    String propertyName = evt.getPropertyName();
                    if ("started".equals(propertyName)) {
                        if (!busyIconTimer.isRunning()) {
                            statusAnimationLabel.setIcon(busyIcons[0]);
                            busyIconIndex = 0;
                            busyIconTimer.start();
                        }
                        progressBar.setVisible(true);
                        progressBar.setIndeterminate(true);
                    } else if ("done".equals(propertyName)) {
                        busyIconTimer.stop();
                        statusAnimationLabel.setIcon(idleIcon);
                        progressBar.setVisible(false);
                        progressBar.setValue(0);
                    } else if ("message".equals(propertyName)) {
                        String text = (String)(evt.getNewValue());
                        statusMessageLabel.setText((text == null) ? "" : text);
                        messageTimer.restart();
                    } else if ("progress".equals(propertyName)) {
                        int value = (Integer)(evt.getNewValue());
                        progressBar.setVisible(true);
                        progressBar.setIndeterminate(false);
                        progressBar.setValue(value);
                    }
                }
            });
        }
    
        @Action
        public void showAboutBox() {
            if (aboutBox == null) {
                JFrame mainFrame = ArcheryProgramApp.getApplication().getMainFrame();
                aboutBox = new ArcheryProgramAboutBox(mainFrame);
                aboutBox.setLocationRelativeTo(mainFrame);
            }
            ArcheryProgramApp.getApplication().show(aboutBox);
        }
    
        /** 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">                          
        private void initComponents() {
    
            mainPanel = new javax.swing.JPanel();
            jScrollPane1 = new javax.swing.JScrollPane();
            jTextArea1 = new javax.swing.JTextArea();
            jTextField1 = new javax.swing.JTextField();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            jLabel3 = new javax.swing.JLabel();
            jTextField2 = new javax.swing.JTextField();
            jTextField3 = new javax.swing.JTextField();
            jButton1 = new javax.swing.JButton();
            jLabel4 = new javax.swing.JLabel();
            jTextField4 = new javax.swing.JTextField();
            jButton2 = new javax.swing.JButton();
            jLabel5 = new javax.swing.JLabel();
            jTextField5 = new javax.swing.JTextField();
            jTextField6 = new javax.swing.JTextField();
            jTextField7 = new javax.swing.JTextField();
            jTextField8 = new javax.swing.JTextField();
            menuBar = new javax.swing.JMenuBar();
            javax.swing.JMenu fileMenu = new javax.swing.JMenu();
            javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
            javax.swing.JMenu helpMenu = new javax.swing.JMenu();
            javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
            statusPanel = new javax.swing.JPanel();
            javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
            statusMessageLabel = new javax.swing.JLabel();
            statusAnimationLabel = new javax.swing.JLabel();
            progressBar = new javax.swing.JProgressBar();
    
            org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(archeryprogram.ArcheryProgramApp.class).getContext().getResourceMap(ArcheryProgramView.class);
            mainPanel.setBackground(resourceMap.getColor("mainPanel.background")); // NOI18N
            mainPanel.setName("mainPanel"); // NOI18N
    
            jScrollPane1.setName("jScrollPane1"); // NOI18N
    
            jTextArea1.setBackground(resourceMap.getColor("jTextArea1.background")); // NOI18N
            jTextArea1.setColumns(20);
            jTextArea1.setFont(resourceMap.getFont("jTextArea1.font")); // NOI18N
            jTextArea1.setForeground(resourceMap.getColor("jTextArea1.foreground")); // NOI18N
            jTextArea1.setRows(5);
            jTextArea1.setText(resourceMap.getString("jTextArea1.text")); // NOI18N
            jTextArea1.setName("jTextArea1"); // NOI18N
            jScrollPane1.setViewportView(jTextArea1);
    
            jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
            jTextField1.setName("jTextField1"); // NOI18N
            jTextField1.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jTextField1MouseClicked(evt);
                }
            });
    
            jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
            jLabel1.setName("jLabel1"); // NOI18N
    
            jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
            jLabel2.setName("jLabel2"); // NOI18N
    
            jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
            jLabel3.setName("jLabel3"); // NOI18N
    
            jTextField2.setText(resourceMap.getString("jTextField2.text")); // NOI18N
            javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(archeryprogram.ArcheryProgramApp.class).getContext().getActionMap(ArcheryProgramView.class, this);
            jTextField2.setAction(actionMap.get("clear")); // NOI18N
            jTextField2.setName("jTextField2"); // NOI18N
            jTextField2.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jTextField2MouseClicked(evt);
                }
            });
    
            jTextField3.setText(resourceMap.getString("jTextField3.text")); // NOI18N
            jTextField3.setName("jTextField3"); // NOI18N
            jTextField3.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jTextField3MouseClicked(evt);
                }
            });
            jTextField3.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jTextField3ActionPerformed(evt);
                }
            });
            jTextField3.addInputMethodListener(new java.awt.event.InputMethodListener() {
                public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
                    jTextField3CaretPositionChanged(evt);
                }
                public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                }
            });
            jTextField3.addKeyListener(new java.awt.event.KeyAdapter() {
                public void keyReleased(java.awt.event.KeyEvent evt) {
                    jTextField3KeyReleased(evt);
                }
            });
    
            jButton1.setAction(actionMap.get("weight")); // NOI18N
            jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
            jButton1.setName("jButton1"); // NOI18N
    
            jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
            jLabel4.setName("jLabel4"); // NOI18N
    
            jTextField4.setText(resourceMap.getString("jTextField4.text")); // NOI18N
            jTextField4.setName("jTextField4"); // NOI18N
            jTextField4.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jTextField4MouseClicked(evt);
                }
            });
    
            jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
            jButton2.setName("jButton2"); // NOI18N
    
            jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
            jLabel5.setName("jLabel5"); // NOI18N
    
            jTextField5.setText(resourceMap.getString("jTextField5.text")); // NOI18N
            jTextField5.setName("jTextField5"); // NOI18N
            jTextField5.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jTextField5MouseClicked(evt);
                }
            });
    
            jTextField6.setText(resourceMap.getString("jTextField6.text")); // NOI18N
            jTextField6.setName("jTextField6"); // NOI18N
            jTextField6.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jTextField6MouseClicked(evt);
                }
            });
    
            jTextField7.setText(resourceMap.getString("jTextField7.text")); // NOI18N
            jTextField7.setName("jTextField7"); // NOI18N
            jTextField7.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jTextField7MouseClicked(evt);
                }
            });
    
            jTextField8.setText(resourceMap.getString("jTextField8.text")); // NOI18N
            jTextField8.setName("jTextField8"); // NOI18N
    
            javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
            mainPanel.setLayout(mainPanelLayout);
            mainPanelLayout.setHorizontalGroup(
                mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addGap(19, 19, 19)
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(mainPanelLayout.createSequentialGroup()
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(193, 193, 193))
                        .addGroup(mainPanelLayout.createSequentialGroup()
                            .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(mainPanelLayout.createSequentialGroup()
                                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE)
                                    .addGap(83, 83, 83))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 92, Short.MAX_VALUE)
                                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(mainPanelLayout.createSequentialGroup()
                                    .addGap(144, 144, 144)
                                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGap(26, 26, 26)))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(mainPanelLayout.createSequentialGroup()
                            .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(30, 30, 30)
                            .addComponent(jButton1))
                        .addComponent(jButton2))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel5))
                    .addGap(191, 191, 191))
            );
            mainPanelLayout.setVerticalGroup(
                mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(70, 70, 70)
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel3)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4)
                            .addComponent(jButton1)
                            .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGap(18, 18, 18)
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel5)
                        .addComponent(jButton2))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jLabel2)
                    .addContainerGap(258, Short.MAX_VALUE))
            );
    
            menuBar.setName("menuBar"); // NOI18N
    
            fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
            fileMenu.setName("fileMenu"); // NOI18N
    
            exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
            exitMenuItem.setName("exitMenuItem"); // NOI18N
            fileMenu.add(exitMenuItem);
    
            menuBar.add(fileMenu);
    
            helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
            helpMenu.setName("helpMenu"); // NOI18N
    
            aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
            aboutMenuItem.setName("aboutMenuItem"); // NOI18N
            helpMenu.add(aboutMenuItem);
    
            menuBar.add(helpMenu);
    
            statusPanel.setName("statusPanel"); // NOI18N
    
            statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N
    
            statusMessageLabel.setName("statusMessageLabel"); // NOI18N
    
            statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
            statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N
    
            progressBar.setName("progressBar"); // NOI18N
    
            javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
            statusPanel.setLayout(statusPanelLayout);
            statusPanelLayout.setHorizontalGroup(
                statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 1162, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(statusMessageLabel)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 992, Short.MAX_VALUE)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(statusAnimationLabel)
                    .addContainerGap())
            );
            statusPanelLayout.setVerticalGroup(
                statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(statusPanelLayout.createSequentialGroup()
                    .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(statusMessageLabel)
                        .addComponent(statusAnimationLabel)
                        .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(3, 3, 3))
            );
    
            setComponent(mainPanel);
            setMenuBar(menuBar);
            setStatusBar(statusPanel);
        }// </editor-fold>                        
    
        private void jTextField2MouseClicked(java.awt.event.MouseEvent evt) {                                         
                    jTextField2.setText("");// TODO add your handling code here:
        }                                        
    
        private void jTextField3MouseClicked(java.awt.event.MouseEvent evt) {                                         
                    jTextField3.setText("");        // TODO add your handling code here:
        }                                        
    
        private void jTextField1MouseClicked(java.awt.event.MouseEvent evt) {                                         
                    jTextField1.setText("");        // TODO add your handling code here:
        }                                        
    
        private void jTextField4MouseClicked(java.awt.event.MouseEvent evt) {                                         
                    jTextField4.setText("");        // TODO add your handling code here:
        }                                        
    
        private void jTextField3KeyReleased(java.awt.event.KeyEvent evt) {                                        
                    // TODO add your handling code here:
        }                                       
    
        private void jTextField3CaretPositionChanged(java.awt.event.InputMethodEvent evt) {                                                 
                     // TODO add your handling code here:
        }                                                
    
        private void jTextField5MouseClicked(java.awt.event.MouseEvent evt) {                                         
                    jTextField5.setText("");        // TODO add your handling code here:
        }                                        
    
        private void jTextField6MouseClicked(java.awt.event.MouseEvent evt) {                                         
                   jTextField6.setText("");        // TODO add your handling code here:
        }                                        
    
        private void jTextField7MouseClicked(java.awt.event.MouseEvent evt) {                                         
                    jTextField7.setText("");        // TODO add your handling code here:
        }                                        
    
        private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {                                            
                            // TODO add your handling code here:
        }                                           
    
     private void jTextField3FocusGained(java.awt.event.FocusEvent evt) {
         jTextField3.setText(null);
        }
    
        @Action
        public void weight() {
        float gpi=  Float.parseFloat(jTextField2.getText());
        float weight=  Float.parseFloat(jTextField3.getText());
        float novanes= Float.parseFloat(jTextField5.getText());
        float vaneweight= Float.parseFloat(jTextField6.getText());
        float nock= Float.parseFloat(jTextField7.getText());
        float point= Float.parseFloat(jTextField8.getText());
        float totalvane= novanes*vaneweight;
        float totalweight= (gpi*weight)+totalvane+nock+point;
        System.out.println("totalweight = "+totalweight);
        jLabel4.setText(""+totalweight+" grains");
        }
    
        // Variables declaration - do not modify                     
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JLabel jLabel5;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTextArea jTextArea1;
        private javax.swing.JTextField jTextField1;
        private javax.swing.JTextField jTextField2;
        private javax.swing.JTextField jTextField3;
        private javax.swing.JTextField jTextField4;
        private javax.swing.JTextField jTextField5;
        private javax.swing.JTextField jTextField6;
        private javax.swing.JTextField jTextField7;
        private javax.swing.JTextField jTextField8;
        private javax.swing.JPanel mainPanel;
        private javax.swing.JMenuBar menuBar;
        private javax.swing.JProgressBar progressBar;
        private javax.swing.JLabel statusAnimationLabel;
        private javax.swing.JLabel statusMessageLabel;
        private javax.swing.JPanel statusPanel;
        // End of variables declaration                   
    
        private final Timer messageTimer;
        private final Timer busyIconTimer;
        private final Icon idleIcon;
        private final Icon[] busyIcons = new Icon[15];
        private int busyIconIndex = 0;
    
        private JDialog aboutBox;
    }
    
    • Tech Nerd
      Tech Nerd about 11 years
      your question is so ambiguous can't even get it lols
    • howlowworld
      howlowworld about 11 years
      how do you make the text in a textfield disappear when you tab into the textfield. It is easy to make it disappear when you mouse click into the textfield, maybe not quite so easy for tab
    • Tech Nerd
      Tech Nerd about 11 years
      are you on NetBeans or anyother IDE?
    • Tech Nerd
      Tech Nerd about 11 years
    • Tech Nerd
      Tech Nerd about 11 years
      you must update NetBeans to 7.2 for better performance
    • howlowworld
      howlowworld about 11 years
      do I lose the drag and drop gui?
    • howlowworld
      howlowworld about 11 years
      it's not a big deal i've just been lazy to learn all of it without drag and drop. Thanks a lot for your time.
  • howlowworld
    howlowworld about 11 years
    it says the method is not used. I put it with all of the other methods that clears the textfield when mouse is clicked.
  • howlowworld
    howlowworld about 11 years
    jTextField1FocusGained is underlined in gray and says the method is not used
  • howlowworld
    howlowworld about 11 years
    and still does not clear the textfield when tabbed into from previous textfield
  • Tech Nerd
    Tech Nerd about 11 years
    you can use jtextfield.setText(null);
  • Tech Nerd
    Tech Nerd about 11 years
    are you generating is as I said to you? send me your code I will fix it for you ok asap