Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: how to accept only integers with or without decimals in a JTextField?

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default how to accept only integers with or without decimals in a JTextField?

    I am creating a program and I don't want it to accept character or string in my textfield


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: how to accept only integers with or without decimals in a JTextField?

    There are methods in the Document class that will allow you to do that. I don't have the names right now, but maybe Google could find it for you.

    Look for the setDocument() method and the Document class's insertString method.
    Last edited by Norm; August 29th, 2011 at 07:41 PM. Reason: Changed methods and class

Similar Threads

  1. [SOLVED] Processing Decimals <1 & >0
    By bgroenks96 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 24th, 2011, 01:53 PM
  2. [SOLVED] Writing Integers to .txt File; Returning Random Characters Instead of Integers
    By verbicidalmaniac in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: March 8th, 2011, 09:42 PM
  3. Convert Decimals to Octals using only If/Else
    By jcattau in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 9th, 2011, 12:58 PM
  4. Make JTextArea accept input from JButton
    By crazed8s in forum AWT / Java Swing
    Replies: 9
    Last Post: December 5th, 2010, 09:38 PM
  5. Determine the two smallest integers from a set of user input integers
    By bpontin in forum Loops & Control Statements
    Replies: 4
    Last Post: October 17th, 2010, 06:38 PM