| | |
Gui Help ( toolbar )
![]() |
•
•
Join Date: Mar 2006
Posts: 3
Reputation:
Solved Threads: 0
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.
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
Any help or guidance AT all, would be amazing
Thanks!
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.
Problem: Placing 5 buttons inside a JToolBar, and positing it under my created JSlider
Java Syntax (Toggle Plain Text)
// 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!
Last edited by PieMan2004; Nov 10th, 2006 at 3:35 pm.
•
•
Join Date: Mar 2006
Posts: 3
Reputation:
Solved Threads: 0
I looked through some of my old codes, and found something i thought would be useful.
Upon editing it i came up with this
So far my attempts to implement it into my code have failed.
Could anyone give me pointers? ( in my first code im using the light layout functions ( UI ) im afraid thats all ive been taught in so far
Upon editing it i came up with this
Java Syntax (Toggle Plain Text)
import java.awt.BorderLayout; import java.awt.Container; import javax.swing.JFrame; import javax.swing.JToggleButton; import javax.swing.JToolBar; public class ToolBarTest { public static void main(String args[]) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); JToolBar bar; bar = new JToolBar(); JToggleButton jb; for (int i = 0; i < 5; i++) { jb = new JToggleButton("" + i); bar.add(jb); } contentPane.add(bar, BorderLayout.SOUTH); frame.setSize(300, 300); frame.show(); } }
So far my attempts to implement it into my code have failed.
Could anyone give me pointers? ( in my first code im using the light layout functions ( UI ) im afraid thats all ive been taught in so far
That isn't what you're supposed to do.
Think subclassing the button to create one that has a custom constructor taking an argument telling it what incrememt or decrement it should apply to the slider and another argument passing a reference to the slider.
Think subclassing the button to create one that has a custom constructor taking an argument telling it what incrememt or decrement it should apply to the slider and another argument passing a reference to the slider.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
![]() |
Similar Threads
- 2 Small GUI Problems ? (Java)
- yupsearch.com toolbar - how to remove? (Viruses, Spyware and other Nasties)
- Lost browser links,internet options etc...toolbar (Web Browsers)
- GUI Builder For Swing (Java)
- GUI development in LINUX (Window and Desktop Managers)
- Help with gui loop. (C)
Other Threads in the Java Forum
- Previous Thread: custom cursor
- Next Thread: Java - Creating a MultiTable from User-Input Numbers
| Thread Tools | Search this Thread |
3d 6 @param affinetransform android api applet application arc array arrays automation binary bluetooth bold byte c++ chat class client code color compare component coordinates database detection doctype eclipse educational error file fractal froglogic game givemetehcodez graphics gridlayout gui guitesting helpwithhomework html ide ideas image ingres input integer internet intersect j2me java java.xls javaexcel javaprojects jni jpanel jtextarea julia keytool keyword linux list map method methods mobile netbeans newbie nextline object os pong problem producer program programming project projectideas read recursion recursive replaysolutions rim scanner sell server set size sms sort sql string swing terminal threads tree web websites windows






