X-Received: by 10.224.72.199 with SMTP id n7mr5986407qaj.5.1365431896478; Mon, 08 Apr 2013 07:38:16 -0700 (PDT) X-Received: by 10.49.95.134 with SMTP id dk6mr1647083qeb.10.1365431896455; Mon, 08 Apr 2013 07:38:16 -0700 (PDT) Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!t2no45491359qal.0!news-out.google.com!ef9ni8256qab.0!nntp.google.com!t2no45491354qal.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.gui Date: Mon, 8 Apr 2013 07:38:16 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=130.76.32.216; posting-account=_7xgmwoAAADi7iXKBO-oX5zbCfSzsCV0 NNTP-Posting-Host: 130.76.32.216 References: <7a07006d-a3a8-4e09-b3a3-1cd9ee01328f@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: How to clip child from layout manager From: FredK Injection-Date: Mon, 08 Apr 2013 14:38:16 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 2864 Xref: csiph.com comp.lang.java.gui:5323 On Friday, April 5, 2013 4:28:07 PM UTC-7, markspace wrote: > On 4/5/2013 10:03 AM, FredK wrote: > I have a custom layout manager. > If= the Swing container that uses this manager is too small to layout > the ch= ildren at preferred sizes, I want to clip one or more of them. > > I do not= want to set the child's size smaller than its desired size. > > For exampl= e, suppose the child's desired width is 100. I want to > place it at x=3D25= 0 with width =3D 100, but I want to clip part of it so > that the first 40 = pixels are clipped. The end result will be > that its position is [250,350]= but only the child's [60,100] part > is visible ( occupying the region [29= 0,350] ). > I think this happens automatically. I think the clip region of = the Graphic2D is already set for you when your layout manager is called. Ju= st call setBounds() on each object you want to lay out. They'll be drawn at= that position, even if only partly visible. If not visible it won't be dra= wn at all, the underlying graphics tool is smart like that. No, this is not what I want do do here. Calling setBound() with a size smaller than the preferred size causes the component to try to draw itself in that smaller size, and will clip anything that won't fit. Here's what I want it to do. Suppose the child's preferred size is 200x500. I want it to draw itself at that size, with its UL corner at, say, (200,400), so its LR corner will be at (400,900). But I want to see only that portion of it that is within my rectangle [upperleft=3D(250,350), lowerright=3D(350,500)]. Thus it clips itself around all edges - similar to what you see in the viewport of a ScrollPane