Article View: borland.public.jbuilder.java.swing
Article #7540Re: Applet, JTree, setCursor problem
From: Jim H.
Date: Wed, 17 Jan 2001 15:33
Date: Wed, 17 Jan 2001 15:33
168 lines
6195 bytes
6195 bytes
Torsten thanks. You articulated what I found but did not understand. I
solved my problem...
..........................................
/***************************************************************************
*********************
* Gets mouse events and passes them on the node for processing.
*
* Note: MouseListener did not work! The only method invoked was
mouseEntered and it only
* worked for the root node. mouseExited was never called.
Therefore, a
* MouseMotionListener was used successfully.
*
*/
class MyMouseListener implements MouseMotionListener
{
NodeBase lastNode = null;
private NodeBase getNode( MouseEvent e)
{
NodeBase node = null;
TreePath selPath = _jTree.getPathForLocation( e.getX(), e.getY());
if ( selPath != null )
{
node =
(NodeBase)((DefaultMutableTreeNode)selPath.getLastPathComponent()).getUserOb
ject();
}
return( node);
}
public void mouseMoved( MouseEvent e)
{
NodeBase node = getNode( e);
if ( node != lastNode )
{
if ( lastNode != null ) lastNode.mouseExited( e);
if ( node != null ) node.mouseEntered( e);
lastNode = node;
}
}
public void mouseDragged( MouseEvent e)
{
mouseMoved( e);
}
}
...............
_jTree.addMouseMotionListener( new MyMouseListener( ));
"Torsten Welches" <torsten.welches@who.cares.netcologne.de> wrote in message
news:3a657033$1_1@dnews...
>
> Jim,
>
> a TreeCellRenderer is only used to *paint* the nodes, it is not
> part of the JTree as a visual component.
> Tooltips work because JTree overrides getToolTipText appropriately.
>
> Torsten
>
> "Jim H." <jgh@metafile.com> wrote:
> >For 2+ days I have been trying to alter the cursor from the default to
the
> >wait and hand with no luck.
> >
> >I have an Applet with a JTree. Some of the tree nodes may be clicked to
> >issue a server request using a background thread. I would like to
display
> >the hand cursor for these nodes. And, while the server request is
> >outstanding, I would like to display the wait cursor. Otherwise, I want
to
> >display the default cursor for all the other tree nodes.
> >
> >I have set the component's (a JLabel) cursor using the following code:
> >------------------------------------
> > public Component render(
> > Component dspComp // The
> >displayed component
> > , JTree tree
> >// The tree structure
> > , DefaultMutableTreeNode node // The
current
> >tree node
> > , boolean isSelected //
Is
> >node selected
> > , boolean isExpanded // Is
> >folder expanded
> > , boolean isLeaf
//
> >Is node a leaf
> > , int row
> >// Row in the tree
> > , boolean hasFocus //
Does
> >node have focus
> > )
> > {
> > JLabel jLabel = (JLabel)super.render( dspComp // The displayed
> >component
> > , tree // The tree
> >structure
> > , node // The current
tree
> >node
> > , isSelected // Is node
selected
> > , isExpanded // Is folder
> >expanded
> > , isLeaf // Is node a
leaf
> > , row // Row in the
tree
> > , hasFocus // Does node
have
> >focus
> > );
> >
> >
> > Cursor jc = Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR);
> >
> > if ( _nodeFailure )
> > {
> > jLabel.setIcon( _damagedIcon);
> > jLabel.setToolTipText( MSG_ERROR);
> > }
> > else if ( isLoadInProgress() )
> > {
> > jLabel.setIcon( _notLoadedIcon);
> > jLabel.setToolTipText( MSG_LOADING);
> > if ( hasFocus) jc = Cursor.getPredefinedCursor(
> >Cursor.WAIT_CURSOR);
> > }
> > else if ( !isLoadCompleted() )
> > {
> > jLabel.setIcon( _notLoadedIcon);
> > jLabel.setToolTipText( MSG_CLICK_TO_LOAD);
> > if ( hasFocus) jc = Cursor.getPredefinedCursor(
> >Cursor.HAND_CURSOR);
> > }
> >
> > jLabel.setCursor( jc);
> > return( jLabel);
> > }
> >---------------------------------------------
> >
> >The tool-tips work great! However, the cursor does not change! Under
the
> >debugger and examining the jLabel, the cursor is changed. But it just is
> >not visually displayed. Only the default cursor is shown.
> >
> >I have tried a mouse listener without success. The above seems simple
and
> >straight forward, but ineffective.
> >
> >Any ideas?
> >
> >Thanks!
> >
> >
> >
>
Technical Details
Message-ID:
<3a65bb81_2@dnews>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!isdnet!newsfeeds.belnet.be!news.belnet.be!skynet.be!newsfeed1.uni2.dk!newssuck.uni2.dk!bornews.borland.com!dnews!208.226.57.227References:
<3a635b19_2@dnews> <3a657033$1_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,fc00ca3aea35938b X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2001-01-17 07:42:27 PST Reply-To: "Jim H." <jgh@metafile.com> From: "Jim H." <jgh@metafile.com> Newsgroups: borland.public.jbuilder.java.swing References: <3a635b19_2@dnews> <3a657033$1_1@dnews> Subject: Re: Applet, JTree, setCursor problem Date: Wed, 17 Jan 2001 09:33:29 -0600 Lines: 170 X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 208.226.57.227 Message-ID: <3a65bb81_2@dnews> X-Trace: 17 Jan 2001 07:34:25 -0800, 208.226.57.227 Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!isdnet!newsfeeds.belnet.be!news.belnet.be!skynet.be!newsfeed1.uni2.dk!newssuck.uni2.dk!bornews.borland.com!dnews!208.226.57.227