Setting tooltips in JApplet

Hi,
I've prepared a very simple JApplet (that implements a MouseListener) which should do the following:
1) When the user clicks on it, it should play an audio clip (.au format),
2) When the user hovers over it, it should display a tooltip. The tooltip has been set on a JLabel which also contains an image.
It seems that I cannot combine both the tooltip and the audio clip. If I display the tooltip, the audio clip will not play. If I get rid of the tooltip, the audio clip plays fine. Any ideas what might be the problem.
Thanks for your help.

I used the "title" attribute to set the tooltip on the cell in h:dataTable. It is working.

Similar Messages

  • Problem with setting tooltips for items of a JCombobox

    hi guys,
    I want to set tooltips for items of JComboBox & the code that i have written is given below , but the tooltip text is set for all the items of Nonitindustrycombo but the tooltips remain the same even for Nonitdesgcombo's items.
    Is that we need to refresh the ComboboxRenderer every time ?
    I am not able to trace out the exact reason for this,please if anyone can suggest me something regarding this would be of great use to me.
    class Searchpanel extends JPanel {
    String[] str = null;
    public SearchPanel(){
    Nonitindustrycombo.addItem("--Select--");
    ArrayList NonITindus = ERPModel.getAllNonitIndustry(); //gets all the items(strings) for Nonitindustrycombo
    for (Iterator iter = NonITindus.iterator(); iter.hasNext();) {
    String str = iter.next().toString();
    Nonitindustrycombo.addItem(str);
    SetTooltip(Nonitindustrycombo,NonITindus);
    Nonitdesgcombo.addItem("--Select---");
    ArrayList desg = ERPModel.getAllNonitDesg(); //gets all the items(strings) for Nonitdesgcombo
    for (Iterator iter = desg.iterator(); iter.hasNext();) {
    Nonitdesgcombo.addItem(iter.next());
    SetTooltip(Nonitdesgcombo,desg);
    class MyComboBoxRenderer extends BasicComboBoxRenderer
    public Component getListCellRendererComponent(JList list, Object value,
    int index, boolean isSelected,
    boolean cellHasFocus)
    if (isSelected)
    setBackground(list.getSelectionBackground());
    setForeground(list.getSelectionForeground());
    if (0 < (index))
    list.setToolTipText(str[index - 1]);
    else
    setBackground(list.getBackground());
    setForeground(list.getForeground());
    setFont(list.getFont());
    setText((value == null) ? "" : value.toString());
    return this;
    private void SetTooltip(JComboBox combo,ArrayList arr){
    str = (String []) arr.toArray (new String [arr.size ()]);
    combo.setRenderer(new MyComboBoxRenderer());
    public static void main(String[] args){
    new SearchPanel();
    Thanks ,
    vishal

    1) You where given a working example in your last posting on this topic. Compare your code with the working code to see whats different and fix it.
    2) The code you posted doesn't compile.
    3) You didn't use the "Code Formatting Tags" when you posted your code so it not readable.

  • Setting tooltip for columns in a JTable

    Hi!
    I have a JTable inside a JScrollPane. How do I set tooltip for each columnheader of the JTable?
    I have noted that if I don�t have the JTable within the JScrollPane, the columnheaders are not shown.
    Regards
    Johan

    1) You need to set the tooptip text on the renderer for the column (yourTable.getColumnModel().getColumn(...).getHeaderRenderer()).
    2) The header is a separate component to the table. When you add a table to a scroll pane it automatically adds the header to the scroll pane too. You can get the component (yourTable.getTableHeader()) and add it to your own container if you wish.

  • DVT Graph - setting tooltip dynamically.

    Hello,
    How can I set tooltip for a graph in java class?
    I know setting tooltip in ".jsp" but I need to set it in java class.
    Thanks,
    Mina

    Hi Sumit,
    It worked creating the graph programmatically using the code below.
    Thanks for your help.
    Eduardo
    Vector graphs = new Vector();
    OAGraphTableBean graphTable = (OAGraphTableBean)webBean;
         Dictionary graphBarDetails = new ArrayMap(10);
    graphBarDetails.put("AGRFUNCTION", "none");
    graphBarDetails.put("GRAPHTYPE", "vertical clustered bar");
    graphBarDetails.put("GRAPHTITLE", "Cost Bar Graph");
    graphBarDetails.put("YAXISLABEL", "Allocation Amount");
    graphBarDetails.put("GRAPHSIZE", "medium");
    graphBarDetails.put("CUSTGRAPHWIDTH", "");
    graphBarDetails.put("CUSTGRAPHHEIGHT", "");
    graphBarDetails.put("DISPLAYTOOLTIP", BooleanUtils.getBoolean(true));
    graphBarDetails.put("XAXISLABEL", "");
    graphBarDetails.put("DRILLDOWNURL", "");
    graphBarDetails.put(DISPLAYED, BooleanUtils.getBoolean(true));
    Vector graphCols = new Vector();
    for(int j=0; j<2; j++) {
    Dictionary graphData = new ArrayMap(5);
    graphData.put("VIEWUSAGENAME", pViewUsage);
    if(j ==0) {
    graphData.put("VIEWATTRIBUTENAME", "AllocatedAmount");
    graphData.put("GRAPHDATASTYLE", "data");
    graphData.put("GRAPHDATAPROMPT", "Allocation Amount");
    else {
    graphData.put("VIEWATTRIBUTENAME", "AllocName");
    graphData.put("GRAPHDATASTYLE", "groupLabels");
    graphData.put("GRAPHDATAPROMPT","");
    graphData.put("GRAPHSTOCKVALUE","none");
    graphCols.addElement(graphData);
    graphBarDetails.put("GRAPHDATACOLS", graphCols);
    graphs.addElement(graphBarDetails);
    graphTable.setGraphDetails(graphs);

  • Setting ToolTips for items which are disabled.

    Folks,
    No offence meant if this is a repeat.
    I have a JPopupMenu with Action as its components.
    1) I have disabled certain menu items to false.
    2) I would like to use a ToolTipText to show a message 'You have no permission'
    when the user hovers over the menu items which are disabled/set to false
    3) I wrote my own ToolTipText,but what is happening is that I am getting the tool tip text
    for all menu items.
    Please can anyone help me in how to get tooltiptext for menu items which are enabled to false?
    Help much appreciated
    // JPopupMenu
    JPopupMenu pm = new JPopupMenu();
    // Add Action
    pm.add(new GraphAction());      
    pm.add(new DescendantsAction());
    pm.add(new DebugAction()).setEnabled(false);
    ToolTipTextForMenuItems.setToolTipForIndividualItem(pm.getComponent()) // Does not display any Tool Tip.
    pm.add(new ResetAction()).setEnabled(false);
    ToolTipTextForMenuItems.setToolTipTextForMenuItem(pm); // Shows ToolTipText for all menu items (disabled and enabled)
    ToolTip Code
    public class ToolTipTextForMenuItems {
    private static final String TOOL_TIP_TEXT = "You have no permission";
         public static void setToolTipTextForMenuItem(JPopupMenu popupMenu){
                 for (int i=0; i<popupMenu.getComponentCount(); i++){
                    Component c = popupMenu.getComponent(i);
                    if (c instanceof JComponent) {
                              ((JComponent)c).setToolTipText(TOOL_TIP_TEXT);
         public static void setToolTipForIndividualItem(Component c){
               if (c instanceof JComponent) {
                         ((JComponent)c).setToolTipText(TOOL_TIP_TEXT);
    }

    Yes,I have looked at the Abstract Action code sent in
    I have not used Action and Abstract Action before,hence if you can/could just
    modify this as per my requirement,then I can enhance on this.
    No offence meant for the above
    Thanks

  • Setting Tooltip on accordion section Does not work. Possible bug??

    HI All,
    I am using accordion control with following code.
    var oAccordion = new sap.ui.commons.Accordion("accordionA");
    //Building Section 1
    var oSection1 = new sap.ui.commons.AccordionSection( "section1" );
      oSection1.setTitle("Section 1kdfjkdasfjsdafffdfjkakfajfajfksafjdkfjdf");
    oSection1.setTooltip("Section 1");
      oSection1.setMaxHeight("100px");
      for (var i=0 ; i < 5 ; i++){  
    var oCheckBox1 = new sap.ui.commons.CheckBox( "CheckBox1"+i );
      oCheckBox1.setText("CheckBox1 "+i);
      oSection1.addContent( oCheckBox1);
    var oLabel1 = new sap.ui.commons.Label( "Label1"+i );
      oLabel1.setText("Label 1 "+i); 
      oSection1.addContent( oLabel1);
      oAccordion.addSection( oSection1 );
    Though I am setting the Tooltip. While mouse hover I don't see the tooltip.
    My thought is whenever sectionsTitle is truncated it should show the tooltip.
    Please clarify when the tooltip will be visibile.
    thank you for allyour inputs and help in advance.
    regards

    Hi there,
    It is a bug. You may use the title for each section until they get the tooltips to work.
    Regards,
    Alejandro.

  • Unable to set tooltip for item (sap.ui.core.Item)

    sap.ui.core.Item does not have the property 'tooltip'. But it borrows 'tooltip' property and setTooltip( ), getTooltip( ) methods from sap.ui.core.Element.
    Still, if I set the tooltip for item, it is not reflected. What might be wrong?
    Consider the following piece of code for example:
    var item = new sap.ui.core.Item({text:'Item'});
      item.setTooltip('tooltip');
      var oCollection = new sap.ui.ux3.Collection({ items: item
      var oCollectionInspector = new sap.ui.ux3.CollectionInspector({
      'fitParent' : false,
      'collections' : [
      new sap.ui.ux3.Collection({
      'title' : 'My Accounts',
      'items' : [ item]
      oCollectionInspector.placeAt('content');

    Tooltip is applied on the Item, but it seems Collection Inspector set its own tooltip for the Item. You can do something like this to set your own tooltip,
    var item = new sap.ui.core.Item("myItem",{text:'Item'});
    var oCollectionInspector = new sap.ui.ux3.CollectionInspector({
      'fitParent' : false,
      'collections' : [
      new sap.ui.ux3.Collection({
      'title' : 'My Accounts',
      'items' : [ item]
      oCollectionInspector.placeAt('content');
      oCollectionInspector.onAfterRendering = function(){
           sap.ui.ux3.CollectionInspector.prototype.onAfterRendering.apply(this,arguments);
           $('#myItem').attr('title','My Tooltip');

  • Setting tooltip when the content of the cell is not visible in jtable

    hello,
    i want to set a tooltip when the content of the cell is not visible in jtable
    please guide me.
    thanks
    daya

    thanks for your replay,
    i did in this way
    final TableColumn colTableColumn = getColumnModel().getColumn(vColIndex);
                        if (colTableColumn.getWidth() < this.getPreferredSize().width)
                            setToolTipText(value.toString());
                        else
                            setToolTipText(null);
                        }thanks
    daya

  • Setting tooltip on column headers in a datagridview

    How to show the tooltip only on the column headers(not on other cells)  of a datagridview, when the datagridview is databound?

    Hi TuffyP,
    In order to display the tooltip only in the header cells but not other cells, you need to disable the built-in tooltip showing functionality, and defines a new tooltip and show it when your mouse enters into the column header cells.
    The following is steps and code:
    1.       Disable built-in tooltip by setting the showcelltooltip property of DataGridView to false.
    Code Snippet
      this.dataGridView1.ShowCellToolTips = false;
    2.       Add CellMouseEnter event handler for DataGridView.
    Code Snippet
    this.dataGridView1.CellMouseEnter += new DataGridViewCellEventHandler(dataGridView1_CellMouseEnter);
    3.       Implement dataGridView1_CellMouseEnter method
    Code Snippet
            void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
                if (e.RowIndex == -1 && e.ColumnIndex!=-1)
                    tt.SetToolTip( this.dataGridView1,this.dataGridView1.Columns[e.ColumnIndex].HeaderCell.FormattedValue.ToString());
                else
                    tt.Hide(this.dataGridView1);
    If you have problems with the code, please don’t hesitate to let me know.
    Best Regards,
    Bruce Zhou

  • Is it possible to set tooltips from schema definition?

    Hi,
    I'm setting up my form to use a schema to bind fields.  What I'd like to do is to be able to define the tooltip to use for the field within the schema (so that for example when someone drags the field onto the form the tooltip is all set up too).
    Is this possible, I can't find any way of doing it.
    Thanks!

    Hi Ben,
    If you are trying to bind the tooltip of a field to an element in your data connection, then you can do that once "Show Dynamic Properties" is set in Options ... Data Binding, the Tooltip caption in the Accessibility pallette becomes a hyperlink that opens the binding dialog.
    If by within the schema you mean the under the annotation or documentation elements then, there doesn't seem to be a way to do it automatically but you can script it.  Refer to this document on schema binding generally http://partners.adobe.com/public/developer/en/livecycle/lc_designer_XML_schemas.pdf and this post on Schema Metadata http://forms.stefcameron.com/2009/08/28/schema-metadata/.
    That example uses Dublin Core appinfo but a documentation element works as well, so a schema element defined as;
       <xs:attribute name="timezone" type="xs:string" use="required">
        <xs:annotation>
         <xs:documentation>
                User time zone. This is not a time zone of any calendar, but the time zone in which events appear on Calendar UI. Long format time zone ID (not PST, but America/Los_Angeles)
         </xs:documentation>
        </xs:annotation>
       </xs:attribute>
    Will have the documentation text added to the bound field under the <desc> element (If you have "Generate Descriptive Information" set).
    <desc>
        <exData name="Schema Annotation">User time zone. This is not a time zone of any calendar, but the time zone in which events appear on Calendar UI. Long format time zone ID (not PST, but America/Los_Angeles)</exData>
    </desc>
    So in the initialise event of the field you could place the following JavaScript (where TZ is the field name).
    TZ.assist.toolTip.value = TZ.desc.nodes.namedItem('Schema Annotation').value;
    Regards
    Bruce

  • How to set tooltip time

    Hi!
    Can we set the time when a tooltip should be show or from which setting of the os is this derived?
    Regards
    Torsten

    Hi Torsten,
    in java use can use TooltipManager.setInitialDelay(milliseconds) so influence this, Maybe you can build a small bean which is included in your starting form to set this (didn't test this).

  • USEREXIT_FIELD_MODIFICATION in MV45AFZZ to set tooltip?

    Hi,
    i will set a tooltip for a specific field in VA02/03 (say Matnr). I try to use the exit
    USEREXIT_FIELD_MODIFICATION in MV45AFZZ.
    There is a possibility to change the structure SCREEN and it works but
    there is no way to set a tooltip.
    Does anyone know a way by using this EXIT or creating a SCREEN variant or
    any otehr way?
    Thanks.
    Regards, Dieter

    Hi,
    I still do not have my desired solution.
    I can not work with userexit_move_field_to_vbap because this userexit is called at the begin of creating a sales document.
    With Userexit_field_modification I still have the problem that I loose the value in VBAP-KTGRM when I leave the dynpro.
    My coding Inside Userexit_field_modification:
    CASE screen-name.
        WHEN 'VBAP-KTGRM'.
    Set to INPUT on when in Create or Change mode
          IF ( t180-trtyp = charh OR t180-trtyp = charv ).
             screen-input = 1.
          ENDIF.
      ENDCASE.
    These code lines make the field editable but I see no chance to save the entered value of VBAP-KTGRM.
    Thanks again,
    Tobi

  • Set a tooltip for a shape, not a button

    Hi everybody,
    Hope you are all ok wherever you are :)
    I have this little problem guys; I want to set a tooltip button in my application but the problem is that i'm not using buttons but shapes instead, in which shapes i've added mouse click handle code.
    I need when the mouse goes over these shapes-buttons i have, some tooltip text to be displayed. I've tried to create a rectangle and display the small text i want into that rectangle and then call repaint for restoring the program to the previous state before the tooltip display, but unfortunately it is too slow.
    Can you please help me out of that? Can you give a way of setting tooltips for shapes instead of buttons?
    Any help would be appreciated.
    Thanks,
    -John

    Your trying to set a tooltip for a given area on some JComponent defined by a Shape which holds the points that make up the border of the Shape, like GeneralPath or something like that? Is that what you mean? I'm not sure but I think you can use Shape.contains(Point2D ...) without actually have drawn the Shape, so that you can test where the mouse is on your JComponent, then check contains to see if a tooltip needs to be displayed. You'll have to write your own tooltip frame that's not dependent on a JComponent, but thats fairly straightforward. Don't know if this is any help to you, but its a possibility.
    Tom
    ioannisc: the OP talks about the use of Shape's, where did subclasses of JComponent come into it?!

  • How set location for tooltip text ??

    hi ,
    i want to set tooltip location myself to a button . for this i override methods are
    1. public String getToolTipText(MouseEvent e)2 public Point getToolTipLocation(MouseEvent e)here is code... where i have to change to set location for tooltip
    * DebugGraphicsTest.java
    * Created on April 28, 2005, 1:14 AM
    package swingtest;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    * @author  Paramasivam
    public class DebugGraphicsTest extends javax.swing.JFrame {
        public DebugGraphicsTest() {
            initComponents();
            MyButton  btn = new MyButton("Chem m e");
            btn.setToolTipText("this is actual");
            getContentPane().add(btn);
            jButton1.setToolTipText("button 1");
            jButton2.setToolTipText("button 2");
            jButton3.setToolTipText("button 3");
        /** 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.
        private void initComponents() {
            jPanel1 = new javax.swing.JPanel();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            jButton3 = new javax.swing.JButton();
            getContentPane().setLayout(new java.awt.FlowLayout());
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jButton1.setText("jButton1");
            jPanel1.add(jButton1);
            jButton2.setText("jButton2");
            jPanel1.add(jButton2);
            jButton3.setText("jButton3");
            jPanel1.add(jButton3);
            getContentPane().add(jPanel1);
            pack();
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new DebugGraphicsTest().setVisible(true);
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton3;
        private javax.swing.JPanel jPanel1;
        // End of variables declaration
    class MyButton  extends JButton{
        public MyButton(String s){
            super(s);
        public Point getToolTipLocation(MouseEvent evnt){
            return new Point(100,300);
        public String getToolTipText(){
            return "hihi";
        public String getToolTipText(MouseEvent me){
            return "event hihi";
    }

    Adding the line ToolTipManager.sharedInstance().registerComponent(this); to MyButton's constructor seems to solve the problem.

  • Tooltip for mousedragged

    I did a program in applet..I want to set tooltip for the drawing..i.e.,when the oval is dragged its new co-ordinates should be displayed by using the tooltip..How can i do this..
    .import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import java.awt.geom.Ellipse2D;
    import java.awt.geom.Line2D;
    import java.awt.geom.Point2D;
    import java.text.DateFormat;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.ArrayList;
    import java.util.Calendar;
    import java.util.Date;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.BorderLayout;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.BorderFactory;
    import javax.swing.border.Border;
    public class mouseevent extends JApplet
          private static final int BALL_DIAMETER = 40; // Diameter of ball
        //--- instance variables
        /** Ball coords.  Changed by mouse listeners.  Used by paintComponent. */
        private int _ballX     = 450;   // x coord - set from drag
        private int _ballY     = 50;   // y coord - set from drag
        /** Position in ball of mouse press to make dragging look better. */
        private int _dragFromX = 0;    // pressed this far inside ball's
        private int _dragFromY = 0;    // bounding box.
        /** true means mouse was pressed in ball and still in panel.*/
        private boolean _canDrag  = false;
        JLabel label;
        String s= "aswedfrtyhgqwsadrftlopqasnhfgrchildnode1";   
        int width = s.length();   
        int border = 2;    int margin = 10;   
        int rectx = margin+border,recty =margin+border+63;   
        int rectwidth = 8, rectheight = 6;   
        int imgborder = 10;   
        int imgline1 = 300;  
        int labellocx = rectx+imgborder+13;  
        int labellocy = recty+imgborder-1;   
        int circlex = rectx+rectwidth;
        int circley = recty+rectheight;  
        int x =rectx+rectwidth+10;  
        int y = recty+rectheight+10;
        int x1 = x+17; 
        int y1 = y+20;  
        int titlebarx= 300;
        int titlebary = 40;  
        boolean title = true;
        String date[] = {"0","4","8","12","16","20","24"}; 
        String day[] = {"Mon","Tue","Wed","Thu","Fri","Sat"};
        int width1 = 180;
    //    int f2= x+168;
        int n =180;
    //    int dayx = 385;
        long From ;
        long To ;
        ArrayList dateList;
         int rect1x= 300;
        int rect1y = 100;
        int rect1width= 50;
        int rect1heigth = 50;
        boolean candrag = false;
        public void init()     
            Container cont = getContentPane();   
            cont.setLayout(new BorderLayout());
            // to see the scrollpane, the scrollpane has to be smaller        
            // then the component held within its viewport             
            setPreferredSize(new Dimension(300, 300));             
            JScrollPane scroll = new JScrollPane();              
            getContentPane().add(scroll, BorderLayout.CENTER);        
            scroll.getViewport().add(new Imagepanel());       
    private class Imagepanel extends JPanel implements MouseListener,MouseMotionListener
            JScrollPane scroll = new JScrollPane();      
            Rectangle rect = new Rectangle(rectx,recty,rectwidth,rectheight);
            Rectangle rect1  = new Rectangle(rect1x,rect1y,rect1width,rect1heigth);
            Ellipse2D.Double circle = new Ellipse2D.Double(_ballX,_ballY,BALL_DIAMETER,BALL_DIAMETER);   
            Ellipse2D.Double circle1 = new Ellipse2D.Double(x+10,y+10,4,4);    
            boolean selected = false;  
            boolean selected1 = false;     
            int w ;     
        Imagepanel()       
            // setting the component to be largenr than the scrollpane           
            // just so we'll see scrollbars.
            setPreferredSize(new Dimension(32710,32710));      
            scroll = new JScrollPane();     
            add(scroll);                 
            addMouseListener(this);       
            addMouseMotionListener(this);
            setBorder(BorderFactory.createLineBorder(Color.BLACK, border));          
        protected void paintComponent(Graphics g)         
            int n = 168;
            int x = 300;
            int x1=300;
            int x2=x;
            int daydx=(width1/2);
            int dayx =(daydx+x);
            int f2= x+n;
            From = new java.util.GregorianCalendar(2007,01,01).getTime().getTime();
            To = new java.util.GregorianCalendar(2007,06,30).getTime().getTime();
            double Difference = To-From;
            long days = Math.round((Difference/(1000*60*60*24)));
            int noday = (int)days;
            Date fromDate = new java.util.GregorianCalendar(2007,01,01).getTime();
            Date toDate = new java.util.GregorianCalendar(2007,06,30).getTime();
            super.paintComponent(g);            
            Graphics2D g2 = (Graphics2D) g;             
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);       
            Font font = new Font("Ariel",Font.PLAIN,11); 
            Font font1 = new Font("Ariel",Font.PLAIN,9);
            g2.fillOval(_ballX, _ballY, BALL_DIAMETER-20, BALL_DIAMETER-20);
            g2.setBackground(Color.GRAY);
            //drawing the tilte bar     
            g2.setBackground(Color.WHITE);  
            g2.drawLine(imgline1,0,imgline1,getHeight()); 
            g2.setPaint(new Color(0,128,192));
            g2.fillRect(imgborder,imgborder,290,45);
            //g2.drawLine(margin,margin,titlebarx,titlebary);              
            //drawing the root node and labeling      
            g2.draw(rect);
            g2.setPaint(Color.WHITE);
            g2.drawLine(margin,margin,titlebarx,titlebary); 
            g2.drawString("RESOURCE",40,40);       
            g2.drawString("TIME",200,25);
            g2.setPaint(Color.green);
            g2.drawString("sadasd",344,22);
            g2.draw(circle);
            rect.setLocation(rectx,recty);      
            rect.setSize(rectwidth,rectheight);
            g2.setPaint(Color.BLACK);
            g2.drawString(" aswedfrtyhgqwsadrftlopqasnhfgrchildnode1",rectx+rectwidth+05,recty+rectheight);               
            for (int i = 0;i<noday;i++)
            Calendar  c = Calendar.getInstance(); // current date
                c.add(Calendar.DATE, i); // add one day
                SimpleDateFormat sdf = new  SimpleDateFormat("MM/dd/yy"); // use the pattern: day_of_month
                String str = sdf.format(c.getTime()); // fromat the date to string
                System.out.println(str); // print it at the console
                for (int j=0;j<6;j++)
                    g2.setFont(font1);
                    g2.drawLine(x1,40,x1,35);
                    g2.drawString(date[j],x1,35);
    //              g2.drawString(day[j],dayx,20);
                    g2.drawString("24",f2,35);
                    f2+=width1;
                    x1+=30;
    //              dayx=+170;
                g2.drawRect(x,10,width1,30);
                x+=width1;
                g2.drawString(str,dayx,20);
                dayx+=180;
            for(int k=0;k<n;k++)
                for(int l=0;l<6;l++)
                Calendar c = Calendar.getInstance(); // current datem
                c.add(Calendar.DAY_OF_WEEK, k); // add one day
                SimpleDateFormat sdf = new SimpleDateFormat("EEE"); // use the pattern: day_of_month
                String str = sdf.format(c.getTime()); // fromat the date to string
                System.out.println(str); // print it at the console
                g2.drawString(str,dayx,5);
    //          g2.drawString(day[l],dayx,20);
                dayx+=180;
            //dividing the drawing panel      
            //drawing for the click event       
            if(selected)       
                Color color = Color.orange; 
                g2.fill(circle);
                g2.draw(circle);          
                //              g2.drawRoundRect(x+30,y+15,200,12,5,5);        
                g2.drawString("aswedfrtyhgqwsadrftlopqasnhfgrchildnode1",x+15,y+5);     
                g2.drawRect(300,y,100,15);      
            if(selected1)      
                g2.setFont(new Font("Arial",Font.PLAIN,12)); 
                g2.fill(circle1);
                g2.draw(circle1);           
                g2.drawString(" aswedfrtyhgqwsadrftlopqmasnhfgrchildnode1",x1+15,y1+5);  
        public void update(Graphics g)    
            paint(g);   
        public void mouseClicked(MouseEvent e)          
            //imagePaneMouseClicked(e);              
        private void imagePaneMouseClicked(MouseEvent e)        
            Point p = e.getPoint();         
            if (rect.contains(p))                  
                if (!selected)              
                    selected = true;        
                    repaint();               
            if(circle.contains(p))     
                if(!selected1)           
                    selected1 = true;    
                    repaint();           
            if(rect.contains(p)) 
                if(e.getClickCount() == 2)    
                    selected = false;  
                    repaint();      
        public void mousePressed(MouseEvent e)        
             int x = e.getX();   // Save the x coord of the click
            int y = e.getY();   // Save the y coord of the click
            if (x >= _ballX && x <= (_ballX + BALL_DIAMETER)
                    && y >= _ballY && y <= (_ballY + BALL_DIAMETER)) {
                _canDrag = true;
                _dragFromX = x - _ballX;  // how far from left
                _dragFromY = y - _ballY;  // how far from top
            } else {
                _canDrag = false;
        public void mouseReleased(MouseEvent e) {        }               
        public void mouseEntered(MouseEvent e) {        }          
        public void mouseExited(MouseEvent e) { 
            candrag = false;
            public void mouseDragged(MouseEvent e) {
              if (_canDrag)
              {   // True only if button was pressed inside ball.
                //--- Ball pos from mouse and original click displacement
                _ballX = e.getX() - _dragFromX;
                _ballY = e.getY() - _dragFromY;
                //--- Don't move the ball off the screen sides
                _ballX = Math.max(_ballX, 0);
                _ballX = Math.min(_ballX, getWidth() - BALL_DIAMETER);
                //--- Don't move the ball off top or bottom
                _ballY = Math.max(_ballY, 0);
                _ballY = Math.min(_ballY, getHeight() - BALL_DIAMETER);
                this.repaint(); // Repaint because position changed.
                this.add(label);
                label.setText(""+_ballX+_ballY);
                label.setLocation(_ballX,_ballY);
            public void mouseMoved(MouseEvent e) {
    }

    The label is not getting displayed...the program throws some exception...
    Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
    at java.awt.Container.addImpl(Container.java:1015)
    at java.awt.Container.add(Container.java:351)
    at javaapplication5.mouseevent$Imagepanel.mouseDragged(mouseevent.java:346)
    at java.awt.Component.processMouseMotionEvent(Component.java:5536)
    at javax.swing.JComponent.processMouseMotionEvent(JComponent.java:3144)
    at java.awt.Component.processEvent(Component.java:5257)
    at java.awt.Container.processEvent(Container.java:1966)
    at java.awt.Component.dispatchEventImpl(Component.java:3955)
    at java.awt.Container.dispatchEventImpl(Container.java:2024)
    at java.awt.Component.dispatchEvent(Component.java:3803)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3909)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
    at java.awt.Container.dispatchEventImpl(Container.java:2010)
    at java.awt.Component.dispatchEvent(Component.java:3803)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Maybe you are looking for