• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Jslider - Button

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am tryng to customise the Jslider.
How to get the slider button from Jslider.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Michael.

Its working perfectly.
 
You know it is dark times when the trees riot. I think this tiny ad is their leader:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic