Cope with having our text set to "".
git-svn-id: https://samskivert.googlecode.com/svn/trunk@1439 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: IntField.java,v 1.6 2004/02/25 13:17:41 mdb Exp $
|
// $Id: IntField.java,v 1.7 2004/05/27 22:57:47 ray Exp $
|
||||||
|
|
||||||
package com.samskivert.swing;
|
package com.samskivert.swing;
|
||||||
|
|
||||||
@@ -43,8 +43,12 @@ public class IntField extends JTextField
|
|||||||
*/
|
*/
|
||||||
public int getValue ()
|
public int getValue ()
|
||||||
{
|
{
|
||||||
|
String s = getText();
|
||||||
|
if ("".equals(s)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(getText());
|
return Integer.parseInt(s);
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
Log.warning("This should never, ever, happen");
|
Log.warning("This should never, ever, happen");
|
||||||
}
|
}
|
||||||
@@ -81,6 +85,9 @@ public class IntField extends JTextField
|
|||||||
// from interface SwingUtil.DocumentTransformer
|
// from interface SwingUtil.DocumentTransformer
|
||||||
public String transform (String s)
|
public String transform (String s)
|
||||||
{
|
{
|
||||||
|
if ("".equals(s)) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
int val = Integer.parseInt(s);
|
int val = Integer.parseInt(s);
|
||||||
return Integer.toString(Math.min(_maxValue, Math.max(_minValue, val)));
|
return Integer.toString(Math.min(_maxValue, Math.max(_minValue, val)));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user