Skip to main content

Java Swing: Use of ToolTip, Change TitleBarIcon

How to use ToolTip in Java Swing

You can create a tool tip for any JComponent with setToolTipText() method. This method is used to set up a tool tip for the component.

For example, to add tool tip to PasswordField, you need to add only one line of code:

  1. field.setToolTipText("Enter your Password");  

Simple ToolTip Example

  1. import javax.swing.*;    
  2. public class ToolTipExample {  
  3.     public static void main(String[] args) {    
  4.      JFrame f=new JFrame("Password Field Example");    
  5.      //Creating PasswordField and label  
  6.      JPasswordField value = new JPasswordField();   
  7.      value.setBounds(100,100,100,30);    
  8.      value.setToolTipText("Enter your Password");  
  9.      JLabel l1=new JLabel("Password:");    
  10.      l1.setBounds(20,10080,30);    
  11.      //Adding components to frame  
  12.      f.add(value);  f.add(l1);  
  13.      f.setSize(300,300);    
  14.      f.setLayout(null);    
  15.      f.setVisible(true);      
  16. }  
  17. }  

Output:

Java How to use tool tip 1


How to change TitleBar icon in Java AWT and Swing

The setIconImage() method of Frame class is used to change the icon of Frame or Window. It changes the icon which is displayed at the left side of Frame or Window.

The Toolkit class is used to get instance of Image class in AWT and Swing.

Toolkit class is the abstract super class of every implementation in the Abstract Window Toolkit(AWT). Subclasses of Toolkit are used to bind various components. It inherits Object class.


Example to change TitleBar icon in Java AWT

  1. import java.awt.*;     
  2. class IconExample {     
  3. IconExample(){     
  4. Frame f=new Frame();     
  5. Image icon = Toolkit.getDefaultToolkit().getImage("D:\\icon.png");    
  6. f.setIconImage(icon);    
  7. f.setLayout(null);     
  8. f.setSize(400,400);     
  9. f.setVisible(true);     
  10. }     
  11. public static void main(String args[]){     
  12. new IconExample();     
  13. }     
  14. }    

Output:

Java How to change titlebar 1

Example to change TitleBar icon in Java Swing

  1. import javax.swing.*;  
  2. import java.awt.*;  
  3. class IconExample {   
  4. IconExample(){   
  5. JFrame f=new JFrame();   
  6. Image icon = Toolkit.getDefaultToolkit().getImage("D:\\icon.png");  
  7. f.setIconImage(icon);  
  8. f.setLayout(null);   
  9. f.setSize(200,200);   
  10. f.setVisible(true);   
  11. }   
  12. public static void main(String args[]){   
  13. new ToolkitExample();   
  14. }   
  15. }  

Output:

Java How to change titlebar 2

Anurag Rana Educator CSE/IT

Comments

Popular posts from this blog

Standard and Formatted Input / Output in C++

The C++ standard libraries provide an extensive set of input/output capabilities which we will see in subsequent chapters. This chapter will discuss very basic and most common I/O operations required for C++ programming. C++ I/O occurs in streams, which are sequences of bytes. If bytes flow from a device like a keyboard, a disk drive, or a network connection etc. to main memory, this is called   input operation   and if bytes flow from main memory to a device like a display screen, a printer, a disk drive, or a network connection, etc., this is called   output operation . Standard Input and Output in C++ is done through the use of  streams . Streams are generic places to send or receive data. In C++, I/O is done through classes and objects defined in the header file  <iostream> .  iostream  stands for standard input-output stream. This header file contains definitions to objects like  cin ,  cout , etc. /O Library Header Files There are...

locking

DBMS Locking Part I (DBMS only) TECHNICAL ARTICLES -> PERFORMANCE ARTICLES [  Back  ] [  Next  ] DBMS is often criticized for excessive locking – resulting in poor database performance when sharing data among multiple concurrent processes. Is this criticism justified, or is DBMS being unfairly blamed for application design and implementation shortfalls? To evaluate this question, we need to understand more about DBMS locking protocols. In this article, we examine how, why, what and when DBMS locks and unlocks database resources. Future articles will address how to minimize the impact of database locking. THE NEED FOR LOCKING In an ideal concurrent environment, many processes can simultaneously access data in a DBMS database, each having the appearance that they have exclusive access to the database. In practice, this environment is closely approximated by careful use of locking protocols. Locking is necessary in a concurrent environment to as...

DATA WAREHOUSE VERSUS DATA MART: THE GREAT DEBATE

DATA WAREHOUSE VERSUS DATA MART: THE GREAT DEBATE Customers exploring the field of business intelligence for the first time often lead with: What is the difference between a data warehouse and a data mart? The next question follows as predictably as night follows day: which one does my company need? Let me start by saying that the two terms are often confused. Indeed, some people in the industry use them virtually interchangeably, which is unfortunate, because they do reflect a valuable hierarchical difference. The Data Warehouse A "data warehouse" will typically contain the full range of business intelligence available to a company from all sources. That data consists of transaction-processing records, corporate and marketing data, and other business operations information; for example, a bank might include loans, credit card statements, and demand deposits data, along with basic customer information. This internal data is frequently combined with statistica...