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 4 of 4

Thread: A textfield to be filled before the update

  1. #1
    Member
    Join Date
    Oct 2013
    Location
    Cyprus
    Posts
    35
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default A textfield to be filled before the update

    Hello guys,
    I have a problem with my code.I want a textfield to be filled before the update.So my code

    if (textfield.getText().is Empty()){
    show message dialog ("Please fill the textfield"); //Shows the message but then continues with the execution and when finish with the update, the request focus is activated
    textfield.requestFocus();
    textfield.getText();
    }

    I want the request focus to work before update and then fill the textfield.That is my problem. I hope you understand.

    Thanks in advance.


  2. #2
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: A textfield to be filled before the update

    Quote Originally Posted by mariosarmy View Post
    I hope you understand.
    Sorry, I don't get it, can you re-explain?
    The message dialog is "modal", I suppose, and when the dialog is visible you can't edit the text field. Is it correct?
    But when the dialog is closed, if you immediately get the text, the user has no time to type ....
    Andrea, www.andbin.netSCJP 5 (91%) – SCWCD 5 (94%)

    Useful links for Java beginnersMy new project Java Examples on Google Code

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: A textfield to be filled before the update

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for newcomers.

  4. #4
    Member
    Join Date
    Oct 2013
    Location
    Cyprus
    Posts
    35
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: A textfield to be filled before the update

    Quote Originally Posted by andbin View Post
    Sorry, I don't get it, can you re-explain?
    The message dialog is "modal", I suppose, and when the dialog is visible you can't edit the text field. Is it correct?
    But when the dialog is closed, if you immediately get the text, the user has no time to type ....
    SOLVED

    BUTTON UPDATE ACTION PERFORMED FUNCTION
     
              String name=txtname.getText();
              String surname=txtsurname.getText();
              String street=txtstreet.getText();
              String carModel=txtcarmodel.getText();
              if(txtmobile.getText().isEmpty()){
                  JOptionPane.showConfirmDialog(rootPane,"Mobile CAN'T BE BLANK","Warning",JOptionPane.ERROR_MESSAGE); //HERE I WANTED TO STOP THE EXECUTION AND FOCUS ON THE TEXTFIELD BEFORE 
                  txtmobile.requestFocus();                                                                                                                 //UPDATE THE TABLE  
                  return;
              }
              String mobile=cl.PhoneNumberConversion(txtmobile.getText());
              String phone=cl.PhoneNumberConversion(txtphone.getText());
              String chassis=txtchassis.getText();
              String carPlate=txtcarPlates.getText();
              String serviceDetails=txtserviceDetails.getText();
            try{   
     
              conn=con.getConn();
     
               String Updatesql="UPDATE customers SET name='"+name+"',surname='"+surname+"',street='"+street+"',car_model='"+carModel+"',mobile='"+mobile+"',phone='"+phone+"',service_details='"+serviceDetails+"',chassisno='"+chassis+"',car_plates='"+carPlate+"' WHERE id='"+lblID.getText()+"'";
               pst=conn.prepareStatement(Updatesql);
     
               int rowsUpdated=pst.executeUpdate();

    Thanks for the reply

Similar Threads

  1. validate the textfield
    By mohamed_mashood in forum Java Theory & Questions
    Replies: 6
    Last Post: April 9th, 2013, 03:40 AM
  2. ComboBox and TextField
    By fahad in forum AWT / Java Swing
    Replies: 2
    Last Post: May 31st, 2010, 08:47 AM
  3. Need Help with my JComboBox and Textfield
    By superawesome in forum AWT / Java Swing
    Replies: 1
    Last Post: November 10th, 2009, 12:15 PM
  4. JComboBox and Textfield
    By Nexusfactor in forum AWT / Java Swing
    Replies: 3
    Last Post: November 9th, 2009, 12:57 PM
  5. Combo/TextField Help
    By GRossi0511 in forum AWT / Java Swing
    Replies: 2
    Last Post: October 26th, 2009, 08:15 PM

Tags for this Thread