AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Painting a Stack with Swing

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits
View previous topic :: View next topic  
Author Message
froorider
Guest





PostPosted: Thu Sep 29, 2005 9:54 am    Post subject: Painting a Stack with Swing Reply with quote



Hy,

I want to make my own swing component. The component should paint a
dynamic stack. The stack contains some panels. These panels should be
painted horizontally or vertically. At init time of the component, an
"empty" stack view with an initial size should be painted.

I used a Panel with a BorderLaout. The stack view is in the center of
it. On the left side, there is a JLabel showing some information. The
problem is, that the "empty" stack is not painted at all. I tired to
fill the stack with empty images but this doesn't worked.

Does someone now how to deal with that or knows a Swing lib with a
predefined layout manager, component or something like that? The
component I want to develop is for a Visualization.

Thanks.

The component should look like this:

------------------------------------
Quote:
| | |
| ------------ | |
| | PALLET 3 | | |
| ------------ | |
| ------------ | |
Place 510 | | PALLET 2 | | |
| ------------ | |
| ------------ | |
| | PALLET 1 | | |
| ------------ | |
| | |
------------------------------------



Back to top
Roedy Green
Guest





PostPosted: Thu Sep 29, 2005 1:29 pm    Post subject: Re: Painting a Stack with Swing Reply with quote



On 29 Sep 2005 02:54:02 -0700, "froorider" <t.hasler (AT) retis (DOT) ch> wrote
or quoted :

Quote:
I want to make my own swing component. The component should paint a
dynamic stack. The stack contains some panels. These panels should be
painted horizontally or vertically. At init time of the component, an
"empty" stack view with an initial size should be painted.

The problem is the default size for your panels would be 0,0 since
they contain nothing.

There are three basic approaches to tackling your problem.

1. You fool around with different layout managers, creating dummy
components, doing setMinimumSize set PreferredSize and setMaxmimuSize,
playing with GridBagLayout weights etc. until you trick Swing into
producing the effects you want. I would give FlowLayout a try for the
right-hand stack section with the variable number of items. Remember
to validate/repaint after every pop/push. See
http://mindprod.com/jgloss/layout.html

2. If no layout will give you the effects you want, write you own. See
http://mindprod.com/jgloss/layoutmananger.html. It is much easier
than you think.

3. If the "panels" are not complex panels in their own right but
merely coloured bars, or labelled bars, overwrite paintComponent on
your main panel, examine the total size of the panel, allocate it to
your stack items, and fillRect some rectangles and drawString on the
labels. The logic is very similar to writing your own LayoutManager. A
LayoutManager would not do any drawing, just the placement.


The advantage of the "StackLayoutManager" is it becomes a much more
reusable component. Code that uses it is much easier to maintain with
application logic, placement logic, and drawing logic nicely
separated.





--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Back to top
froorider
Guest





PostPosted: Fri Sep 30, 2005 6:44 am    Post subject: Re: Painting a Stack with Swing Reply with quote



Thank you for your hints. I've already begun to write a custom
LayoutManager. I called it StackLayout. When I'm finished with it, I
will post the code somewhere.

Greetz

Tom

Back to top
Roedy Green
Guest





PostPosted: Fri Sep 30, 2005 7:21 am    Post subject: Re: Painting a Stack with Swing Reply with quote

On 29 Sep 2005 23:44:34 -0700, "froorider" <t.hasler (AT) retis (DOT) ch> wrote
or quoted :

Quote:
Thank you for your hints. I've already begun to write a custom
LayoutManager. I called it StackLayout. When I'm finished with it, I
will post the code somewhere.

Good. A Layout is a little harder to get you head around, but the end
product is much cleaner. See
http://mindprod.com/jgloss/starlayout.html

It is the source code for the world most mindlessly simple layout
manager. It is an absolute layout manager that arranges components in
star shaped patterns, e.g. compass points, VCR buttons, clocks.

Looking at the source should help you grab the concepts of what you
need to do in your layout manager, without overwhelming you with
details.

The nice thing is, when you are done, the StackLayout will behave
itself under all conditions without futzing about trying to trick it
into behaving. Further, you will also have a much deeper
understanding of layouts in general, which is nice to have under your
belt.

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.