Re: TextField Increment/Decrement Buttons



Martijn Mulder wrote:
This is very nice. Thank you! JSpinner is just what I was looking for and with your example and with the specs from internet I'll find out how to use it. JSpinner rules :-)


"IchBin" <weconsul@xxxxxxx> schreef in bericht news:D_KdnbQSY_D5X0beUSdV9g@xxxxxxxxxx
Martijn Mulder wrote:
No JSpinner in my Java Developers ALMANAC :-(


"IchBin" <weconsul@xxxxxxx> schreef in bericht news:-tOdnSFRy6y_DkbeUSdV9g@xxxxxxxxxx
Martijn Mulder wrote:
I cannot find the javax.swing component that does the following. A fairly common control on the right side of a TextField, consisting of two small arrows, one up and one down, that lets you increment or decrement the value in the TextField by clicking on one of them. I know they must be there but I cannot find out how they are called in java.

Thank you
The only thing I can think of is in combination with a JSpinner



--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________


'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor,  Regular Guy (1952-)

I did not know that you *only* look at the "Almanac" to see what objects\classes java supported. Yes you will not find the JSpinner in the Almanac. I built mine working from the JDK API Specs.

You should get into a habit of referencing it, life will be much easer. You will have to look at the API Specs for Spinner\SpinnerNumberModel(s) to changed a few things but here is some code to get you going..


private JSpinner spinnerCompareSize; private SpinnerNumberModel spinnerModelCompareSize;

public JSpinner buildSpinner(String toolTip)
{
Dimension spinnerDimension = new Dimension(35, 25);
spinnerCompareSize = new JSpinner();
spinnerCompareSize.setToolTipText(toolTip);
spinnerCompareSize.putClientProperty("is3DEnabled", Boolean.TRUE);
spinnerCompareSize.setMinimumSize(spinnerDimension);
spinnerCompareSize.setPreferredSize(spinnerDimension);
spinnerCompareSize.setMaximumSize(spinnerDimension);
spinnerModelCompareSize = new SpinnerNumberModel(12, 0, 100, 1);
//
// Disable keyboard edits in the spinner
JFormattedTextField tf =
((JSpinner.DefaultEditor) spinnerCompareSize.getEditor()).getTextField();
tf.setEditable(false);
spinnerCompareSize.setModel(spinnerModelCompareSize);
spinnerCompareSize.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent evt) {
JSpinner spinner = (JSpinner)evt.getSource();
quoteCompareSize = (Integer)((JSpinner)evt.getSource()).getValue();
}
});
return spinnerCompareSize;
}


--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________


'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)


Please stop top posting your responses in these NG's.

You can also look at the 'Big Index' on how to use the JSpinner
http://java.sun.com/docs/books/tutorial/reallybigindex.html

particularly:
http://java.sun.com/docs/books/tutorial/uiswing/components/spinner.html


--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________


'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor,  Regular Guy (1952-)
.