Hi,
I’ve written my own JavaBean wrapper to the JSlider and have got Servoy to talk to it and adjust it, eg. when a button is pressed the slider position updates.
I’ve gone through the scheduler example as best I can and come up with the code below…It compiles and runs inside Servoy, but it just doesn’t run the method…
I also get the following error when I move the slider bar:
Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException
at ServoyJSlider.stateChanged(ServoyJSlider.java:152)
at javax.swing.JSlider.fireStateChanged(JSlider.java:338)
at javax.swing.JSlider$ModelListener.stateChanged(JSlider.java:266)
at javax.swing.DefaultBoundedRangeModel.fireStateChanged(DefaultBoundedRangeModel.java:348)
at javax.swing.DefaultBoundedRangeModel.setRangeProperties(DefaultBoundedRangeModel.java:285)
at javax.swing.DefaultBoundedRangeModel.setValueIsAdjusting(DefaultBoundedRangeModel.java:214)
at javax.swing.JSlider.setValueIsAdjusting(JSlider.java:510)
at javax.swing.plaf.basic.BasicSliderUI$TrackListener.mouseReleased(BasicSliderUI.java:1361)
at javax.swing.plaf.synth.SynthSliderUI$SynthTrackListener.mouseReleased(SynthSliderUI.java:670)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Please can anyone see why its not working?
Thanks,
Nick
import java.awt.;
import java.awt.event.;
import javax.swing.;
import javax.swing.event.;
import java.io.Serializable;
import java.beans.PropertyChangeEvent;
import java.util.Properties;
import com.servoy.j2db.scripting.IScriptObject;
import com.servoy.j2db.plugins.IClientPlugin;
import com.servoy.j2db.plugins.IClientPluginAccess; // use javac -classpath = …/location of j2db.jar/
import com.servoy.j2db.plugins.PluginException;
import com.servoy.j2db.preference.PreferencePanel;
public class ServoyJSlider extends JPanel implements
IClientPlugin,
ChangeListener,
Serializable {
protected int Minimum = 1;
protected int Maximum = 20;
protected int Value = 10;
JSlider Slider;
JLabel sliderLabel;
private IClientPluginAccess access;
public IScriptObject getScriptObject()
{
return null;
}
public void initialize(IClientPluginAccess access) throws PluginException
{
this.access = access;
}
public ServoyJSlider()
{
setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
//Create the label.
sliderLabel = new JLabel(“Unmoved”, JLabel.CENTER);
sliderLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
//Create the slider.
// JSlider Slider = new JSlider(JSlider.HORIZONTAL,
// Minimum, Maximum, 1);
Slider = new JSlider(JSlider.HORIZONTAL, Minimum, Maximum, Value);
Slider.addChangeListener(this);
// Slider.setMajorTickSpacing(10);
// Slider.setMinorTickSpacing(1);
// Slider.setPaintTicks(true);
// Slider.setPaintLabels(true);
Slider.setBorder( BorderFactory.createEmptyBorder(0,0,10,0) );
// add stuff to the pannel
add(Slider);
add(sliderLabel);
setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
}
// Minimum Slider range
public void setMinimum(int newValue)
{
Minimum = newValue;
Slider.setMinimum(Minimum);
}
public int getMinimum()
{
return Minimum;
}
// Maximum slider range
public void setMaximum(int newValue)
{
Maximum = newValue;
Slider.setMaximum(Maximum);
}
public int getMaximum()
{
return Maximum;
}
// value - this is the slider position
public void setValue(int newValue)
{
Value = newValue;
Slider.setValue(Value);
}
public int getValue()
{
Value = Slider.getValue();
return Value;
}
/* listen for state change */
public void stateChanged(ChangeEvent e) {
JSlider source = (JSlider)e.getSource();
if (!source.getValueIsAdjusting()) {
// Slider has been moved
if ( Slider.getValue() != Value ) {
Value = Slider.getValue();
sliderLabel.setText(“Slider used, v=”+Value);
access.executeMethod(“stock_NAV_browse”, “update_all”, new Object[0]);
}
// Something else moved the slider
else {
sliderLabel.setText(“you pressed a button??”);
}
}
}
// orientation
// MajorTickSpacing
//MinorTickSpacing
// Override a load of methods we don’t want…
public Properties getProperties()
{
return null;
}
public void load() throws PluginException
{
}
public void unload() throws PluginException
{
}
public Icon getImage()
{
return null;
}
public PreferencePanel getPreferencePanels()
{
return null;
}
public void propertyChange(PropertyChangeEvent evt)
{
}
}