943,999 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2027
  • Java RSS
Nov 10th, 2006
0

Gui Help ( toolbar )

Expand Post »
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.

Quote ...
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

Java Syntax (Toggle Plain Text)
  1. // bob smith
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6.  
  7.  
  8. class Testing extends JFrame
  9. {
  10. int min = 40;
  11. int max = 180;
  12. int value = min;
  13.  
  14. JSlider slider = new JSlider(min,max,value);
  15. MyUI ui = new MyUI(slider);
  16. int tw,sw,startGap;
  17.  
  18. public Testing(){
  19.  
  20. setSize(250,100);
  21. setLocation(400,200);
  22. setDefaultCloseOperation(EXIT_ON_CLOSE);
  23. slider.setUI(ui);
  24. slider.addMouseListener(new MouseAdapter(){
  25. public void mousePressed(MouseEvent me)
  26. {
  27. slider.setValue(min+(max-min)*(me.getX()-startGap)/tw);
  28. }
  29. });
  30. slider.setMajorTickSpacing(20);
  31. slider.setMinorTickSpacing(10);
  32. slider.setPaintTicks(true);
  33. slider.setPaintLabels(true);
  34. getContentPane().add(slider);
  35. setVisible(true);
  36. tw = ui.getTrackWidth();
  37. sw = slider.getWidth();
  38. startGap = (sw-tw)/2;
  39. }
  40. public static void main(String args[]){new Testing();}
  41. }
  42. class MyUI extends javax.swing.plaf.basic.BasicSliderUI
  43. {
  44. public MyUI(JSlider js)
  45. {
  46. super(js);
  47. }
  48. public int getTrackWidth()
  49. {
  50. return (int)((Rectangle)trackRect).getWidth();
  51. }
  52.  
  53. }

Any help or guidance AT all, would be amazing

Thanks!
Last edited by PieMan2004; Nov 10th, 2006 at 3:35 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
PieMan2004 is offline Offline
3 posts
since Mar 2006
Nov 10th, 2006
0

Re: Gui Help ( toolbar )

Sure it's possible. You just have to correctly read your assignment.

Putting a JToolBar anywhere except on the edges of a window is however NOT possible.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Nov 10th, 2006
0

Re: Gui Help ( toolbar )

I looked through some of my old codes, and found something i thought would be useful.

Upon editing it i came up with this

Java Syntax (Toggle Plain Text)
  1. import java.awt.BorderLayout;
  2. import java.awt.Container;
  3. import javax.swing.JFrame;
  4. import javax.swing.JToggleButton;
  5. import javax.swing.JToolBar;
  6.  
  7. public class ToolBarTest {
  8. public static void main(String args[]) {
  9. JFrame frame = new JFrame();
  10. Container contentPane = frame.getContentPane();
  11. JToolBar bar;
  12. bar = new JToolBar();
  13. JToggleButton jb;
  14. for (int i = 0; i < 5; i++) {
  15. jb = new JToggleButton("" + i);
  16. bar.add(jb);
  17.  
  18. }
  19. contentPane.add(bar, BorderLayout.SOUTH);
  20. frame.setSize(300, 300);
  21. frame.show();
  22. }
  23. }


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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
PieMan2004 is offline Offline
3 posts
since Mar 2006
Nov 11th, 2006
0

Re: Gui Help ( toolbar )

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: custom cursor
Next Thread in Java Forum Timeline: Java - Creating a MultiTable from User-Input Numbers





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC