Thursday, August 4, 2011

Adding ToolTipText on JTextField

Output:


Code:

/**

* File: jtextfieldToolTipText.java

* Tiltle: Adding ToolTipText on JTextField

* Author: http://java-code-complete.blogspot.com

*/



//Java Core Package

import javax.swing.*;

//Java Extension Package

import java.awt.*;



public class jtextfieldToolTipText extends JFrame {



//Initializing JTextField

private JTextField field;



//Setting up GUI

public jtextfieldToolTipText() {



//Setting up the Title of the Window

super("Adding ToolTipText on JTextField");



//Set Size of the Window (WIDTH, HEIGHT)

setSize(300,100);



//Exit Property of the Window

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);



//Constructing JTextField with a size of 20

field = new JTextField(20);



//Setting or Adding JTextField ToolTipText

field.setToolTipText("JTextField ToolTipText. Enter Text Here..");



//Setting up the container ready for the components to be added.

Container pane = getContentPane();

setContentPane(pane);



//Adding the JTextField component to the container

pane.add(field, BorderLayout.NORTH);



/**Set all the Components Visible.

* If it is set to "false", the components in the container will not be visible.

*/

setVisible(true);

}



//Main Method

public static void main (String[] args) {

jtextfieldToolTipText jtfttt = new jtextfieldToolTipText();

}

}


Important Part of the Program:

//Constructing JTextField with a size of 20 

JTextField field = new JTextField(20);



//Setting or Adding JTextField ToolTipText

field.setToolTipText("JTextField ToolTipText. Enter Text Here..");

No comments:

Post a Comment