How to unSelect a JTree??

R

Ramon F Herrera

I have a problem with JTrees: the user can click away
selecting a set of paths (with the usual <shift> and
<control> keys) but there is no click method that will
restore the tree to its original, pristine, unselected
state.

What I would like to implement is the familiar Mac and
Windows icon selection: when the user clicks on the
desktop all the file icons become unselected.

I figured out how to perform the actual unselection:

if (tree == leftTree && rightTree.getLastSelectedPathComponent() != null)
rightTree.setSelectionPath(null);

However, I don't know what event should trigger the above
response. The only Tree Listener seems to be 'valueChanged'
which is fired only when one of the folders is clicked.

How can I detect a click on the background of a tree??

TIA,

-Ramon F Herrera
 
A

Andrew Thompson

What I would like to implement is the familiar Mac and
Windows icon selection: when the user clicks on the
desktop all the file icons become unselected.

What 'File Icons'?

I just checked what happens when you have a node
selected in a tree of Outlook Express then click the
DeskTop, it changes from blue to grey.. It does
not become 'deselected' as you suuggest.

Might I suggest that the user is better off
without you imposing your bizarre ideas of how
their trees should work? [ It would be more
logical for them to get used to a consistent
Look and Feel of their own choosing, than have
that same L&F 'tweaked' at random according to
the ideas of individual developers.. ]

Oh, and a better group for such questions is..
<http://www.physci.org/codes/javafaq.jsp#cljg>

HTH
 
R

Ramon F Herrera

Andrew Thompson said:
What 'File Icons'?

The very familiar icons introduced by Xerox and popularized
by the Macintosh and Windows. They have the name of a file
and when you double click on them the file is opened by the
corresponding associated application.

My point is that you can always bring back those icons to
unselected, by clicking on their background, in an empty
stop where there are no icons.

-Ramon
 
R

Ramon F Herrera

Andrew Thompson said:
Might I suggest that the user is better off
without you imposing your bizarre ideas of how
their trees should work? [ It would be more
logical for them to get used to a consistent
Look and Feel of their own choosing, than have
that same L&F 'tweaked' at random according to
the ideas of individual developers.. ]

You say tomatoe, I say tomato...
You say bizarre, I say it makes perfect sense.

Andrew: you know very well that the Tree widget is one
of the most complicated in the Swing universe. There
is no way the designers could have foretold all the
possibles uses, and very wisely left plenty of room for
the end developer to add extra functionality. Some of
GUI aspects are purposedly incomplete, you are supposed to
fill the blanks.

My application has not one, but two trees next to each other.
The user makes a selection and the application performs some
actions based on the last selected set of leaves. The user may
click somewhere on the left tree, change his mind and then go
exploring the right tree. I am trying those two trees, which
represent two different logical views of the same thing, to behave
as a single tree. When the user begins selections on one tree,
the past selections on the other(s) tree should disappear
visually, because now we are dealing with another tree altogether.

"Bizarre" is the current way my app is working. The user clicks
away in both trees, and when the "process" button is pressed
he is left wondering: "what was that last tree that I clicked on?
Is is going to perform the computations on the right or on the
left tree selection". And this would be the reaction of an
advanced user, a less observant user would be left in a state
of confusion.

The JTree designers "forgot" (I bet on purpose) to provide a
construct called "Set of Trees". They said: "we provide the
building blocks, let the designers implement the forest".

-Ramon
 
T

Thomas Weidenfeller

Ramon said:
Andrew: you know very well that the Tree widget is one
of the most complicated in the Swing universe.

Sorry, I disagree. It is one of the simplest non-trivial widgets. You
want something complicated? Try JTable. Even some of the simple widgets
like JSpinner or JComboBox do behave more badly.
I am trying those two trees, which
represent two different logical views of the same thing, to behave
as a single tree.

So you are using the widget well outside of its specification. Why are
you complaining? If you need such a specific widget, write your own.
When the user begins selections on one tree,
the past selections on the other(s) tree should disappear
visually, because now we are dealing with another tree altogether.

So what is wrong with registering a TreeSelectionListener and calling

clearSelection()

on the other tree? To simple?
The JTree designers "forgot" (I bet on purpose) to provide a
construct called "Set of Trees".

One constructor to create multiple (a set of) GUI objects? Doesn't sound
like a great idea to me.
They said: "we provide the
building blocks, let the designers implement the forest".

No, they said "We provide widgets for the common cases. Programmers (not
designers) who need more have to do what programmers are paid for:
programming.

/Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,130
Latest member
MitchellTe
Top