Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Tooltip support is actually provided by the <code>TableCellRenderer</code> directly. Your <code>TableCellRenderer</code> is a little muddled. It extends from <code>DefaultTreeCellRenderer</code> but makes no use of any of it's features, instead creating a new <code>Box</code>, <code>JButton</code> and loading icons each time a cell is rendered...</p> <p>This is going to increase your memory usage a slow you application down...</p> <p>Instead, try something like...</p> <pre><code>class PCellRenderer extends Box implements TreeCellRenderer { private Image imgToUse = null; private Image imgRollOver = null; public PCellRenderer() { super(BoxLayout.X_AXIS); JButton myButton = new JButton("test"); try { URL urlIcon = new URL("file:///C:/1.jpg"); // &lt;===== change their the path to icons imgToUse = ImageIO.read(urlIcon); urlIcon = new URL("file:///C:/2.jpg"); // &lt;===== change their the path to icons imgRollOver = ImageIO.read(urlIcon); } catch (IOException e) { e.printStackTrace(); } myButton.setRolloverIcon(new ImageIcon(imgRollOver)); myButton.setIcon(new ImageIcon(imgToUse)); add(myButton); } public Component getTreeCellRendererComponent(JTree ptree, Object pvalue, boolean psel, boolean pexpanded, boolean pleaf, int prow, boolean phasFocus) { // set the tooltip text here... // Maybe change the icon... return this; } } </code></pre> <p>Now, actually doing something...</p> <p>Renderers are rubber stamps. That are not actually life components. Think of them like photos. You can take a snap shot of your friends, but you can't interact with them...same thing here...</p> <p>Your idea of a <code>MouseListener</code> on the <code>JTree</code> is a correct one, in fact the <a href="http://docs.oracle.com/javase/7/docs/api/javax/swing/JTree.html" rel="nofollow">JavaDocs</a> actually have a demonstration of this...</p> <pre><code>public void mousePressed(MouseEvent e) { int selRow = tree.getRowForLocation(e.getX(), e.getY()); TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); if(selRow != -1) { if(e.getClickCount() == 1) { mySingleClick(selRow, selPath); } else if(e.getClickCount() == 2) { myDoubleClick(selRow, selPath); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload