Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Tom Newsgroups: comp.lang.java.gui Subject: Re: adding border to JSlider using Nimbus Date: Thu, 8 Sep 2011 22:57:42 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 38 Message-ID: References: NNTP-Posting-Host: Vd3zjYYo2heJAT9ZVcrkiA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Pan/0.133 (House of Butterflies) X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.gui:4681 On Thu, 08 Sep 2011 11:57:31 -0700, Fred wrote: > I create a vertical JSlider with ticks and labels painted. Its width is > x pixels (x depends on the font, etc.) > > I then add a border using: > mySlider.setBorder( BorderFactory.createLineBorder( Color.black, > 10 ) ); > > With Metal L&F, the internal part ofstays the same width, with a > 10-pixel wide border around it; the component's width is now (x+20) > pixels. This is what I would expect - the component wants to be x pixels > wide (to display the slider and the scales) plus 10 pixelsl on each side > for the border. > > Using Nimbus, however, the component stays the same width, with the > border inside it, clipping 10 pixels off each edge. > > How can I add the border correctly using Nimbus? > > Here's the code: > -- snip -- A L&F may use use borders as part of what it does to paint the component. This is not unique to Nimbus - I think you get some interesting effects putting borders directly on to text fields in Windows... Two things to try: See if the component already has a border with JComponent.getBorder(). If it does, replace it with a CompoundBorder putting the existing one as the inside and yours as the outside. Or Put the slider inside a JPanel as the only component and put your border on that.