get parent of jframe popup

Hi all

I have a jpanel that popup after button clicking on.

So inside my jframe popup i have different jtextfield with some values.

I want that when I select one of the jtextfield (just with the cursor on)

its value fill up parent jframe jtextfield.

Monstly i need to fill up a jtextfiled in a parent jframe of my popup jframe.

Hope to be clear

Regards

[402 byte] By [gionnyDeepa] at [2007-11-27 6:30:06]
# 1

hey,

you could use a focuslistener. so.. add a focuslistener to your textfields in the popup and in focusgained() set the textfield text from your "parent"-frame with the text from your popup textfield. A little demo code.....

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.FocusEvent;

import java.awt.event.FocusListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JTextField;

public class MyFrame extends JFrame {

private JTextField field = new JTextField("myFrameField");

public static void main(String[] args) {

new MyFrame();

}

public MyFrame() {

JPanel panel = new JPanel();

panel.add(field);

JButton button = new JButton("popup");

button.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

new Popup();

}

});

panel.add(button);

this.setContentPane(panel);

this.setLocation(100, 100);

this.setDefaultCloseOperation(EXIT_ON_CLOSE);

this.pack();

this.setVisible(true);

}

public JTextField getField() {

return field;

}

class Popup extends JFrame implements FocusListener {

public Popup(){

JPanel pane = new JPanel();

final JTextField field = new JTextField("first");

final JTextField field2 = new JTextField("second");

field.addFocusListener(this);

field2.addFocusListener(this);

pane.add(field);

pane.add(field2);

this.setContentPane(pane);

this.setLocation(200, 200);

this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

this.pack();

this.setVisible(true);

}

public void focusGained(FocusEvent e) {

getField().setText(((JTextField)e.getComponent()).getText());

}

public void focusLost(FocusEvent e) {}

}

}

hope it helps.... :)

izziieea at 2007-7-12 17:54:30 > top of Java-index,Desktop,Core GUI APIs...
# 2
great!.Thank u
gionnyDeepa at 2007-7-12 17:54:30 > top of Java-index,Desktop,Core GUI APIs...