Subpanel problem

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2005
Posts: 2
Reputation: mgdz is an unknown quantity at this point 
Solved Threads: 0
mgdz mgdz is offline Offline
Newbie Poster

Subpanel problem

 
0
  #1
Jul 18th, 2005
I am trying to create a class which could be a subpanel. It extends JPanel and implements AdjustmentListener. The JPanel is used here as a container and it keeps JLabels and JScrorrButtons layouted with gridBagLayout.

This class instantiated in application doesn't work, none of components (labels and scroolButtons) don't even show up.

  1.  
  2. public class parameteManager extends JPanel implements AdjustmentListener{
  3.  
  4. public JPanel pane;
  5. public JScrollBar scrbF;
  6. public JScrollBar scrbA ;
  7. public JScrollBar scrbC ;
  8. public JTextField wartF ;
  9. public JTextField wartA ;
  10. public JTextField wartC ;
  11.  
  12.  
  13.  
  14.  
  15. public parameteManager(int a,int b,int c,int d,int e,int f,int g,int h,int i, int j,int k,int l,java.lang.String z) {
  16. scrbF = new JScrollBar(JScrollBar.HORIZONTAL, a, b, c, d);
  17. scrbA = new JScrollBar(JScrollBar.HORIZONTAL, e, f, g, h);
  18. scrbC = new JScrollBar(JScrollBar.HORIZONTAL, i, j, k, l);
  19. wartF = new JTextField ();
  20. wartA = new JTextField ();
  21. wartC = new JTextField ();
  22. pane=new JPanel();
  23. pane.setSize(500,300);
  24.  
  25. GridBagLayout gridbg = new GridBagLayout();
  26. GridBagConstraints constr = new GridBagConstraints();
  27. constr.insets=new Insets(2,2,2,2);
  28. pane.setLayout(gridbg);
  29.  
  30.  
  31. //adding components to the panel , to set all constraints needed for gridBagLayout buildConstraints function is used.
  32.  
  33. buildConstraints(constr, 0, 0, 1, 1, 30, 2,3,0);
  34. constr.fill = GridBagConstraints.NONE;
  35. constr.anchor = GridBagConstraints.EAST;
  36. JLabel label1 = new JLabel("Faza:", JLabel.LEFT);
  37. gridbg.setConstraints(label1, constr);
  38. pane.add(label1);
  39. //amplituda
  40.  
  41. //pokaz wart czestotl
  42. wartC.setEditable(false);
  43. wartC.setText(""+scrbC.getValue());
  44. buildConstraints (constr,1,2,1,1,0,0,3,0);
  45. constr.fill= GridBagConstraints.HORIZONTAL;
  46. constr.anchor = GridBagConstraints.CENTER;
  47. gridbg.setConstraints(wartC, constr);
  48. pane.add(wartC);
  49.  
  50. pane.setBorder(BorderFactory.createTitledBorder("Manager O"+z));
  51.  
  52. try {
  53. jbInit();
  54. } catch (Exception ex) {
  55. ex.printStackTrace();
  56. }
  57. }
  58.  
  59.  
  60.  
  61. public void adjustmentValueChanged(AdjustmentEvent e) {
  62. Object source = e.getSource(); //scrbF scrbA scrbC - zrodlo zdarzenia
  63. if (source == scrbF) {
  64. int value=scrbF.getValue();
  65. wartF.setText(""+value);
  66. }
  67. if (source == scrbA){
  68. int value=scrbA.getValue();
  69. wartA.setText(""+value/10);
  70. }
  71. if (source == scrbC){
  72. int value=scrbC.getValue();
  73. wartC.setText(""+value);
  74. }
  75. }
  76.  
  77.  
  78. private void buildConstraints(GridBagConstraints gbc, int gx, int gy,
  79. int gw, int gh, int wx, int wy,int px, int py) {
  80. //gbc.insets = new Insets(5,5,3,5);
  81. gbc.gridx = gx;
  82. gbc.gridy = gy;
  83. gbc.gridwidth = gw;
  84. gbc.gridheight = gh;
  85. gbc.weightx = wx;
  86. gbc.weighty = wy;
  87. gbc.ipadx=px;
  88. gbc.ipady=py;
  89. }
  90.  
  91. private void jbInit() throws Exception {
  92. }
  93.  
  94. }
  95.  
  96.  
  97.  
  98.  
  99. //the applicaion that uses parameteManger class
  100.  
  101. public class Chart extends JFrame implements AdjustmentListener{
  102.  
  103. parameteManager managerx,managery; //subpanels
  104. JPanel contentPane;
  105.  
  106. public Chart(){
  107. super ("Chart");
  108. contentPane = new JPanel();
  109. contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
  110. //contentPane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
  111.  
  112. managerx= new parameteManager(2,0,0,6,60,0,60,100,2,0,0,100,"X");
  113. managery= new parameteManager(2,0,0,6,60,0,60,100,2,0,0,100,"Y");
  114.  
  115.  
  116. contentPane.add(managerx);
  117. contentPane.add(managery);
  118.  
  119. setContentPane(contentPane);
  120. setTitle("Chart");
  121.  
  122. try {
  123. jbInit();
  124. } catch (Exception ex) {
  125. ex.printStackTrace();
  126. }
  127. }
  128.  
  129.  
  130.  
  131. public static void main(String[] args){
  132. JFrame frame = new Lissajous1();
  133. ExitWindow exit = new ExitWindow();
  134. frame.addWindowListener(exit);
  135. frame.show();
  136. }
  137.  
  138. public void adjustmentValueChanged(AdjustmentEvent e) {
  139. Object source = e.getSource(); //scrbF scrbA scrbC - zrodlo zdarzenia
  140. if (source == managerx.scrbF) {
  141. int value=managerx.scrbF.getValue();
  142.  
  143. }
  144. if (source == managerx.scrbA){
  145. int value=managerx.scrbA.getValue();
  146.  
  147. }
  148. if (source == managerx.scrbC){
  149. int value=managerx.scrbC.getValue();
  150.  
  151. }
  152. }
  153.  
  154. private void jbInit() throws Exception {
  155. this.setResizable(false);
  156. }
  157.  
  158.  
  159. }

what could be wrong with it... maybe it is the case of event handling?? any idaes?
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 802
Reputation: Phaelax is on a distinguished road 
Solved Threads: 40
Phaelax Phaelax is offline Offline
Practically a Posting Shark

Re: Subpanel problem

 
0
  #2
Jul 18th, 2005
That's because "parameteManager" doesn't contain anything. "parameteManager" is a panel, that's what you're adding inside of "Chart". The panel is technically still blank, you must add your scrollbars and other panels to it first. Simply stated, add
  1. this.add(pane);
at the end of the "parameteManager" contructor.

Also, the size of the JFrame isn't being set properly, and with you calling jbInit() inside of Chart, you can't resize the frame and won't see the content anyway.
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


Views: 2093 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC