public static class IntegerField extends JTextField { public IntegerField(String txt) { super(txt); setDocument(new IntegerDocument()); } public int getInt() { return this.getText().equals("") ? 0 : Integer.parseInt(this.getText()); } }
/** * Inserts a string. * * @param i i. * @param s s. * @param attributes the attributes. * * @throws BadLocationException ?? */ public void insertString(final int i, final String s, final AttributeSet attributes) throws BadLocationException { super.insertString(i, s, attributes); if (s != null && (!s.equals("-") || i != 0 || s.length() >= 2)) { try { Integer.parseInt(getText(0, getLength())); } catch (NumberFormatException e) { remove(i, s.length()); } } }
/** * Inserts a string. * * @param i i. * @param s s. * @param attributes the attributes. * * @throws BadLocationException ?? */ public void insertString(final int i, final String s, final AttributeSet attributes) throws BadLocationException { super.insertString(i, s, attributes); if (s != null && (!s.equals("-") || i != 0 || s.length() >= 2)) { try { Integer.parseInt(getText(0, getLength())); } catch (NumberFormatException e) { remove(i, s.length()); } } }
current = (current == null) ? new Insets(0, 0, 0, 0) : current; this.topValueEditor = new JTextField(new IntegerDocument(), "" + current.top, 0); this.leftValueEditor = new JTextField(new IntegerDocument(), "" + current.left, 0); this.bottomValueEditor = new JTextField(new IntegerDocument(), "" + current.bottom, 0); this.rightValueEditor = new JTextField(new IntegerDocument(), "" + current.right, 0);
/** * Inserts a string. * * @param i i. * @param s s. * @param attributes the attributes. * * @throws BadLocationException ?? */ public void insertString(final int i, final String s, final AttributeSet attributes) throws BadLocationException { super.insertString(i, s, attributes); if (s != null && (!s.equals("-") || i != 0 || s.length() >= 2)) { try { Integer.parseInt(getText(0, getLength())); } catch (NumberFormatException e) { remove(i, s.length()); } } }
current = (current == null) ? new Insets(0, 0, 0, 0) : current; this.topValueEditor = new JTextField(new IntegerDocument(), "" + current.top, 0); this.leftValueEditor = new JTextField(new IntegerDocument(), "" + current.left, 0); this.bottomValueEditor = new JTextField(new IntegerDocument(), "" + current.bottom, 0); this.rightValueEditor = new JTextField(new IntegerDocument(), "" + current.right, 0);
current = (current == null) ? new Insets(0, 0, 0, 0) : current; this.topValueEditor = new JTextField(new IntegerDocument(), "" + current.top, 0); this.leftValueEditor = new JTextField(new IntegerDocument(), "" + current.left, 0); this.bottomValueEditor = new JTextField(new IntegerDocument(), "" + current.bottom, 0); this.rightValueEditor = new JTextField(new IntegerDocument(), "" + current.right, 0);