Results 1 to 9 of 9
Like Tree2Likes
  • 1 Post By jim829
  • 1 Post By heatblazer

Thread: JSlider change table/ruler position

  1. #1
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Question JSlider change table/ruler position

    Hello,
    I need to change a JSlider ticks/ rulers as follows:
    The original is:
    [----------------O-----------------]
    [1----2----3----4----5----6----7]

    and what I need is

    [1----2----3----4----5----6----7]
    [----------------O-----------------]

    the pointer to be below the hashtable. Is there a way to do it ?

  2. #2
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Default Re: JSlider change table/ruler position

    Bump that. Please I need some help about this.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: JSlider change table/ruler position

    Not that I am aware. One possibility is to create your own version of a slider. Just turn off the tick marks for the current slider and then add your own tick marks to a label and position it above the slider. You can put both of these in a small JPanel which would make positioning easier. This means overriding pantComponent in JLabel to add the ticks via the graphics context. I haven't tried it before but it should work. If not, try a JPanel instead.

    Or wait and see if others have a better suggestion.

    Regards,
    Jim
    Last edited by jim829; 02-19-2014 at 04:03 AM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Default Re: JSlider change table/ruler position

    Thanks for the reply. I was thinking if it`s possible to set the entire slider invisible but the tick panel, so I can add another Slider on top of the original and it will do nothing but his bottom ticks will be top of mine. But is it possible to make the slider completely invisible.

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: JSlider change table/ruler position

    Quote Originally Posted by heatblazer View Post
    But is it possible to make the slider completely invisible.
    I assume you mean, as you said, everything except the tick marks. Not that I am aware. I believe the code to draw the slider is part of the SliderUI which manages the Look and Feel. So there is nothing documented that I have found that you could override or set to do this.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  6. #6
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Default Re: JSlider change table/ruler position

    I was able to find a way. Here is the solution
    Java Code:
    private static class MySliderUI extends BasicSliderUI {
    		private static float[] fracs = {0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0f };
    
    		private LinearGradientPaint paint; 
    		public MySliderUI(JSlider b) {
    			super(b);
    			
    			// TODO Auto-generated constructor stub
    		}
    	
    		@Override
    		public void paintTrack(Graphics g) {
    		/*	Graphics2D g2d = (Graphics2D) g;
    			Rectangle t = trackRect;
    			Point2D start = new Point2D.Float(t.x, t.y);
    			Point2D end = new Point2D.Float(t.width, t.height);
    			Color[] colors = {Color.magenta, Color.blue, Color.cyan,
    					Color.green, Color.yellow, Color.red };
    			paint = new LinearGradientPaint(start, end, fracs, colors);
    			g2d.setPaint(paint);
    			g2d.fillRect(t.x, t.y, t.width, t.height); */
    		}
    		
    		@Override
    		public void paintThumb(Graphics g) {
    			/*
    			Graphics2D g2d = (Graphics2D) g;
    			g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    					RenderingHints.VALUE_ANTIALIAS_ON);
    			Rectangle t = thumbRect;
    			Rectangle t2 = trackRect;
    			g2d.setColor(Color.black);
    			int tw2 = t.width / 2;
    			int th2 = t.height + 20;
    		//	g2d.drawLine(t.x, t.y, t.x+t.width-1, t.y);
    		//	g2d.drawLine(t.x, t.y, t.x+(tw2*2), t.y+t.height+(t.height/2));
    		//	g2d.drawLine(t.x+t.width-1, t.y, t.x+tw2*2, t.y+t.height+(t.height/2));
    		//	g2d.fillRect(t.x, t.y, t.width*2, t.height*2);
    			
    			g2d.fillOval(t.x, t.y-20 , t.width*2, t.height*2);
    			*/
    		} 
    		
    	} // END INNER CUSTOMIZING CLASS
    That is the auxilarySlider. They are both added to a JPanel one on top of other. The aux slider is just not painting. But in the original program you set the pain ticks and DO NOT override the method in BasicSliderUI.

  7. #7
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Default Re: JSlider change table/ruler position

    I was able to find a way. Here is the solution
    Java Code:
    private static class MySliderUI extends BasicSliderUI {
    		private static float[] fracs = {0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0f };
    
    		private LinearGradientPaint paint; 
    		public MySliderUI(JSlider b) {
    			super(b);
    			
    			// TODO Auto-generated constructor stub
    		}
    	
    		@Override
    		public void paintTrack(Graphics g) {
    		/*	Graphics2D g2d = (Graphics2D) g;
    			Rectangle t = trackRect;
    			Point2D start = new Point2D.Float(t.x, t.y);
    			Point2D end = new Point2D.Float(t.width, t.height);
    			Color[] colors = {Color.magenta, Color.blue, Color.cyan,
    					Color.green, Color.yellow, Color.red };
    			paint = new LinearGradientPaint(start, end, fracs, colors);
    			g2d.setPaint(paint);
    			g2d.fillRect(t.x, t.y, t.width, t.height); */
    		}
    		
    		@Override
    		public void paintThumb(Graphics g) {
    			/*
    			Graphics2D g2d = (Graphics2D) g;
    			g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    					RenderingHints.VALUE_ANTIALIAS_ON);
    			Rectangle t = thumbRect;
    			Rectangle t2 = trackRect;
    			g2d.setColor(Color.black);
    			int tw2 = t.width / 2;
    			int th2 = t.height + 20;
    		//	g2d.drawLine(t.x, t.y, t.x+t.width-1, t.y);
    		//	g2d.drawLine(t.x, t.y, t.x+(tw2*2), t.y+t.height+(t.height/2));
    		//	g2d.drawLine(t.x+t.width-1, t.y, t.x+tw2*2, t.y+t.height+(t.height/2));
    		//	g2d.fillRect(t.x, t.y, t.width*2, t.height*2);
    			
    			g2d.fillOval(t.x, t.y-20 , t.width*2, t.height*2);
    			*/
    		} 
    		
    	} // END INNER CUSTOMIZING CLASS
    That is the auxilarySlider. They are both added to a JPanel one on top of other. The aux slider is just not painting. But in the original program you set the pain ticks and DO NOT override the method in BasicSliderUI.

  8. #8
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: JSlider change table/ruler position

    Glad you found away around it. Just make certain your implementation is stand alone and not based on any JDK implementation or anything in the source code (assuming you have it). If you depend on something that isn't documented it may very well break in future releases.

    Regards,
    Jim
    heatblazer likes this.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  9. #9
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    137
    Rep Power
    0

    Default Re: JSlider change table/ruler position

    Yes, I keep that in mind. Good that someone else might find my problem and reuse it :)
    DarrylBurke likes this.

Similar Threads

  1. Replies: 1
    Last Post: 01-19-2014, 08:05 PM
  2. Replies: 3
    Last Post: 02-05-2012, 07:10 AM
  3. JSlider change JPanel[][] rows and columns
    By Charlie161 in forum AWT / Swing
    Replies: 3
    Last Post: 02-28-2011, 06:44 PM
  4. Replies: 4
    Last Post: 12-31-2010, 01:15 PM
  5. How to I change the position in arrays
    By LennyKosmos in forum New To Java
    Replies: 3
    Last Post: 09-27-2010, 11:04 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •