source event type in DefaultSingleSelectionModel

J

Joe

User clicks on a tabbed pane of several. I've subclassed
DefaultSingleSelectionModel so that I can display a dialog window
before the chosen tabbedpane is actually displayed. My dialog is
displayed from within the setSelectedIndex() method of my subclass.

My problem is that I want to filter events so that I only display this
dialog when it comes from clicking on a tabbed pane and not a JTree
node (which is what is currently happening).

---
tabbedPaneListener = new TabbedPaneListener(this);
tabbedPane = new JTabbedPane();
tabbedPane.addTab("tab", mypanel);
SingleSelectionModel tabModel = new TabbedSelectionModel(this);
tabbedPane.setModel(tabModel);
tabbedPane.addChangeListener(tabbedPaneListener);
---

For some reason, clicking on a JTree node also sends the same event as
a tabbed pane and I need to filter between the two.

Also, the TabbedPaneListener (where I could get the event source),
comes after the point that I need the source type which is in
setSelectedIndex(). So first setSelectedIndex() gets called, then the
stateChanged() from the listener gets called, and I need the source
type inside the setSelectedIndex().

Anyone have ideas?
 
D

Daniele Futtorovic

User clicks on a tabbed pane of several. I've subclassed
DefaultSingleSelectionModel so that I can display a dialog window
before the chosen tabbedpane is actually displayed. My dialog is
displayed from within the setSelectedIndex() method of my subclass.

My problem is that I want to filter events so that I only display
this dialog when it comes from clicking on a tabbed pane and not a
JTree node (which is what is currently happening).

--- tabbedPaneListener = new TabbedPaneListener(this); tabbedPane =
new JTabbedPane(); tabbedPane.addTab("tab", mypanel);
SingleSelectionModel tabModel = new TabbedSelectionModel(this);
tabbedPane.setModel(tabModel);
tabbedPane.addChangeListener(tabbedPaneListener); ---

For some reason, clicking on a JTree node also sends the same event
as a tabbed pane and I need to filter between the two.

This sounds rather odd.
Also, the TabbedPaneListener (where I could get the event source),
comes after the point that I need the source type which is in
setSelectedIndex(). So first setSelectedIndex() gets called, then the
stateChanged() from the listener gets called, and I need the source
type inside the setSelectedIndex().

There is no "source" at that level. The tab change could originate from
various actions, user actions or programmer action. It isn't monolinear.

There may be some hacks to get your issue resolved, but the behaviour
you described smells a bit fishy, so rather than suggesting some, I
think at first your time ought rather be spent trying to figure out:
Why does the SelectionModel of your JTabbedPane fire a stateChanged()
when a JTree node (?) gets clicked?
If you want this NG to help you out with that, it would be best if you
provided a "Short, Self-Contained Correct Example", or maybe a few
screenshots showing what's happening (the code will later probably be
needed anyway).
 

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,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top