aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes size Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "size" Watch "size" New topic
Author

size

rob armstrong
Ranch Hand

Joined: Jul 25, 2005
Posts: 77
Trying to make a extended JSlider (smaller slider) that is sized quite smaller than the factory one. Which method do i edit to do this? I tried setSize and setPreferredSize(dimension) but i have not had any luck at making it smaller.
Basically i want it to be really small and isFilled(false) and an invisible background rail just the sliding icon itself is all i need>
THanks in advance!!
roba
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
here's your 'knob only'. Don't know your definition of small, perhaps if you
advise the range of the slider and size relative to what I post, it might give
us a better idea.

rob armstrong
Ranch Hand

Joined: Jul 25, 2005
Posts: 77
class MyUI extends javax.swing.plaf.metal.MetalSliderUI
{
public void paintThumb(Graphics g)
{
super.paintThumb(g);
Graphics2D g2=(Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g2.setPaint(Color.BLACK);
g2.fill(tHandle);
g2.draw(tHandle);
}









public void paintTrack(Graphics g)
{
} // puts nothing in for the track
}

ok it worked but i want to make a rectangle object to be my 'THUMB' Is this along the proper way to do it?

roba
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
change
class MyUI extends javax.swing.plaf.metal.MetalSliderUI
to
class MyUI extends javax.swing.plaf.basic.BasicSliderUI

and you will get a rectangle knob

[EDIT]
you'll need a couple of other changes for the above to work
1) constructor for MyUI()
public MyUI(JSlider js){super(js);}

2) in SliderKnobOnly()
setUI(new MyUI());
changes to
setUI(new MyUI(this));
[ August 10, 2006: Message edited by: Michael Dunn ]
rob armstrong
Ranch Hand

Joined: Jul 25, 2005
Posts: 77
Wow I am very impressed with your proptness and knowledge of GUI! What is the best way for me to understand the GUI heiarchry the way you do? I was close to the same lines today and I found that the basic.BasicSliderUI was what i wanted but than it said it didn't have a default constructor and i was cooked at that point! So i went back and looked at other ways to do it....time passes...

Ok got the rectangle knob working but it does not display the Graphics g rectangle I made. My graphic is in the paintThumb(Graphics g) {} method but it is only displayed at 0,0 and not changed when i move the slider. It is stationary.
Thanks again
roba
rob armstrong
Ranch Hand

Joined: Jul 25, 2005
Posts: 77
This may help.....


class MyUI extends javax.swing.plaf.basic.BasicSliderUI
{
public MyUI(JSlider js)
{
super(js);
}
public void paintThumb(Graphics g)
{
//super.paintThumb(g);
Graphics2D g2=(Graphics2D)g;
Shape tHandle=new RoundRectangle2D.Double(20,0,10,5,3,3);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g2.setPaint(Color.BLACK);
g2.fill(tHandle);
//g2.draw(tHandle);
}

public void paintTrack(Graphics g)
{
} // puts nothing in for the track
}


Thanks
roba
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
are you trying to make a smaller knob?

if so, try this

rob armstrong
Ranch Hand

Joined: Jul 25, 2005
Posts: 77
Thanks that worked properly! I origionally wanted to make a RoundRectangle2D object instead of the thumb or rectangle but now rethinking it would problably not display anyway cause it will be so small. So what we have here is perfect. Please explain the method i would override if i was to add my own Round Rectangle or ellipse just for educational purposes. Thanks roba
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
I'ts not something I've tried, but it looks like you would create your own Icon,
then, perhaps the easiest way is to change it in the UIManager (for all sliders)
UIManager.put("Slider.horizontalThumbIcon", ........ );
 
 
subject: size