Example usage for javax.swing JTree setToolTipText

List of usage examples for javax.swing JTree setToolTipText

Introduction

In this page you can find the example usage for javax.swing JTree setToolTipText.

Prototype

@BeanProperty(bound = false, preferred = true, description = "The text to display in a tool tip.")
public void setToolTipText(String text) 

Source Link

Document

Registers the text to display in a tool tip.

Usage

From source file:org.apache.jmeter.gui.MainFrame.java

/**
 * Create and initialize the GUI representation of the test tree.
 *
 * @param treeModel//from   w ww  . j  av a2  s.c  om
 *            the test tree model
 * @param treeListener
 *            the test tree listener
 *
 * @return the initialized test tree GUI
 */
private JTree makeTree(TreeModel treeModel, JMeterTreeListener treeListener) {
    JTree treevar = new JTree(treeModel) {
        private static final long serialVersionUID = 240L;

        @Override
        public String getToolTipText(MouseEvent event) {
            TreePath path = this.getPathForLocation(event.getX(), event.getY());
            if (path != null) {
                Object treeNode = path.getLastPathComponent();
                if (treeNode instanceof DefaultMutableTreeNode) {
                    Object testElement = ((DefaultMutableTreeNode) treeNode).getUserObject();
                    if (testElement instanceof TestElement) {
                        String comment = ((TestElement) testElement).getComment();
                        if (comment != null && comment.length() > 0) {
                            return comment;
                        }
                    }
                }
            }
            return null;
        }
    };
    treevar.setToolTipText("");
    treevar.setCellRenderer(getCellRenderer());
    treevar.setRootVisible(false);
    treevar.setShowsRootHandles(true);

    treeListener.setJTree(treevar);
    treevar.addTreeSelectionListener(treeListener);
    treevar.addMouseListener(treeListener);
    treevar.addKeyListener(treeListener);

    // enable drag&drop, install a custom transfer handler
    treevar.setDragEnabled(true);
    treevar.setDropMode(DropMode.ON_OR_INSERT);
    treevar.setTransferHandler(new JMeterTreeTransferHandler());

    addQuickComponentHotkeys(treevar);

    return treevar;
}