Java programming part 67 GUI : Adding Tool tips to components

Published: 23 May 2012
on channel: Redemptie
641
2

Java Programming tutorial, GUI, Graphical User Interface. this tutorial is teaching You how to add a Tool Tips to your application Components and containers.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
public class UserFrame extends JFrame implements ActionListener{
static String name = "charles";
static JMenuItem print;
UserFrame(){
setTitle("UsersFrame");
setSize(600,550);

}


public static void main(String[] args){

UserFrame f = new UserFrame();
JMenuBar bar = new JMenuBar();
bar.setToolTipText("this is the manu bar please use this carefully");
JToolBar tb = new JToolBar();
tb.setToolTipText("This is a too bar");
JButton jb11 = new JButton("tb11");
jb11.setToolTipText("this button has a tool tip, please read!");
JButton jb12 = new JButton("tb12");
JButton jb13 = new JButton("tb13");
JButton jb14 = new JButton("tb14");
JButton jb15 = new JButton("tb15");
JButton jb16 = new JButton("tb16");
JButton jb17 = new JButton("tb17");
JMenu fileMenu = new JMenu("File");
JMenu editMenu = new JMenu("Edit");
print = new JMenuItem("print name");
JMenuItem print2 = new JMenuItem("print nothen");
print.addActionListener(f);
fileMenu.add(print);
fileMenu.add(print2);
bar.add(fileMenu);
bar.add(editMenu);
f.setJMenuBar(bar);

JPanel pan1 = new JPanel();
pan1.setLayout(new BorderLayout());
pan1.setBackground(Color.GREEN);
JPanel pan2 = new JPanel();
pan2.setBackground(Color.ORANGE);
JPanel pan3 = new JPanel();
pan3.setBackground(Color.RED);
JPanel pan4 = new JPanel();
pan4.setBackground(Color.magenta);
JPanel pan5 = new JPanel();
pan5.setBackground(Color.BLUE);
JPanel pan6 = new JPanel();
pan6.setBackground(Color.WHITE);
pan6.setLayout(new BorderLayout());
JButton jb = new JButton("Hello");
jb.setToolTipText("Hello Button");
jb.addActionListener(f);
JButton jb6 = new JButton("WEST added");
JButton jb7 = new JButton("EAST added");
JLabel lb = new JLabel(" label for panel, this is showing the paneel");
lb.setToolTipText("this is the label");
JLabel lb2 = new JLabel(" East");
pan6.add(lb,BorderLayout.NORTH);
pan6.add(lb2,BorderLayout.EAST);
pan6.setToolTipText("this is panel 6");
jb.setSize(50, 50);
pan1.add(jb,BorderLayout.NORTH);
pan1.setToolTipText("this is panel 1");
pan1.add(pan6,BorderLayout.SOUTH);
JButton jb2 = new JButton("there");
jb2.addActionListener(f);
jb.setSize(50, 50);
pan2.add(jb2);
pan2.add(jb7);
JButton jb3 = new JButton("North");
jb.setSize(50, 50);
pan3.add(jb3);
JButton jb4 = new JButton("South");
jb.setSize(50, 50);
pan4.add(jb4);
JButton jb5 = new JButton("Center");
jb.setSize(50, 50);
pan5.add(jb5);
tb.add(jb11);
tb.add(jb12);
tb.add(jb13);
tb.add(jb14);
tb.add(jb15);
tb.add(jb16);
tb.add(jb17);
f.add(tb,BorderLayout.NORTH);
f.add(pan1,BorderLayout.WEST);
f.add(pan2,BorderLayout.EAST);
//f.add(pan3,BorderLayout.NORTH);
f.add(pan4,BorderLayout.SOUTH);
f.add(pan5,BorderLayout.CENTER);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);
f.setVisible(true);
}


@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JMenuItem item = (JMenuItem) e.getSource();
if("Hello"==e.getActionCommand()){
System.out.println("you clicked the hello button");
}
if("there"==e.getActionCommand()){
System.out.println("you clicked the there button");
}
if(item==print){
System.out.println("Charles");
}

}


}


On this page of the site you can watch the video online Java programming part 67 GUI : Adding Tool tips to components with a duration of hours minute second in good quality, which was uploaded by the user Redemptie 23 May 2012, share the link with friends and acquaintances, this video has already been watched 641 times on youtube and it was liked by 2 viewers. Enjoy your viewing!