Archive for the tag 'NumericStepper'

Create a AsWing’s NumericStepper

November 5th, 2008

Although we have JAdjuster component for AsWing, steroids but sometimes people ask us for NumericStepper, viagra here most time, we tell them just use JAdjuster, we know it’s different, but most time they are replacable.

Well, if you do want a NumericStepper component, it’s easy to create by your self, just combine with JTextField+2Button, with a BoundedRangeModel, a basic MVC NumericStepper component born.

Here’s a example implementation, see the demo screenshot below:
NumericStepper

The test App source code:

package{

import flash.display.Sprite;
import flash.events.Event;

import org.aswing.*;

public class NumericStepperTest extends Sprite{

private var infoText:JTextArea;
private var ns:NumericStepper;

public function NumericStepperTest(){
super();
AsWingManager.initAsStandard(this);
var frame:JFrame = new JFrame(null, "NumericStepperTest");
var topPane:JPanel = new JPanel();
ns = new NumericStepper();
var button:JButton = new JButton("Reset");
topPane.appendAll(button, ns);

infoText = new JTextArea();
frame.getContentPane().append(topPane, BorderLayout.NORTH);
frame.getContentPane().append(
new JScrollPane(infoText), BorderLayout.CENTER);
frame.setSizeWH(300, 300);
frame.show();

ns.addStateListener(__nsStateChanged);
button.addActionListener(__resetValue);
}

private function __resetValue(e:Event):void{
ns.getModel().setValue(50);
}

private function __nsStateChanged(e:Event):void{
infoText.appendByReplace("value : " + ns.getModel().getValue()+"
");
infoText.scrollToBottomLeft();
}
}
}

Well, for copyright reason, i can’t post all of the component codes, maybe after the book published, there will be a downloadable version.

But trust me, if you want, you can implement it easily by yourself, a Container with a BorderLayout, left is a JTextField(lost border and background), right is a Box contains two JButton with Arrow Icons, and with a BoundedRangeModel to hold the data(you can take JAdjuster as example), finally create a Border to your NumericStepper, it is!

  • A3 , Tutorials
  • Comments Off on Create a AsWing’s NumericStepper