Re: Painting a Stack with Swing
- From: Roedy Green <my_email_is_posted_on_my_website@xxxxxxxxxxxxxx>
- Date: Thu, 29 Sep 2005 13:29:13 GMT
On 29 Sep 2005 02:54:02 -0700, "froorider" <t.hasler@xxxxxxxx> wrote
or quoted :
>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.
.
- References:
- Painting a Stack with Swing
- From: froorider
- Painting a Stack with Swing
- Prev by Date: Re: Can no longer use arrow keys to move cursor around an AWT TextArea after upgrading to JDK 1.4.2.07
- Next by Date: Re: Always on top JDialog or JWindow
- Previous by thread: Painting a Stack with Swing
- Next by thread: Re: Painting a Stack with Swing
- Index(es):
Relevant Pages
|
|