I have a bean that creates a JSlider, a textfield, and a label. I want to use the the bean to put these things on a window. I have panel that is a content pane to hold the colored circle. I want another panel to hold the slider. I am able to put the circle on the content pane without a problem but the sliderpanel doesn't seem to appear. Do I need to do something different to the driver program or the bean?
Multiple problems... you can't add your XSliderBeans to the inside of your panel because they extend from JFrame... instead they should just extend JPanel or JComponent. Another problem is that you are creating new XSliderBeans every time the DrawPanel is painted. You should be creating the XSliderBeans once and just attach listeners to know when to set values in the DrawPanel. You should probably also add the XSliderBeans to the panel that holds the DrawPanel and not the DrawPanel itself, and have listeners at this level that listen to changes of the sliders and call methods on the DrawPanel to set the color.
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I am trying to make the changes suggested but I'm having a problem with blue.addAdjustmentListener(this); I get a complie error: The method addAdjustmentListener(DrawFrame) is undefined for the type BlueSliderBean. I have added
If you're creating the sliders inside the DrawFrame class, then you just need to pass a reference to the DrawPanel to that method. It would show up somewhere after this code:
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Whoops... I went back and looked and the slider bean doesn't have that method defined for it. You'll need to add the addAdjustmentListener() and removeAdjustmentListener() methods to the bean yourself. All they'll do is pass their parameter on to the JSlider inside the slider bean.
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
The problem is that in the constructor all the components are created and added to panels, but nothing is added to the BlueSliderBean itself. (this.add(...)). You could fix it either by adding "panel2" to "this", or by doing away with "panel2" and adding everything to "this" instead.
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I have taken out panel2 and add: this.add(sliderPanel, BorderLayout.CENTER); this.add(textField); this.add(integerlbl, BorderLayout.SOUTH); but still nothing appears on the window.