Greetings,
Ive came across problems while doing a tutorial work piece.
i've to design a toobar ( yup a JToolBar ) with 5 buttons inside it, that will do certain functions for a JSlider.( set them at certain values )
Its simple enough to go and write 5 buttons into my code, but thats not wot ive to do.
The idea is that you will
develop one button that is customisable at design time to have one of 5 different
appearances. Developing 5 separate buttons is NOT an acceptable solution.
Is this even possible? ( pls note the 5 different appearances are Symbals )
Problem: Placing 5 buttons inside a JToolBar, and positing it under my created JSlider
// bob smith
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Testing extends JFrame
{
int min = 40;
int max = 180;
int value = min;
JSlider slider = new JSlider(min,max,value);
MyUI ui = new MyUI(slider);
int tw,sw,startGap;
public Testing(){
setSize(250,100);
setLocation(400,200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
slider.setUI(ui);
slider.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent me)
{
slider.setValue(min+(max-min)*(me.getX()-startGap)/tw);
}
});
slider.setMajorTickSpacing(20);
slider.setMinorTickSpacing(10);
slider.setPaintTicks(true);
slider.setPaintLabels(true);
getContentPane().add(slider);
setVisible(true);
tw = ui.getTrackWidth();
sw = slider.getWidth();
startGap = (sw-tw)/2;
}
public static void main(String args[]){new Testing();}
}
class MyUI extends javax.swing.plaf.basic.BasicSliderUI
{
public MyUI(JSlider js)
{
super(js);
}
public int getTrackWidth()
{
return (int)((Rectangle)trackRect).getWidth();
}
}
Any help or guidance AT all, would be amazing :)
Thanks!