<html><head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Adding a tool tip</title><meta name="generator" content="DocBook XSL Stylesheets V1.61.2"><link rel="home" href="book.html" title="Developing Graphical User Interfaces with FXRuby"><link rel="up" href="tutorial1.html" title="Chapter 3. Hello, World!"><link rel="previous" href="ch03s03.html" title="Messages"><link rel="next" href="ch03s05.html" title="Adding an icon"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Adding a tool tip</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch03s03.html">Prev</a> </td><th width="60%" align="center">Chapter 3. Hello, World!</th><td width="20%" align="right"> <a accesskey="n" href="ch03s05.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="d0e868"></a>Adding a tool tip</h2></div></div><div></div></div><p>To wrap up this introduction, we'd like to add a few finishing touches to the program. The first addition is to add a tool tip to the button, such that when the mouse cursor hovers over the button for a short while, it will pop up a little message describing what the button does:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">require 'rubygems' require_gem 'fxruby' include Fox theApp = FXApp.new theMainWindow = FXMainWindow.new(theApp, "Hello") theButton = FXButton.new(theMainWindow, "Hello, World!") <span class="bold"><b>theButton.tipText = "Push Me!"</b></span> theButton.connect(SEL_COMMAND) { exit } <span class="bold"><b>FXToolTip.new(theApp)</b></span> theApp.create theMainWindow.show theApp.run</pre></td></tr></table><p>There are two changes involved here. The first is to set the tool tip text for the button using the <tt class="methodname">tipText</tt> accessor, and for this example we're setting the button's tip text to "Push Me!". The second change is to create the (single) <tt class="classname">FXToolTip</tt> instance for the application. Although this program shows the <tt class="classname">FXToolTip</tt> instance being created after the <tt class="classname">FXButton</tt>, it doesn't really matter when you do it. You just want to have instantiated the <tt class="classname">FXToolTip</tt> before you drop into the main event loop by calling <tt class="methodname">FXApp#run</tt>. If you run this version and hover over the button for a second or so, you should see the tooltip pop up:</p><div class="screenshot"><div class="mediaobject" align="center"><img src="images/hello-with-tooltip.png" align="middle"></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch03s03.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="tutorial1.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch03s05.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Messages </td><td width="20%" align="center"><a accesskey="h" href="book.html">Home</a></td><td width="40%" align="right" valign="top"> Adding an icon</td></tr></table></div></body></html>