DefaultBoundedRangeModel: setMinimum(int n) : DefaultBoundedRangeModel « javax.swing « Java by API






DefaultBoundedRangeModel: setMinimum(int n)

/*
javax.swing.DefaultBoundedRangeModel[value=0, extent=0, min=0, max=100, adj=false]
Now setting minimum to 50 . . .
A ChangeEvent has been fired!
javax.swing.DefaultBoundedRangeModel[value=50, extent=0, min=50, max=100, adj=false]
Now setting maximum to 40 . . .
A ChangeEvent has been fired!
javax.swing.DefaultBoundedRangeModel[value=40, extent=0, min=40, max=40, adj=false]
Now setting maximum to 50 . . .
A ChangeEvent has been fired!
javax.swing.DefaultBoundedRangeModel[value=40, extent=0, min=40, max=50, adj=false]
Now setting extent to 30 . . .
A ChangeEvent has been fired!
javax.swing.DefaultBoundedRangeModel[value=40, extent=10, min=40, max=50, adj=false]
Now setting several properties . . .
A ChangeEvent has been fired!
javax.swing.DefaultBoundedRangeModel[value=40, extent=10, min=40, max=50, adj=true]
A ChangeEvent has been fired!
A ChangeEvent has been fired!
A ChangeEvent has been fired!
A ChangeEvent has been fired!
javax.swing.DefaultBoundedRangeModel[value=40, extent=20, min=0, max=100, adj=false]
*/
import javax.swing.DefaultBoundedRangeModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class MainClass {
  public static void main(String args[]) {
    try {
      DefaultBoundedRangeModel model = new DefaultBoundedRangeModel();
      ChangeListener myListener = new MyChangeListener();
      model.addChangeListener(myListener);

      System.out.println(model.toString());
      System.out.println("Now setting minimum to 50 . . .");
      model.setMinimum(50);
      System.out.println(model.toString());
      System.out.println("Now setting maximum to 40 . . .");
      model.setMaximum(40);
      System.out.println(model.toString());
      System.out.println("Now setting maximum to 50 . . .");
      model.setMaximum(50);
      System.out.println(model.toString());
      System.out.println("Now setting extent to 30 . . .");
      model.setExtent(30);
      System.out.println(model.toString());

      System.out.println("Now setting several properties . . .");
      if (!model.getValueIsAdjusting()) {
        model.setValueIsAdjusting(true);
        System.out.println(model.toString());
        model.setMinimum(0);
        model.setMaximum(100);
        model.setExtent(20);
        model.setValueIsAdjusting(false);
      }
      System.out.println(model.toString());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

class MyChangeListener implements ChangeListener {
  public void stateChanged(ChangeEvent e) {
    System.out.println("A ChangeEvent has been fired!");
  }
}

           
       








Related examples in the same category

1.new DefaultBoundedRangeModel()
2.DefaultBoundedRangeModel: addChangeListener(ChangeListener l)
3.DefaultBoundedRangeModel: getValueIsAdjusting()
4.DefaultBoundedRangeModel: setExtent(int n)
5.DefaultBoundedRangeModel: setMaximum(int n)
6.DefaultBoundedRangeModel: setValueIsAdjusting(boolean b)
7.DefaultBoundedRangeModel: toString()