Thanks My friend. This is exactly what I am looking for.
Chetan Pandey
Mystifier <[EMAIL PROTECTED]> wrote:
Mystifier <[EMAIL PROTECTED]> wrote:
Sorry. I do not read things well.
There has been changes to the above functionality in 1.3, 1.4 and 1.5
I have written it for 1.5 and have no idea if it will run on others.
Execute this and you will see 2 textboxes. type on the first one and it will
be updated in the second. I hope you are looking for this.
Mystifier
/*
* Created on Mar 18, 2005
*
*/
package mystifier.examples.keypress;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
* @author mystifier
*
*/
public class KeyPressExample extends JPanel implements KeyListener {
private JTextField textField1;
private JTextField textField2;
public KeyPressExample() {
super(new GridBagLayout());
textField1 = new JTextField(20);
textField1.addKeyListener(this);
textField2 = new JTextField(20);
//Add Components to this panel.
GridBagConstraints c = new GridBagConstraints();
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.HORIZONTAL;
add(textField1, c);
add(textField2, c);
c.fill = GridBagConstraints.BOTH;
c.weightx = 1.0;
c.weighty = 1.0;
}
//The three events
public void keyTyped(KeyEvent e) {}
public void keyPressed(KeyEvent e) {}
public void keyReleased(KeyEvent e) {
textField2.setText(textField1.getText());
}
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
JFrame frame = new JFrame("TextDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
JComponent newContentPane = new KeyPressExample();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Chetan Pandey
Sent: Friday, March 18, 2005 7:54 AM
To: Indian Java Users Group at Delhi
Subject: RE: [JUG-Delhi] Two Text Fields
Dear Mystifier:
My work is a pure JAVA application for offline work and I cannot use Java
Script.
But are you suggesting that their i no such functionality in JAVA Swing that
we have to depend on other languages.
Thanks.
Chetan Pandey
Mystifier <[EMAIL PROTECTED]>wrote:
You need to use _javascript_ to do the task.
Look up Ajax xml on Google.
Regards,
Mystifier
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Chetan Pandey
Sent: Thursday, March 17, 2005 9:06 PM
To: [email protected]
Subject: [JUG-Delhi] Two Text Fields
Dear List:
I am using Java 5 and trying to create a Swing Application.
I want to create two Textfields so that any key-board input in Textfield # 1
is immedietely printed in Text-field # 2. Without clicking on any JButton.
Can anyone pls tell me what Listener to use and the syntax.
Thanks.
Chetan Pandey
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
_______________________________________________
Java mailing list
[email protected]
http://mail.jug-delhi.org/mailman/listinfo/java_jug-delhi.org
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
_______________________________________________
Java mailing list
[email protected]
http://mail.jug-delhi.org/mailman/listinfo/java_jug-delhi.org
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
_______________________________________________ Java mailing list [email protected] http://mail.jug-delhi.org/mailman/listinfo/java_jug-delhi.org
