Tooltip over a TreeNode in JTree

We are trying to get the tooltip for a TreeNode to show up directly over the text of the node so that when the TreeNode text is clipped by a JSplitPane divider it can be seen completly as a tooltip. Our interface is very similar to Explorer where there is a file system tree on the left and a table on the right. We want the tooltip to show up just like it does in Explorer. We have tried numerous different techniques, but am unable to get the tooltip to show up directly over the node and to the right of the TreeNode's icon.
Any help you can give would be greatly appreciated... and I'll throw in some duke dollars too. What the heck, I've got so many, I don't know what to do with them. ;-)
Thanks,
Troy

Override the getToolTipLocation(MouseEvent e) method in your JTree to display the tooltip in the desired location(directly over the tree node).
Try this piece of code. I've used it in my application and it works!
public Point getToolTipLocation(MouseEvent event)
Point location = null;
     Point point = event.getPoint();
     TreePath path = getPathForLocation(point.x, point.y);
     if (path != null && isTextVisible(path) == false)
          TreeCellRenderer renderer = getCellRenderer();
          java.awt.Component c =
               renderer.getTreeCellRendererComponent(
               this,path.getLastPathComponent(),false,
               false,false,0,false);
          if (c instanceof JLabel)
               JLabel label = (JLabel)c;
               int icon = label.getIcon() == null
                    ? 0 : label.getIcon().getIconWidth();
               Rectangle cellBounds = getPathBounds(path);
               location = new Point(cellBounds.x icon label.getIconTextGap(), cellBounds.y);
          return location;
private boolean isTextVisible(TreePath path)
     Rectangle cellBounds = this.getPathBounds(path);
     Rectangle visibleRect = this.getVisibleRect();
     if ((visibleRect.width - cellBounds.x) < cellBounds.width)
          return false;
     return true;
}

