Results 1 to 7 of 7
  1. #1
    user6123456 is offline Member
    Join Date
    Oct 2009
    Posts
    3
    Rep Power
    0

    Default jTextField Listeners

    I built a basic program that generates an output file that is pushed through a bat file for additional purposes.

    So far the program works just fine I just need to make some aesthetic changes which I don't quite understand.

    Below is the code I have for a button that basically sets all my text fields to a single value. The problem is the text fields don't update themselves after I push the button, they will match the values but the actually jTextFields in the GUI don't update themselves with the correct value.

    I believe I need to add a Listener that will check for changes upon pressing the button but I cant seem to figure out how to implement it.

    Java Code:
        private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
            jTextField1 = jTextField14;
            jTextField2 = jTextField14;
            jTextField3 = jTextField14;
            jTextField4 = jTextField14;
            jTextField5 = jTextField14;
            jTextField6 = jTextField14;
        }

  2. #2
    Willi's Avatar
    Willi is offline Member
    Join Date
    Oct 2009
    Posts
    40
    Rep Power
    0

    Default

    I think it should be like this :

    Java Code:
        private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
            jTextField1.setText() = jTextField14.getText();
            jTextField2.setText() = jTextField14.getText();
            jTextField3.setText() = jTextField14.getText();
            jTextField4.setText() = jTextField14.getText();
            jTextField5.setText() = jTextField14.getText();
            jTextField6.setText() = jTextField14.getText();
        }
    Write a program to achieve anything you want in your life!

  3. #3
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Better make that
    Java Code:
    jTextField1.setText(jTextField14.getText());
    instead.

  4. #4
    Willi's Avatar
    Willi is offline Member
    Join Date
    Oct 2009
    Posts
    40
    Rep Power
    0

    Default

    Quote Originally Posted by r035198x View Post
    Better make that
    Java Code:
    jTextField1.setText(jTextField14.getText());
    instead.
    yeah! thank r035198x, I just keep forgetting about the assignment and comparision of 2 String object :eek:
    Write a program to achieve anything you want in your life!

  5. #5
    user6123456 is offline Member
    Join Date
    Oct 2009
    Posts
    3
    Rep Power
    0

    Default

    Worked perfectly, I tried something like that last night but for all my effort could not get it to work with jTextFields.

  6. #6
    user6123456 is offline Member
    Join Date
    Oct 2009
    Posts
    3
    Rep Power
    0

    Default Another question

    Another question, I have a check box that when selected changes all the appropriate text fields to a single value. The code below works and updates the fields correctly but the problem is that this is a single pass move. Once clicked it populates the fields but if I deselect, I want to perform a clear of all the existing values. Now is there a way to code in a condition to check if the box is already selected? Or is there a way to specify two actions for two seperate events for a jCheckBox? For example on Action Performed Select and Action Performed Select?

    Java Code:
        
    private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {                                           
           
            jTextField8.setText("Enabled");
            jTextField9.setText("Enabled");
            jTextField10.setText("Enabled");
            jTextField11.setText("Enabled");
            jTextField12.setText("Enabled");
            jTextField13.setText("Enabled");
        }
    Sorry if this seems pretty basic, never really programmed a GUI interface before.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Breaking for-loops with listeners?
    By CBarry in forum New To Java
    Replies: 3
    Last Post: 04-22-2009, 03:38 AM
  2. Replies: 1
    Last Post: 01-30-2009, 06:44 PM
  3. Seriously need help on my listeners!!
    By themburu in forum Java Applets
    Replies: 4
    Last Post: 05-26-2008, 10:41 AM
  4. Multiple listeners per event
    By Java Tip in forum Java Tip
    Replies: 1
    Last Post: 01-03-2008, 10:06 AM
  5. Action Event and Listeners
    By lost1 in forum New To Java
    Replies: 3
    Last Post: 11-14-2007, 04:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •