JGoodies Binding: Bounded Range Adapter Example
/*
Code revised from Desktop Java Live:
http://www.sourcebeat.com/downloads/
*/
import java.text.DecimalFormat;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import com.jgoodies.binding.adapter.BoundedRangeAdapter;
import com.jgoodies.binding.beans.PropertyConnector;
import com.jgoodies.binding.value.ConverterFactory;
import com.jgoodies.binding.value.ValueHolder;
import com.jgoodies.binding.value.ValueModel;
import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.FormLayout;
public class BoundedRangeAdapterExample extends JPanel {
public BoundedRangeAdapterExample() {
DefaultFormBuilder defaultFormBuilder = new DefaultFormBuilder(new FormLayout("p, 2dlu, p"));
defaultFormBuilder.setDefaultDialogBorder();
ValueModel percentageModel = new ValueHolder();
percentageModel.setValue(new Integer("1"));
JSlider slider = new JSlider();
BoundedRangeAdapter boundedRangeAdapter = new BoundedRangeAdapter(percentageModel, 0, 0, 100);
slider.setModel(boundedRangeAdapter);
defaultFormBuilder.append("Slider:", slider);
JLabel sliderLabel = new JLabel();
PropertyConnector propertyConnector2 = new PropertyConnector(ConverterFactory.createStringConverter(percentageModel, new DecimalFormat("#")), "value", sliderLabel, "text");
propertyConnector2.updateProperty2();
defaultFormBuilder.append("Label:", sliderLabel);
add(defaultFormBuilder.getPanel());
}
public static void main(String[] a){
JFrame f = new JFrame("Bounded Range Adapter Example");
f.setDefaultCloseOperation(2);
f.add(new BoundedRangeAdapterExample());
f.pack();
f.setVisible(true);
}
}
jgoodiesDataBinding.zip( 254 k)Related examples in the same category