Similar Messages

  • Editing JPanel of TreeNode in JTree

    Hi all,
    I am badly stuck with one issue.
    I have a Jtree, some of the node of Jtree contains panel, panels also has some components JtextField and JLabels.
    Tree is generating properly. Node containing Panel shows all the
    components (TextField and Labels).
    The only problem is I am not able to edit the Textbox of JPanel.
    Pls help me out.

    Override the getToolTipLocation(MouseEvent e) method in your JTree to display the tooltip in the desired location(directly over the tree node).
    Try this piece of code. I've used it in my application and it works!
    public Point getToolTipLocation(MouseEvent event)
    Point location = null;
         Point point = event.getPoint();
         TreePath path = getPathForLocation(point.x, point.y);
         if (path != null && isTextVisible(path) == false)
              TreeCellRenderer renderer = getCellRenderer();
              java.awt.Component c =
                   renderer.getTreeCellRendererComponent(
                   this,path.getLastPathComponent(),false,
                   false,false,0,false);
              if (c instanceof JLabel)
                   JLabel label = (JLabel)c;
                   int icon = label.getIcon() == null
                        ? 0 : label.getIcon().getIconWidth();
                   Rectangle cellBounds = getPathBounds(path);
                   location = new Point(cellBounds.x icon label.getIconTextGap(), cellBounds.y);
              return location;
    private boolean isTextVisible(TreePath path)
         Rectangle cellBounds = this.getPathBounds(path);
         Rectangle visibleRect = this.getVisibleRect();
         if ((visibleRect.width - cellBounds.x) < cellBounds.width)
              return false;
         return true;
    }

  • Tooltips over graphics objects

    Hi All
    Hope you all had a merry Christmas.
    Does anyone know if i can add a tooltip to a graphics objects?
    Basically i am drawing a series of rectangles in a JPanel and when i hover my mouse over each rectangle i want a different tip to display...however if i use the setToolText() method it sets it for the entire JPanel? any ideas?

    tooltip-like popup with mouseover

  • Display a tooltip over a word [was: I should know this....]

    I don't remember what it's called or how to do it.
    I want to create a little text bubble that appears on mouseover a particular word, similar to the Alt text that appears upon mouseover an image.
    The word I want to mouseover may or may not be a link - not sure yet.
    Thanks for your help.
    J
    [Subject line edited by moderator to indicate nature of question]

    The delay is set automatically by the browser. To get a faster response, you can use CSS. You'll find a lot of results if you Google "CSS tooltips".
    Unfortunately, IE6 supports the :hover pseudo-class only on links. If you're using Dreamweaver CS4, you can use the Spry Tooltip widget, which works cross-browser (as long as JavaScript is enabled).

  • Filechooser with tooltips over each file

    Hi,
    I have made a FileChooser which extends JFileChooser.
    I would like to have tooltips for each of the files shown in the view. The info shown in each tooltip would be derived from the file itself. I can already get the info but I dont know how to apply the tooltips.
    Any ideas?
    Cheers,
    Jim

    Set an accessory for the file chooser. The accessory should implement PropertyChangeListener. When selection is changed use something like this
        public void propertyChange(PropertyChangeEvent e) {
            String prop = e.getPropertyName();
            if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(prop)) {
                file = (File) e.getNewValue();
            }to get file and show tooltip.
    Regards,
    Stas

  • JTree - show tooltip

    Just want some feedback. I want to show tooltips for nodes in a Jtree. When I hover over a node in the tree I get the information I want to display in the tooltip.
    I was thinking about adding a mouse listener to the tree, and in the mouseEntered method...get the node which is located at the point where the mouse was moved and get the info for it...then set the tooltip for that node in the tree node cell renderer.
    Is there some better way or any other info. u can think of about this? Is this the best way?
    thanks

    Here's an example:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    public class TreeToolTip extends JFrame {
         private JScrollPane scrollPane;
         private JTree tree;
         public TreeToolTip() {
              try {
                   setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                   scrollPane = new JScrollPane();
                   getContentPane().add(scrollPane, BorderLayout.CENTER);
                   tree = new JTree() {
                        public String getToolTipText(MouseEvent e) {
                             Object tip = null;
                             TreePath path = getPathForLocation(e.getX(), e.getY());
                             if (path != null) {
                                  tip = path.getLastPathComponent();
                             return tip == null ? null : tip.toString();
                   ToolTipManager.sharedInstance().registerComponent(tree);
                   scrollPane.setViewportView(tree);
                   pack();
                   setSize(300, 200);
                   setLocationRelativeTo(null);
                   setVisible(true);
              } catch (Exception e) { e.printStackTrace(); }
         public static void main(String[] args) { new TreeToolTip(); }
    }

  • How do I keep states active on a image after applying a tooltip?

    Hi. I'm making a portfolio website and have a series of thumbnail images.  I had set up the images to start at 50% opacity, and then become fully opaque as you roll over them. This worked great until I applied a tooltip over each image so I could surface text to describe each thumbnail.  Once I had the tooltip working, I realized that my states no longer change on the thumbnail once you roll over them.
    Does anyone know how to combine the two effects or have a workaround that could help me accomplish this?  Also, the text sufaces off to the side, away from the thumbnail.
    thanks!

    just found a workaround but if anyone has a better solution, please let me know.
    workaround is to delete the original image and instead load that thumbnail image as the tooltip fill.  from there you can adjust the opacity at different states and get the desired effect.

  • Tooltip doesn't show with own component

    Hello,
    I have my own component that paints some rectangles to a
    canvas. Now the problem is that I can't see the tooltip over my
    object. Here is wat I do
    var record:SessionRecord = new SessionRecord();
    record.height = TIMELINEHEIGHT;
    record.width = data.SESSION_TIME*TIMELINE_SECOND;
    record.x =
    ((data.SESSION_START_SEC*TIMELINE_SECOND)+MARGINLEFT)/2;
    record.y = yCanvasPointer/2;
    record.toolTip = "blabjdsqodhqhjiouqh";
    record.enabled = true;
    canvas.addChild(record);
    I've implemented the get/set method of the tooltip in my
    component class (actionscript class).
    public override function get toolTip():String
    return this.tooltipText;
    public override function set toolTip(value:String):void
    this.tooltipText = value;
    Anybody any idea ?
    Thanks!
    Ward

    quote:
    Originally posted by:
    Greg Lafrance
    The FB3 help topic "About creating advanced components"
    mentions the following about Flex components implemtning the
    IToolTipManagerClient interface:
    IToolTipManagerClient - Indicates that a component has a
    toolTip property, and therefore is monitored by the ToolTipManager.
    So maybe if you implement this interface you will have
    tooptip support.
    This is the interface I implemented (specifying the get/set
    tooltip methode)...

  • DnD: custom TransferHandler and JTree

    Hi!
    I have seen a similar post like this one before, but there was no real answer.
    When I use the standard TransferHandler for DnD in a JTree, things work the way they should. However, when I use my own custom subclass of TransferHandler, no dragging behaviour is to be seen. Obviously, some crucial piece of code is missing from my class, but what is it?
    public class TopicTransferHandler extends TransferHandler {
        private TM4J_FSControllerFactory factory;
        private Object objectInTree = null;
        public TopicTransferHandler(TM4J_FSControllerFactory factory) {
         super();
         this.factory = factory;
        protected Transferable createTransferable(JComponent c) {
         Transferable trans = null;
         // if we are dragging from a tree (should always be the case)...
         if (c instanceof FSTree) {
             // then we let the HTMController construct a transferable from
             // the currently selected object in the tree
             FSTree tree = (FSTree) c;
             HandleTopicMirrorController mc =
              factory.createMirrorController(true);
             trans = mc.getTransferable(objectInTree);
             System.out.println("createTransferable(): " + trans);
         return trans;
        public int getSourceActions(JComponent c) {
         return COPY_OR_MOVE;
    }I appreciate any help!
    Dunk

    Hello!!
    I was having the same problem, but using the source code of TransferHandler and the tutorial I finally got it!! Eba!!
    /** Check http://java.sun.com/docs/books/tutorial/uiswing/misc/dnd.html
    * @author Stenio L. Ferreira
    * Created on 20/08/2003
    * [email protected]
    import javax.swing.*;
    import java.awt.datatransfer.*;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import javax.swing.tree.*;
    import com.exactus.vbcomponentes.*;
    public class JTreeTransferHandler extends TransferHandler {
         protected Transferable createTransferable(JComponent c) {
              return new StringSelection(exportString(c));
         public int getSourceActions(JComponent c) {
              return COPY_OR_MOVE;
         protected String exportString(JComponent c) {
              DefaultMutableTreeNode treeNode =
                   (DefaultMutableTreeNode) ((JTree) c)
                        .getSelectionPath()
                        .getLastPathComponent();
              Node meuNode = (Node) treeNode.getUserObject();
              Integer result = new Integer(meuNode.getMeuId());
              return (result.toString());
         private static class DragHandler implements MouseMotionListener {
              MouseEvent firstMouseEvent;
              public void mousePressed(MouseEvent e) {
                   firstMouseEvent = e;
                   e.consume();
              public void mouseDragged(MouseEvent e) {
                   if (firstMouseEvent != null) {
                        e.consume();
                        int dx = Math.abs(e.getX() - firstMouseEvent.getX());
                        int dy = Math.abs(e.getY() - firstMouseEvent.getY());
                        //Arbitrarily define a 5-pixel shift as the
                        //official beginning of a drag.
                        if (dx > 5 || dy > 5) {
                             JComponent c = ((JTree) e.getSource());
                             JTreeTransferHandler th =
                                  (JTreeTransferHandler) c.getTransferHandler();
                             Transferable t = th.createTransferable(c);
                             th.exportDone(c, null, NONE);
                             firstMouseEvent = null;
              public void mouseReleased(MouseEvent e) {
                   firstMouseEvent = null;
              public void mouseMoved(MouseEvent e) {
    }Hope this helps!

  • Selecting a node in a JTree knowing his path

    Hello for all,
    I'm trying to select a specific node in a JTree component by clicking a button.. this is my code :
    private DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode("root");
    private DefaultTreeModel treeModel = new DefaultTreeModel(treeNode);
    private JTree tree = new JTree(treeModel);
    private JButton button = new JButton("Select");
    DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("child1");
    DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("child2");
    child1.add(new DefaultMutableTreeNode("child11"));
    treeNode.add(child1);
    treeNode.add(child2);
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        TreePath path = new TreePath(new Object[]{"root", "child1"});               
        tree.setExpandsSelectedPaths(true);
        tree.scrollPathToVisible(path);
    });as you can see, I want to select the node with the path "root/child1"..
    but I'm getting this exception : Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to javax.swing.tree.TreeNode..
    any ideas ?

    You will want to read the second sentence in the TreePath comments section.
    Also, read the second sentence in the TreePath Method Detail section for the
    getLastPathComponent method.
    With these clues &#8212; try getting a TreePath from the tree you are working with.
    For example, you can try something like tree.getPathForRow(row) using the
    visible row index of "child1". Since the TreePath returned comes from the tree
    it will understand what to do with it. You can check the class name of the
    components that are returned in the TreePath to confirm this. And it will
    explain the exception you quoted.

  • Search JTree for a node

    Hi everyone,
    Lets say I have a JTree such as:
    Root
    -Child1
    --Child1_1
    -Child2
    Now is there a method which given the name of a node, eg. Child1_1 can go and get that node? By get i mean i have the above tree then i say:
    currentNode = Child1_1;
    tree.getNode(currentNode);
    I know there are methods that can do this if the node has been selected but in my case it has to be done without the node being selected.
    Hope i've made it clear!
    Thanks.

    Hello.
    There is no such built-in method because it all depends on what kind of node you use. The String (name) representing a node is really a rendering thing.
    Assuming you're using a DefaultTreeModel with DefaultMutableTreeNodes :public static TreeNode findNode(JTree aTree, Object aUserObject) {
         if (aTree == null) throw new IllegalArgumentException("Passed tree is null");
         if (aUserObject == null) throw new IllegalArgumentException("Passed user object is null");
         DefaultMutableTreeNode node = (DefaultMutableTreeNode)aTree.getModel().getRoot();
         return findNodeImpl(node, aUserObject);
    private static DefaultMutableTreeNode findNodeImpl(DefaultMutableTreeNode aNode, Object aUserObject) {
         if (aNode.getUserObject().equals(aUserObject)) return aNode;
         int childCount = aNode.getChildCount();
         for (int i = 0; i < childCount; i++) {
              DefaultMutableTreeNode child = (DefaultMutableTreeNode)aNode.getChildAt(i);
              DefaultMutableTreeNode result = findNodeImpl(child, aUserObject);
              if (result != null) return result;
         return null;
    }

  • Icefaces - tooltip on items in HtmlSelectOneListbox

    Im trying to display a tooltip over an item as the user selects/highlight it in a HtmlSelectOneListbox. It seems that SelectItem UI doesnt have a setTitle. Any other way to get around this. I can't even capture the highlight event (only the value change ). I dont mind setting title to the whole HtmlSelectOneListbox but I need to capture the highlight event in the listitems/selectitems because the title/tooltip is dependent on which item is selected.
    Thanks for any help in advance

    Hi,
    You should go to ICEsoft forum for any needed info, problems.
    http://www.icefaces.org/main/product/woodstock-migration.iface
    Thanks.
    /krys

  • MapViewer geometry theme 'mouse_click' doesn't always work in FF3

    I have code that works with IE7 but not FireFox 3 (I'm using MapViewer Ver1033p5_B080908 and an 11.1.0.6 db). I've been able to duplicate it by only slightly modifying Oracle Maps demo #5, "Theme Based FOI layer visibility". Code is shown below.
    I'm displaying two geometry themes. I need to know when the user clicks on either theme or the background. I add the themes and call setEventListener('mouse_click') for both themes and the mapview. In IE7 I get the expected result - one of the three handlers gets called depending on where I click. In FF3 (specifically 3.0.3) only the "top" theme's mouse handler is active. Cicking on the bottom theme - even when there is no overlap at all - only calls the mapview's handler. Same is true with info tooltips - they display for both themes in IE7, but only for the top theme in FF3. (http://www.navsys.com/BruceB/mapviewer.gif shows the two themes - one green, the other pink. On FF3 I never get a "hand" cursor or a tooltip over any of the pink areas, and clicking calls the mapview handler, not the theme handler.)
    Incidently if I hide the "top" theme, then the mouse clicks/tooltip work again on the other theme.
    Is this expected?
    Thanks!
    -Bruce
    <html>
    <head>
    <META http-equiv="Content-Type" content="text/html" charset=UTF-8">
    <TITLE>Map Cache Server/Map Client</TITLE>
    <link rel="stylesheet" type="text/css" href="../t.css" />
    <script language="Javascript" src="/mapviewer/fsmc/jslib/oraclemaps.js"></script>
    <script language=javascript>
    var mapview;
    function showMap()
    var baseURL = "http://"+document.location.host+"/mapviewer";
    var mapCenterLon = -83.498
    var mapCenterLat = 31.453;
    var mapZoom = 4;
    var mpoint = MVSdoGeometry.createPoint(mapCenterLon,mapCenterLat,8307);
    mapview = new MVMapView(document.getElementById("map"), baseURL);
    mapview.addMapTileLayer(new MVMapTileLayer("mapdata.demo_map"));
    mapview.setCenter(mpoint);
    mapview.setZoomLevel(mapZoom);
    mapview.setEventListener('mouse_click',backgroundClick);
    addThemeBasedFOI();
    mapview.addNavigationPanel() ;
    mapview.display();
    function addThemeBasedFOI()
    var themebasedfoi1 = new MVThemeBasedFOI('themebasedfoi1','grim.T_121_GBOTEST_70265_F');
    themebasedfoi1.enableAutoWholeImage(true) ;
         themebasedfoi1.setEventListener('mouse_click',theme1clicked);
    mapview.addThemeBasedFOI(themebasedfoi1);
    var themebasedfoi2 = new MVThemeBasedFOI('themebasedfoi2','grim.TR_GBOTEST_86094_F');
    themebasedfoi2.setEventListener('mouse_click',theme2clicked);
    mapview.addThemeBasedFOI(themebasedfoi2);
    function setVisible(item)
    var themebasedfoi = mapview.getThemeBasedFOI(item.value);               
    themebasedfoi.setVisible(!themebasedfoi.isVisible());
    function theme1clicked(pt,foidata,me)
         alert('Tour clicked');
    function theme2clicked(pt,foidata,me)
         alert('Best clicked');
    function backgroundClick()
    alert('background click');
    </script>
    </head>
    <body onload="javascript:showMap();">
    <h3>Oracle Maps example - show/hide Theme Based FOI layers </h3>
    <ul>
    <LI ><INPUT TYPE="checkbox" value="themebasedfoi1" onclick="setVisible(this)" checked/>Show County population layer
    <LI ><INPUT TYPE="checkbox" value="themebasedfoi2" onclick="setVisible(this)" checked/>Show Customer layer
    </ul>
    <div id="map" style="left:0px;top:10px;width:100%; height:60%"></div>
    <HR/>
    </body>
    </html>

    Alan McClean has alluded to the cause of this behaviour but I think others would benefit from a full explanation because it doesn't appear to be documented. I might add that Business Objects support were no help at all on this (they suggested I had a problem with my mouse, PC or network which I don't).
    Normal response to a mouse double-click on a document name in InfoView XI3:
    The double-click action performs the default action on the right-click list. This is the option you see in bold when you right-click on a document name. The default action is 'View' document. So when you double-click on the document it opens for viewing.
    In CMC, under Applications>InfoView if you set 'Default viewing action on listing page:' to 'View the latest successful instance of the object' then the double-click behaviour changes:
    The double-click action now tries to open the latest successful instance of a document. I found that any document in my Inbox or any document with instances (e.g. scheduled report) will still open for viewing using the double-click. For any other document the double-click fails silently. I assume this is because there simply isn't a latest instance to open.
    Conclusions:
    1. Don't use the 'View the latest successful instance of the object'. I have reset my CMC setting back to 'View the object'.
    2. I think Business Objects should change the double-click behaviour so that rather than fail silently it opens the document.

  • Creating a "ribbon" style menu with Muse?

    Is it possible to do a scrolling thumbnail "ribbon" in Muse? I'm trying to achieve the effect of having a small window that has several thumbnails in it that the user can scroll through to change the target. If not, how do we get that as a requested feature for Muse? It would be insanely useful, and I know a lot of other users would want to use something similar.

    Hi Julia,
    I understand that I can tooltip over them, but what I'm looking for is something that will allow me to do something like this example on the main page for Lionsgate.com. The functionality I want is to be able to present the player with a menu of thumbnail buttons which will change a main display, very much like what you illustrated above. What is different, however, is that I want the user to be able to SCROLL a list of thumbnails which are contained within a menu window. In this way, if I wanted to have links to twenty or fifty or a hundred buttons/thumbnails, I can present the player with only a few at a time without completely cluttering the interface. They can use arrow keys to scroll up or down through the available thumbnails. It's a very common interface, and Apple uses the ribbon idea as part of their main interface. 
    Long story short, is it possible to replicate this with existing Muse widgets, or does someone know of a not-too crazy way to do this?
    Thanks,
    Neal

  • I upgraded to mavericks and now my wi-fi doesn't connect

    I recently (and reluctantly) upgraded my MacBook Pro to Mavericks (OS 10.9.2) so that it would be in sync with my desk tops. After doing so, I discovered that  Wi-Fi is inoperative. Tooltip over the wi-if symbol shows "Wi-Fi: No hardware installed" and running diagnostics through system preferences: network simply contnues to scan without result.

    Well, couple of options. As an FYI, the "No Hardware Installed" error is usually an indicator of hardware failure. It is VERY hard for software to damage hardware, so odds are, if this is a hardware issue, Mavericks wasn't what broke it. But, before taking it in for service, there are a couple of options that we have.
    Option 1)
    Rule out software issues.
    To do this, open keychain access (easiest way is to open spotlight with command+spacebar, type in keychain, open keychain access by clicking it). From here, find your wireless settings, it should have your SSID in the name. Delete these. Yes, that means you need to know your wifi password.
    Open a "go to the folder" window. You can do this by opening finder, and pressing command+shift+g on the keyboard. Once that's open, copy and paste this into it:
    /library/preferences
    From here, scroll to the bottom to find a folder named "SystemConfiguration"
    Drag and drop this folder to the desktop (don't want to trash it yet. This file should auto restore, but just in case it doesn't, having a backup is nice). It will ask for your admin password.
    Once this is moved (make sure it's also deleted from /library/preferences!), restart the system.
    Once the computer is off for the restart, let's do an SMC reset.
    Did that bring your wireless back up? If not, odds are, we're looking at a hardware issue. You have the option to take this in for service, and if it's in AppleCare, that's what I would do. You also have some 3rd party options. If this wasn't in warranty, I would grab a USB wireless receiver and just use that. Gets the job done for about $30-$50.
    Note: These steps may cause your energy saver settings to reset. If you have anything customized, you can set it back up via system preferences -> energy saver after the restart.
    Option 2)
    Don't worry about ruling out software, just take it in for repair.
    Option 3)
    Don't worry about either, use ethernet.

Maybe you are looking for

  • Settlement to cost center posted for statistical WBS element

    We have the following scenario Statistical WBS elements with assigned Cost center posted for actual postings Network assigned to statistical WBSE and settlement rule on the same WBSE On settlement run CJ88  the network costs are transferred from netw

  • Patch for Macromedia Director 6.0 Upgrade for Windows - DOES ANYBODY STILL HAVE IT?

    Hello, I am a collector of 1990's multimedia who likes seeking out older, pre-Adobe versions of Director. I have the upgrade version of Director 6.0 for Windows, and it's unfortunately part of an early batch that comes with a corrupted copy of the Pr

  • How to extend material in storage location automatically???

    Dear Gurus, We have 9 plants in this company. Every time we create a material we have to extend it in all plants. Because it takes to long to do this one by one with MM01 we use mm17 and we created there a variant that extends the materials in all pl

  • STO's created from TLB

    Hello Experts: When I create STO's, I don't see any source of default values, like Delivery Tolerance, Confirmation control key, etc, that for a PO usually come from the Vendor or The Info Record. We have managed to add these values via BADI, but for

  • Error occurred while building the following file

    hi, i get an error while compilating my programm. i did not change the vis listed below, they are standard express vi's... An error occurred while building the following file: C:\Program Files\National Instruments\LabVIEW 8.0\vi.lib\express\express a