Article View: borland.public.jbuilder.java.swing
Article #9587Re: JSplitPane does not remember the divider
From: John P. McGrath
Date: Thu, 02 Mar 2000 00:00
Date: Thu, 02 Mar 2000 00:00
62 lines
3599 bytes
3599 bytes
On Wed, 1 Mar 2000 17:32:56 -0500, Oliver Chiu wrote: > I don't really figure out how to avoid this. It look fine > when I compiled and run the program. However, the splitpane > divider will always go back to its original position in the > designer. It's annoying to reset every panel everytime when > I use the designer. Can someone tell me how to fix this ? And in an e-mail message, Oliver Chiu wrote: > What do you mean by realized the JSplitPane? This problem > is really bugging me. The split panel in the designer keeps > collapsing after I compile and run the program. I would > appreciate if you could give me some hint :) Gladly. But as a general rule, you should post questions like this to the newsgroup, rather than via private e-mail. That gives everyone the opportunity to reply, and everyone else the opportunity to read the replies and learn from them. When you create a component it is, in a sense, not a "real" component. The component's constructor has been called (or the component has been deserialized), and you truly have a Java object, but it is not a "real" component. It cannot be seen, nor does it receive events. Later in the process, the component is realized, and it becomes "real". For top-level components, such as a Frame, Dialog, or Window, this occurs when the component is shown using the setVisible() or show() method. Other components are realized when they are visible, and are added to another component that has been realized, or when the top-level component of the hierarchy to which it belongs is realized. So if you add a component to a Frame, but the frame has not yet been shown, neither the Frame nor your component are realized. Then, when you show the Frame, it and all of its children are realized. But if you add a component to a showing Frame, it will be realized at that time. Many things happen when the components are realized, but the part that concerns us now is that it runs the component's doLayout() method, which normally runs the layoutContainer() method of the components' layout manager. The job of the layout manager is to determine and set the size and position of the component's children. Each layout manager lays out a container in its own unique way, but it usually follow the same general approach. It asks the children of the container for their preferred, minimum, and/or maximum sizes. It then looks at the size of the container and based on its own rules, and sets the size and position for each child component. The layout manager for a JSplitPane sets the sizes and positions of its children based on their preferred and minimum sizes as well. This includes the divider, so its initial position is determined by these sizes, not by a call to setDividerLocation(). After the component is realized, you can use setDividerLocation() to adjust the location of the divider, and thus the size of the two other components in the JSplitterPane. -- John P. McGrath <JPMcGrath@fast.net> <jpm@nscs.fast.net>
Technical Details
Message-ID:
<MPG.1327eda6168210329897d3@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<38BA53F1.1799F1B6@es.sigma.se> <89k508$m856@bornews.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,797b2cd8aaf16ca9 X-Google-Attributes: gid111d45,public From: John P. McGrath <JPMcGrath@fast.net> Subject: Re: JSplitPane does not remember the divider Date: 2000/03/02 Message-ID: <MPG.1327eda6168210329897d3@forums.borland.com> X-Deja-AN: 592136501 References: <38BA53F1.1799F1B6@es.sigma.se> <89k508$m856@bornews.borland.com> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.swing