Results 1 to 6 of 6
  1. #1
    Renegade85 is offline Member
    Join Date
    Nov 2007
    Posts
    25
    Rep Power
    0

    Default [SOLVED] Help Using ToolTipText Please

    Hi, i am trying to use a tooltiptext for a JButton.

    I am writing it in as

    Java Code:
    jbtCalculate.setToolTipText( "Calculates the total return of the bet") ;
    and it is giving me back this error

    Java Code:
    StakePanel.java:26: <identifier> expected
        jbtCalculate.setToolTipText( "Calculates the total return of the bet") ;
                                   ^
    StakePanel.java:26: illegal start of type
        jbtCalculate.setToolTipText( "Calculates the total return of the bet") ;
                                     ^
    2 errors
    Any ideas what i am doing wrong?

    BTW, i am using a Panel to do this in if that makes a difference :confused:

  2. #2
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    10

    Default

    are you sure you imported the tooltexttip and I'm not sure if you can add one to a panel.
    My IP address is 127.0.0.1

  3. #3
    Renegade85 is offline Member
    Join Date
    Nov 2007
    Posts
    25
    Rep Power
    0

    Default

    Quote Originally Posted by Zosden View Post
    are you sure you imported the tooltexttip and I'm not sure if you can add one to a panel.
    These are what i have imported

    Java Code:
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.text.*;
    and as far as i'm aware, it's in the import javax.swing.*; one

    EDIT

    I have changed the code to the following:
    Java Code:
    jttCalculate = new JToolTip();
    jttCalculate.setTipText("Calculates the total return of the bet");
    jttCalcualte.setComponent(jbtCalculate);
    Still not working though :(

    Getting these errors

    Java Code:
    StakePanel.java:22: <identifier> expected
    	 jttCalculate= new JToolTip();
    	             ^
    StakePanel.java:23: <identifier> expected
    	 jttCalculate.setTipText("Calculates the total return of the bet");
    	                               ^
    StakePanel.java:23: illegal start of type
    	 jttCalculate.setTipText("Calculates the total return of the bet");
    	                                ^
    StakePanel.java:24: <identifier> expected
    	 jttCalcualte.setComponent(jbtCalculate);
    	                          ^
    StakePanel.java:24: <identifier> expected
    	 jttCalcualte.setComponent(jbtCalculate);
    	                                       ^
    5 errors
    Last edited by Renegade85; 04-25-2008 at 04:53 PM.

  4. #4
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    11

    Default

    No need to use JToolTip...

    It's already inherited from JComponent......

    I think there is no wrong about setting the tooltiptext....
    I don't know.. bec you didn't show us your complete code....

    Here is an example,

    Java Code:
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JButton;
    
    public class test extends JFrame{
    
    	public test(){
    		JButton jb = new JButton("Click here");
    		jb.setToolTipText( "Would you like to click me?");
    		add(new JPanel().add(jb));
    		setBounds(100,100,100,100);
    		setDefaultCloseOperation(3);
    	}
    
    	public static void main(String args[]){
    		new test().setVisible(true);
    	}
    }
    Last edited by sukatoa; 04-26-2008 at 03:37 AM.
    freedom exists in the world of ideas

  5. #5
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    10

    Default

    The way I used tooltip before is just add it to the component I want with the specified string. I never declared and created a tooltip object
    My IP address is 127.0.0.1

  6. #6
    Renegade85 is offline Member
    Join Date
    Nov 2007
    Posts
    25
    Rep Power
    0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •