Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #4678

adding border to JSlider using Nimbus

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!news-out.readnews.com!transit3.readnews.com!postnews.google.com!t30g2000prm.googlegroups.com!not-for-mail
From Fred <fred.l.kleinschmidt@boeing.com>
Newsgroups comp.lang.java.gui
Subject adding border to JSlider using Nimbus
Date Thu, 8 Sep 2011 11:57:31 -0700 (PDT)
Organization http://groups.google.com
Lines 63
Message-ID <daabdcd3-7d35-400f-9235-edf9539fef75@t30g2000prm.googlegroups.com> (permalink)
NNTP-Posting-Host 130.76.32.208
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
X-Trace posting.google.com 1315511823 30198 127.0.0.1 (8 Sep 2011 19:57:03 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Thu, 8 Sep 2011 19:57:03 +0000 (UTC)
Complaints-To groups-abuse@google.com
Injection-Info t30g2000prm.googlegroups.com; posting-host=130.76.32.208; posting-account=_7xgmwoAAADi7iXKBO-oX5zbCfSzsCV0
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-Header-Order HACRNKUEL
X-HTTP-UserAgent Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2),gzip(gfe)
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.gui:4678

Show key headers only | View raw


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:

import java.awt.Color;
import java.awt.FlowLayout;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.UIManager;
import javax.swing.border.Border;

public class Slide extends JPanel {
   public Slide() {
      try {
         UIManager.setLookAndFeel(
           "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" );
      } catch ( Exception e ) {
         System.out.println( "No nimbus!" );
      }

      JSlider js = new JSlider();
      js.setPaintTicks( true );
      js.setPaintLabels( true );
      Border b = BorderFactory.createLineBorder( Color.black, 10 );
      js.setBorder( b );
      js.setOrientation( 1 );
      int imin = 0;
      int imax = 200;
      js.setMinimum( imin );
      js.setMaximum( imax );
      js.setMajorTickSpacing( ( imax - imin ) / 5 );

      setLayout( new FlowLayout() );
      add( js );
   }

   public static void main( String[] args ) {
      JFrame f = new JFrame( "Slider" );
      Slide mll = new Slide();
      f.getContentPane().add( mll );
      f.pack();
      f.setVisible( true );
   }
}

Back to comp.lang.java.gui | Previous | NextNext in thread | Find similar


Thread

adding border to JSlider using Nimbus Fred <fred.l.kleinschmidt@boeing.com> - 2011-09-08 11:57 -0700
  Re: adding border to JSlider using Nimbus Tom <tom400f@gmail.com> - 2011-09-08 22:57 +0000
  Re: adding border to JSlider using Nimbus "John B. Matthews" <nospam@nospam.invalid> - 2011-09-08 19:09 -0400
  Re: adding border to JSlider using Nimbus Roedy Green <see_website@mindprod.com.invalid> - 2011-09-16 16:45 -0700
    Re: adding border to JSlider using Nimbus "John B. Matthews" <nospam@nospam.invalid> - 2011-09-16 23:19 -0400

csiph-web