Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2005

Tip: Looking for answers? Try searching our database.

Animated/sliding toolbar

Thread view: 
Ted Hill - 13 Apr 2005 20:02 GMT
I'm wondering how to program a toolbar that appears to 'slide' out into
a container panel.

I have a panel that displays images.

I want to have a toolbar available to the user to activate pan, zoom,
rotate, functionality etc.

Normally I want to hide the toolbar so that the entire panel will just
display the image.

But when the user moves the mouse to the top of the panel, I want the
toolbar to appear to 'slide' down into the panel to show itself.
Something similar to the Windows taskbar.

Right now I'm just showing/hiding the toolbar with setVisible(true/false).

Any suggestions on how to make it 'slide' into place would be appreciated,

Thanks,

Ted
John McGrath - 13 Apr 2005 22:26 GMT
> Right now I'm just showing/hiding the toolbar with
> setVisible(true/false).
>
> Any suggestions on how to make it 'slide' into place would be
> appreciated,

Use a javax.swing.Timer.  You set it up to run a Runnable in the event
thread on a fixed schedule (such as every 50 or 100 milliseconds).  Then
in the Runnable's run() method, you move the toolbar.

Signature

Regards,

John McGrath

Ted Hill - 14 Apr 2005 13:45 GMT
John,

Thanks for your response.

I have experience with javax.swing.Timer

but not sure how to "move the toolbar".

Currently, when I show/hide the toolbar with .setVisible(true/false),
the container panel has a BorderLayout and I've put the toolbar in at NORTH.

In order to move the toolbar:

1. Should I still use BorderLayout? or some other Layout?
2. Should I use no Layout and just absolute position?
3. Should I set a minimum/preferred size on the toolbar?
4. On each callback to the timer, should I use the setLocation(x,y)
method to actually move the component?

Any other advice?

Thanks,

Ted
Thomas Weidenfeller - 14 Apr 2005 14:54 GMT
> In order to move the toolbar:
>
[quoted text clipped - 5 lines]
>
> Any other advice?

Your ideas are not enough to slide the toolbar down. And please forget
about setLocation(). I haven't thought this through in all details, and
I have no intention to do so, but here is how I would approach the problem:

Don't do it :-)))

If this is not an option, I would start with defining some principle
behavior. E.g. what do you want?

a) Maybe you want that the contents of the rest of the window (below the
toolbar) is moving smoothly, too. This is maybe the most difficult case,
since the involved layout manager(s) would have to re-layout all that
stuff repeatedly and smoothly, while you gradually enhance the size of
the sliding toolbar. A lot of calculation and repainting might be going
on, and the result might be all but smooth. Gradually resizing the
toolbar component shouldn't be a big problem, but what these resizing
does to the other components might be. Try if the resizing works
smoothly, before you spend time on the gradual painting of the component.

b) Adding the toolbar immediately reserves the space for the complete
toolbar, and then gradually paints/slides the toolbar into that space.
The rest of the window would only have to be re-layouted once. The
disadvantages would be, that the rest of the window would "jump" once,
and you would have some void on top, which then starts to fill. I am not
sure if this would look ok.

c) The sliding toolbar overlaps with the window contents. In this case,
I would give Popup and PopupFactory a very good look, including the
source code of the classes in order to figure out if they can be
convinced to be resized gradually.

When you have settled on a behavior, you have to solve the next problem.
Gradually drawing the toolbar. Regarding the gradual painting in case a)
and b) I would probably consider messing with the paintComponent(), or
in this case even paint() method of the toolbar. A timer should trigger
repaints, which in turn should result in calls to paint(). I would try
to override paint in such a way that paint first manipulates the
Graphics contents by moving the origin and clipping region, before
calling the original method(). The more often paint() is called, the
smaller this manipulation should be, until you reach the final point. In
case this results in to much CPU time, I would think of letting the
first paint() go to some Image, and the following paints then gradually
draw parts from the image - until the image is painted completely. From
that point on I would direct the painting to the original method.

I have no idea if such a painting is also possible with c).

For extra points you might want to mess with the origins of events to
ensure the toolbar already works while you slide it down.

Oh, have you considered, that such a sliding might go on your user's
nerves? I for example hate many of that "eye candy" which delays things.
E.g. I don't like windows or menus which open or close with some animation.

The more I think about it, the more I like my original suggestion :-)

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

John McGrath - 14 Apr 2005 21:14 GMT
> I would start with defining some principle behavior.
> E.g. what do you want?
<snip>

That is almost exactly what I was fixing to say, but probably better said.
It does not make sense to ask how to implement something until you have
decided what that "something" is.

> Don't do it :-)))

That is probably very good advice, but I would suggest a slightly
different approach:  Don't do it now.

Anytime you have a feature that you think might be useful, or maybe just
plain cool, consider whether implementing it is the most important feature
that you can implement right now.  Is a sliding toolbar more important to
the success of your application than implementing the functions for the
toolbar buttons?  If it is not, put it on a list of "cool features" to
implement later.  When implementing the feature becomes the most important
thing you can do for the success of your application, that is the time to
work on it.

In practice, this often turns out to be the same as "Don't do it", since
there are always more important features to work on, but it is generally
a more palatable way to deal with the issue.  But sometimes, the features
do turn out to be significant, and become important once you complete the
basic functionality.

> Oh, have you considered, that such a sliding might go on your user's
> nerves? I for example hate many of that "eye candy" which delays things.
> E.g. I don't like windows or menus which open or close with some
> animation.

Same here.  When people put in "features" like this, it is always a good
idea to make them optional.

Signature

Regards,

John McGrath



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.