aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes make node blink in jtree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "make node blink in jtree" Watch "make node blink in jtree" New topic
Author

make node blink in jtree

pavan in
Ranch Hand

Joined: Oct 22, 2002
Posts: 64
Is it possible to make a node blinking in jtree?If yes, how?
When the usr clicks on a button, I want the node selected to start blinking and when the user clicks on another button, it should stop blinking.
Thanks.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Here's a short example...



-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
pavan in
Ranch Hand

Joined: Oct 22, 2002
Posts: 64
Cool. Thanks a looot.
pavan in
Ranch Hand

Joined: Oct 22, 2002
Posts: 64
Nathan,
One more requirement.
when the user clicks on node 1 and clicks start.Node 1 should start blinking (works fine with the code you have given)). Now, the user clicks on another node (node 2). node 1 should be blinking while node 2 should be shown as normal selection. is it possible to do this task?
Thanks.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Here's how I changed the code to save what nodes were blinking... Though at this point the nodes themselves are having to remember a lot about their state, so I would start putting this behavior in the objects in the model rather than just the renderer...

pavan in
Ranch Hand

Joined: Oct 22, 2002
Posts: 64
Thanks Nathan.
I should make the tree -> jtree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
is it right?
But, I want only one node to be selected at any point.so, i have set the selection model as SINGLE_TREE_SELECTION.
is it possible to make the node 1 blinking and still be able to select only 1 node?
pavan in
Ranch Hand

Joined: Oct 22, 2002
Posts: 64
Nathan,
In the above example, when i select node 2, the node 1 stops blinking. because, 'value' is changed when the user selects another node.isnt it?
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

The selection changes only if you call the blink() method of the tree again...

And it shouldn't matter if you use single selection. The new code saves whatever nodes are selected (whether it is one or many) when the blink() method of the tree is called. Then those nodes blink until either blinking is turned off, or a new node selection is made by calling the blink() method again.
pavan in
Ranch Hand

Joined: Oct 22, 2002
Posts: 64
Nathan,
Once I select node 2 in the tree, the node 1 which was blinking gets deselected and node 2 is highlighted. but, i want node 1 to blink while node 2 is highlighted.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Have you run the second code posting?

It does exactly that!

Click a node (node 1).

Click "start".

node 1 blinks.

Now you can select any other nodes, and node 1 is still blinking.
[ March 13, 2003: Message edited by: Nathan Pruett ]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Just a thought - A Sun (I think Sun) tutorial on Timer suggested it as an alternative to managing your own threads for blinking and other animation effects. The main advantage is that it can manage many timers on only one thread for a little less overhead.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: make node blink in jtree