Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: What do you think of my CropImage class Date: Thu, 21 Jul 2016 12:56:36 -0400 Organization: A noiseless patient Spider Lines: 39 Message-ID: References: <87twfk93vu.fsf@Equus.decebal.nl> <8737n36ucx.fsf@Equus.decebal.nl> <87lh0v560n.fsf@Equus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 21 Jul 2016 16:56:48 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="2d081e2f7155c28005d4472f67c2f43d"; logging-data="23013"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/nrxQhA30/WBtAUPpUX02+" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 In-Reply-To: <87lh0v560n.fsf@Equus.decebal.nl> Cancel-Lock: sha1:g0GMePNheRbhvOKmXd9C8zRN3aA= Xref: csiph.com comp.lang.java.programmer:35058 On 7/21/2016 12:07 PM, Cecil Westerhof wrote: > On Thursday 21 Jul 2016 15:35 CEST, Eric Sosman wrote: > [...] >> - It constructs a pair of JLabels on whatever thread loads and >> initializes the class. (And the JLabels are static, which is so >> very odd as to be downright weird. Have you thought this through?) > [...] > But about the things being static. There is always exactly one, so > what is the problem with things being static? If it is a real no-no I > could change it. There's a containment hierarchy of displayed things: You start with a top-level container (JFrame, JDialog, ...) that contains lower- level sub-components (JPanels, JTrees, ...) that in turn contain still lower-level components (JButtons, more JPanels, ...). That is, components are nested in a tree. It follows that a given component can appear at only one spot in the tree: It is contained in exactly one container, or is a top-level component that is not contained at all. This way, the contained component can have (for example) *a* position relative to its container, instead of a whole Map of "I'm *here* in this container, *there* in that container, ..." (Swing might have required a container to maintain a list of contained objects *and* their positions and sizes, but it didn't; positions and sizes and so on are attributes of the contained objects.) To maintain tree-ness, when you add a component to a container Swing automatically removes it from any container it already belonged to. So, if you have a static JLabel and you add it to one CropImage instance, it cannot simultaneously appear in another CropImage: It can be in one or the other (or neither), but not in both. Since you're probably anticipating only one CropImage instance this may not seem a big deal, may not even *be* a big deal (were it not for the EDT issue), but it's certainly weird. -- esosman@comcast-dot-net.invalid "Don't be afraid of work. Make work afraid of you." -- TLM