?
Solved

jpanel change listener

Posted on 2003-03-25
5
Medium Priority
?
407 Views
Last Modified: 2013-11-23
hellou
is there any simple way to check changes in jpanel members (jtextfields)?

regards
interm
0
Comment
Question by:intermiras
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 8201587
You could add an actionListener to the JTextFields and flag a boolean value.
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 8201602
You can add an ActionListener to the JTextFields which will be notified when chnages occur.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8201622
I guess it should be a Text-listener for the JTextField, implementing the textValueChanged () method.

Mayank.
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 8201647
Or a CaretListener...
0
 
LVL 15

Accepted Solution

by:
ozymandias earned 750 total points
ID: 8201728
Example using a DocumentListener :

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;

public class JTextFieldExample extends JFrame{

     Container contentPane;
     JTextField jtf;

     public JTextFieldExample(String[] args){
          super("JTextFieldExample");
          this.setDefaultCloseOperation(EXIT_ON_CLOSE);
          contentPane = this.getContentPane();
          contentPane.setLayout(new BorderLayout());
          jtf = new JTextField(30);
          jtf.getDocument().addDocumentListener(new DocumentListener(){
               public void changedUpdate(DocumentEvent e){
                    System.out.println("change");
               }
               public void insertUpdate(DocumentEvent e){
                    System.out.println("insert");
               }
               public void removeUpdate(DocumentEvent e){
                    System.out.println("remove");
               }
          });
          contentPane.add(jtf,BorderLayout.NORTH);
     }

     public static void main(String[] args){
          JTextFieldExample jtfe = new JTextFieldExample(args);
          jtfe.setSize(400,400);
          jtfe.setVisible(true);
     }
}
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question