Results 1 to 7 of 7
Thread: jTextField Listeners
- 10-15-2009, 02:33 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 3
- Rep Power
- 0
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; }
- 10-15-2009, 02:49 PM #2
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!
- 10-15-2009, 02:52 PM #3
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Better make that
instead.Java Code:jTextField1.setText(jTextField14.getText());
- 10-15-2009, 02:56 PM #4
- 10-15-2009, 03:06 PM #5
Member
- Join Date
- Oct 2009
- Posts
- 3
- Rep Power
- 0
Worked perfectly, I tried something like that last night but for all my effort could not get it to work with jTextFields.
- 10-15-2009, 05:03 PM #6
Member
- Join Date
- Oct 2009
- Posts
- 3
- Rep Power
- 0
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?
Sorry if this seems pretty basic, never really programmed a GUI interface before.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"); }
-
You really need to read the Sun Swing tutorial on use of check boxes as it will answer this question just as a quick look at the text field tutorial would have answered the other question: How to Use Buttons, Check Boxes, and Radio Buttons (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
Similar Threads
-
Breaking for-loops with listeners?
By CBarry in forum New To JavaReplies: 3Last Post: 04-22-2009, 03:38 AM -
how to access jTextField of one JFrame1 from JFrame2 & Modify JTextField contents
By sumit1mca in forum AWT / SwingReplies: 1Last Post: 01-30-2009, 06:44 PM -
Seriously need help on my listeners!!
By themburu in forum Java AppletsReplies: 4Last Post: 05-26-2008, 10:41 AM -
Multiple listeners per event
By Java Tip in forum Java TipReplies: 1Last Post: 01-03-2008, 10:06 AM -
Action Event and Listeners
By lost1 in forum New To JavaReplies: 3Last Post: 11-14-2007, 04:26 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks