Basic custom layout manager question

Discussion in 'Java' started by Sam Takoy, Jun 9, 2010.

  1. Sam Takoy

    Sam Takoy Guest

    Hi,

    I'm writing a custom layout manager and here's what I don't understand.

    My experience tells that, generally speaking, there are two modes of
    layout. One, when the layout happens for the first time and all elements
    assume the size that they would most like.

    In the second mode, when the user resizes the JFrame, all elements
    inside just need to deal.

    So, in layoutContainer(Container parent), how do I know what mode it is?

    I guess the difference b/w the two modes is that in the former, I tell
    the parent what size to become. In the latter, the parent tells its
    children what size it wants to be.

    So how do I tell?

    Many thanks in advance,

    Sam
    Sam Takoy, Jun 9, 2010
    #1
    1. Advertising

  2. Sam Takoy

    Jeff Higgins Guest

    On 6/8/2010 8:13 PM, Sam Takoy wrote:
    > Hi,
    >
    > I'm writing a custom layout manager and here's what I don't understand.
    >
    > My experience tells that, generally speaking, there are two modes of
    > layout.


    Please be specific.

    > One, when the layout happens for the first time and all elements
    > assume the size that they would most like.
    >
    > In the second mode, when the user resizes the JFrame, all elements
    > inside just need to deal.
    >
    > So, in layoutContainer(Container parent), how do I know what mode it is?
    >
    > I guess the difference b/w the two modes is that in the former, I tell
    > the parent what size to become. In the latter, the parent tells its
    > children what size it wants to be.


    Please provide a pointer to the description of these modes in the
    documentation for the specific framework with which you are working.

    >
    > So how do I tell?


    Read the documentation?

    >
    > Many thanks in advance,
    >
    > Sam
    Jeff Higgins, Jun 9, 2010
    #2
    1. Advertising

  3. Sam Takoy

    Sam Takoy Guest

    On 6/8/2010 9:20 PM, Jeff Higgins wrote:
    > On 6/8/2010 8:13 PM, Sam Takoy wrote:
    >> Hi,
    >>
    >> I'm writing a custom layout manager and here's what I don't understand.
    >>
    >> My experience tells that, generally speaking, there are two modes of
    >> layout.

    >
    > Please be specific.


    Read my question
    Sam Takoy, Jun 9, 2010
    #3
  4. Sam Takoy

    Gene Guest

    On Jun 8, 8:13 pm, Sam Takoy <> wrote:
    > Hi,
    >
    > I'm writing a custom layout manager and here's what I don't understand.
    >
    > My experience tells that, generally speaking, there are two modes of
    > layout. One, when the layout happens for the first time and all elements
    > assume the size that they would most like.
    >
    > In the second mode, when the user resizes the JFrame, all elements
    > inside just need to deal.
    >
    > So, in layoutContainer(Container parent), how do I know what mode it is?
    >
    > I guess the difference b/w the two modes is that in the former, I tell
    > the parent what size to become. In the latter, the parent tells its
    > children what size it wants to be.
    >
    > So how do I tell?
    >
    > Many thanks in advance,
    >
    > Sam


    This doesn't make much sense. The layout must take a given container
    size and lay out/resize the contained components to fit. This is the
    pack() operation. Whether the container is being drawn initially or
    after a resize makes no difference at all.
    Gene, Jun 9, 2010
    #4
  5. Sam Takoy

    Sam Takoy Guest

    On 6/8/2010 10:29 PM, Gene wrote:
    > On Jun 8, 8:13 pm, Sam Takoy<> wrote:
    >> Hi,
    >>
    >> I'm writing a custom layout manager and here's what I don't understand.
    >>
    >> My experience tells that, generally speaking, there are two modes of
    >> layout. One, when the layout happens for the first time and all elements
    >> assume the size that they would most like.
    >>
    >> In the second mode, when the user resizes the JFrame, all elements
    >> inside just need to deal.
    >>
    >> So, in layoutContainer(Container parent), how do I know what mode it is?
    >>
    >> I guess the difference b/w the two modes is that in the former, I tell
    >> the parent what size to become. In the latter, the parent tells its
    >> children what size it wants to be.
    >>
    >> So how do I tell?
    >>
    >> Many thanks in advance,
    >>
    >> Sam

    >
    > This doesn't make much sense. The layout must take a given container
    > size and lay out/resize the contained components to fit. This is the
    > pack() operation. Whether the container is being drawn initially or
    > after a resize makes no difference at all.


    Doesn't the pack() operation go "inside-out". In other words, the
    contained components suggest to the container what size it should be?
    Sam Takoy, Jun 9, 2010
    #5
  6. Sam Takoy

    markspace Guest

    Sam Takoy wrote:

    > Doesn't the pack() operation go "inside-out". In other words, the
    > contained components suggest to the container what size it should be?



    I looked at this recently, due to someone else's question, and the
    answer turns out to be "no." As near as I can tell from examining the
    code, all operations are strictly "top down" from the root container to
    each of it's components to each of their components.

    Thus, both the initial "size" and the subsequent "resize" is the same,
    from the layout manager's point of view.
    markspace, Jun 9, 2010
    #6
  7. Sam Takoy

    Sam Takoy Guest

    On 6/8/2010 11:16 PM, markspace wrote:
    > Sam Takoy wrote:
    >
    >> Doesn't the pack() operation go "inside-out". In other words, the
    >> contained components suggest to the container what size it should be?

    >
    >
    > I looked at this recently, due to someone else's question, and the
    > answer turns out to be "no." As near as I can tell from examining the
    > code, all operations are strictly "top down" from the root container to
    > each of it's components to each of their components.
    >
    > Thus, both the initial "size" and the subsequent "resize" is the same,
    > from the layout manager's point of view.
    >


    So, perhaps pack() has some special features on top of the layout logic?
    Sam Takoy, Jun 9, 2010
    #7
  8. Sam Takoy

    markspace Guest

    Sam Takoy wrote:

    >
    > So, perhaps pack() has some special features on top of the layout logic?



    Not really. I think it just calls preferredLayoutSize(Container) first,
    to set its own bounds, then it lays out the container with those same
    bounds. (This is a good reason for a layout manager to cache results.)

    It doesn't matter though. Just implement your LayoutManager according
    to the Java docs and the rest will work out. Only if you're
    implementing a top level window yourself, it might matter.
    markspace, Jun 9, 2010
    #8
  9. In article <humu2b$q3d$-september.org>,
    Sam Takoy <> wrote:

    > On 6/8/2010 9:20 PM, Jeff Higgins wrote:
    > > On 6/8/2010 8:13 PM, Sam Takoy wrote:
    > >> Hi,
    > >>
    > >> I'm writing a custom layout manager and here's what I don't understand.
    > >>
    > >> My experience tells that, generally speaking, there are two modes of
    > >> layout.

    > >
    > > Please be specific.

    >
    > Read my question


    I too believe your modality premise is false, but I would welcome a
    counter example.

    <http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/420e9da9a927201f>

    --
    John B. Matthews
    trashgod at gmail dot com
    <http://sites.google.com/site/drjohnbmatthews>
    John B. Matthews, Jun 10, 2010
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ***C.Steamer***

    Creating a Custom Circular Layout Manager!

    ***C.Steamer***, Oct 6, 2004, in forum: Java
    Replies:
    5
    Views:
    1,500
    Scott Robert Ladd
    Oct 6, 2004
  2. Replies:
    1
    Views:
    564
    John Timney \(MVP\)
    Jun 19, 2006
  3. padma
    Replies:
    0
    Views:
    337
    padma
    Oct 3, 2007
  4. Mark Space
    Replies:
    4
    Views:
    676
    Mark Space
    Oct 5, 2007
  5. Metalone
    Replies:
    0
    Views:
    334
    Metalone
    Jan 6, 2010
Loading...

Share This Page