Gui Help ( toolbar )

Reply

Join Date: Mar 2006
Posts: 3
Reputation: PieMan2004 is an unknown quantity at this point 
Solved Threads: 0
PieMan2004 PieMan2004 is offline Offline
Newbie Poster

Gui Help ( toolbar )

 
0
  #1
Nov 10th, 2006
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

  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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Gui Help ( toolbar )

 
0
  #2
Nov 10th, 2006
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 3
Reputation: PieMan2004 is an unknown quantity at this point 
Solved Threads: 0
PieMan2004 PieMan2004 is offline Offline
Newbie Poster

Re: Gui Help ( toolbar )

 
0
  #3
Nov 10th, 2006
I looked through some of my old codes, and found something i thought would be useful.

Upon editing it i came up with this

  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
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Gui Help ( toolbar )

 
0
  #4
Nov 11th, 2006
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC