ToolTipText is a string that is displayed when user moves mouse cursor over a swing component like JButton , JTextArea ,JLabel, JTextField...
ToolTipText is a string that is displayed when user moves mouse cursor over a swing component like JButton,JTextArea,JLabel,JTextField etc
JTextField setToolTipText example
[
import javax.swing.JFrame; import javax.swing.JTextField; public class JavaJTextField extends JFrame{ JavaJTextField() { super("JTextField Tooltiptext"); JTextField field=new JTextField(); field.setToolTipText("Enter your name"); field.setBounds(50,50, 150,20); add(field); setSize(400,400); setLocationRelativeTo(null); setLayout(null); setVisible(true); } public static void main(String args[]) { new JavaJTextField(); } }
]
[field.setToolTipText("Enter your name");] this is the code that sets tooltiptext.Run above code and hover the mouse over the JTextField, "Enter your name " text will pop up.
JTextField setEditable example
setEditable() function is used to enable or disable user inputs.If you setEditable(false),user cannot enter any input in that field.
[
[
import javax.swing.JFrame; import javax.swing.JTextField; public class JavaJTextField extends JFrame{ JavaJTextField() { super("JTextField Tooltiptext"); JTextField field=new JTextField(); field.setToolTipText("Enter your name"); field.setEditable(false); field.setBounds(50,50, 150,20); add(field); setSize(400,400); setLocationRelativeTo(null); setLayout(null); setVisible(true); } public static void main(String args[]) { new JavaJTextField(); } }]