From: Sam Takoy on 5 Apr 2010 19:17 Hi, Here's what I don't get fundamentally about the Layout managers and the available documentation doesn't explain. The documentation seems to suggest that the layout process is bottoms up: the children are laid out first, then the parents. I think that makes sense for the "pack" command, but not for the when the user re-sizes the window. Is the a place where the procedure for laying out components actually described? Or could someone explain it? Thanks! Sam
From: markspace on 5 Apr 2010 20:03 Sam Takoy wrote: > The documentation seems to suggest that the layout process is bottoms > up: the children are laid out first, then the parents. I think that > makes sense for the "pack" command, but not for the when the user > re-sizes the window. Is the a place where the procedure for laying out > components actually described? Or could someone explain it? It actually varies, depending on how each component is configured. For example, a component with isValidateRoot() equal to true stops the layout process for any component above it. You might try looking at the source code. I'm sure that's well documented. For example, in my own CustomLayout, I can set a breakpoint in layoutContainer() and see the call stack. There are several calls to validateTree() and then a call do doLayout() on the call stack. Immediately preceding those is a call to validate() and then pack(), so I assume that's where it starts. I really think you'd be better off to learn how to control an existing layout to do what you want, rather than try to write your own. I took a peak inside the layoutContainer() method of a simple layout manager, BoxLayout, and even that code is pretty complicated. I don't think you're going to enjoy having to debug and maintain your own custom class.
From: Roedy Green on 6 Apr 2010 17:54 On Mon, 05 Apr 2010 19:17:12 -0400, Sam Takoy <sam.takoy(a)yahoo.com> wrote, quoted or indirectly quoted someone who said : > >The documentation seems to suggest that the layout process is bottoms >up: the children are laid out first, then the parents. I think that >makes sense for the "pack" command, but not for the when the user >re-sizes the window. Is the a place where the procedure for laying out >components actually described? Or could someone explain it? It is completely up to you, the author of the layout manager, to figure out how to lay out the pieces. The layout manager works with only one layer at a time, e.g. the JPanel. Any JPanels within that are handled separately, so that to the layout mananger they just look like Components. I suggest you look at the source for some existing layout managers. Your layout manager has a list of components to place. It can ask the components their preferred, max and min sizes. It then decides how big to make them, does a setSize and setLocation. In addition it has the object you glued to the component when you did your add. It contains your proprietary information about how to do the layout, e.g. a GridBagConstraints For an overview of the process see http://mindprod.com/jgloss/layout.html http://mindprod.com/jgloss/layoutmanager.html -- Roedy Green Canadian Mind Products http://mindprod.com Programs are abstract structured data. They map better onto 3D visual structures than they do onto linear streams of characters. We have to gently break the strangehold of the written language metaphor for programs before we can make any major progress. An IDE ginergerly decorates text with graphics. We need to evolved that to a SCID with graphics ginergly decorated with text, where the dynamic graphics tell nearly all the story.
|
Pages: 1 Prev: store variables in a jsp page scope with the spring framework Next: Fun with casts |