Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Jslider - Button  RSS feed

 
Aabha Varma
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am tryng to customise the Jslider.
How to get the slider button from Jslider.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
look up BasicSliderUI()
override one of the thumb() methods
 
Aabha Varma
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using BasicSliderUI only.
I have over written some of the methods. paintThump()...etc.

But i am getting the image at 0,0 position as well as a slider button.
My intention was to set the image on to the button.


Is there any link which tells more abt how to use this Component UI, Basic slider ui...etc with some example code.

Here is the code.

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JSlider;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.SliderUI;
import javax.swing.plaf.basic.BasicSliderUI;

public class test extends JFrame
{
private JPanel cJPanel1 = new JPanel();
private JSlider cJSlider1 = new JSlider();
private ImageIcon image = new ImageIcon("c:\\image1");

public test()
{
try
{
jbInit();
}
catch(Exception e)
{
e.printStackTrace();
}

}

private void jbInit() throws Exception
{
cJPanel1.add(cJSlider1, null);
cJSlider1.setBackground(cJSlider1.getParent().getBackground());

DefaltSliderUI sliderUI = new DefaltSliderUI(cJSlider1);
cJSlider1.setUI(sliderUI);

this.getContentPane().add(cJPanel1, BorderLayout.CENTER);
}


class DefaltSliderUI extends BasicSliderUI
{
private JSlider cjSlider;
public DefaltSliderUI(JSlider cJSlider1)
{
super(cJSlider1);
this.cjSlider = cJSlider1;

}
public void paintThumb (Graphics g)
{
g.drawImage(image.getImage(),0,0, null); super.paintThumbg);

}
public void scrollDueToClickInTrack()
{
super.scrollDueToClickInTrack(1);
}
public void paintTrack(Graphics g)
{
g.setColor(Color.RED);
}

public void paint(Graphics g,JSlider cjSlider)
{
super.paint(g,cjSlider);
}
}

public static void main(String[] args)
{
test test = new test();
test.setSize(500,100);
test.setVisible(true);
}
}
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this draws an imabe as the thumb, but sliding/repainting kills it

 
Aabha Varma
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Michael.

Its working perfectly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!