How to use the Swing integer spinner field control on a form.
You can run this technique code from:
NOTE First make sure that database is running on your localhost SilverStream Server | |
See the chapter on the Form Designer in the Tools Guide |
This code uses the getValue()
method to get the current value of the integer spinner control spinRate. It then uses setText()
to place the value in the text label lblSpinnerValue.
This code is from the valueChanged event for the spinRate AgcIntegerSpinner control.
// Display the new spinner value lblSpinnerValue.setText("Spinner Value = " + spinRate.getValue());
On the clicked event of push button btnDecrease, this code uses the getValue()
method to get the current value of the spinner spinRate, then decrements the value by 10 units. It then uses setValue()
to set the new value. Finally it uses setText()
to place the new value in the text label lblSpinnerValue.
This code is from the actionPerformed event of the btnDecrease button. In the live example, similar code for the btnIncrease button checks the value against an upper limit of 100 and increments the value.
private void handle_btnDecrease_actionPerformed(ActionEvent evt) { // Get the current spinner value int iValue = spinRate.getValue(); // Will subtracting 10 from the current spinner value // result in a value which is less than 0? if (iValue - 10 < 0) // Yes, so set the new value to 0 iValue = 0; else // No, so set the new value to (current value - 10) iValue -= 10; // Set the spinner to the new value m_bModifiedbyProgram = true; spinRate.setValue(iValue); m_bModifiedbyProgram = false; // Display the new spinner value lblSpinnerValue.setText("Spinner Value = " + iValue + "%"); }
getMaxValue()
or getMinValue()
.