I new here, and I'm a beginner about developing. My problem is that I have couple of JTextField
controls inside a JPanel
which is inside a JFrame
too, and the text field doesn't show the text that I pass by a method, and I don't know why, because the source for that is really simple.
THE PROBLEM
I want to show the coordinates of the mouse of a canvas that I get in a pair of text fields. That canvas is inside a frame like a panel which contain the couple of text fields. I'm going to put here the source of a canvas which in a MouseMotionListener
is refer.
public void addPosicionPuntero(){
addMouseMotionListener(new MouseMotionAdapter(){
@Override
public void mouseMoved(MouseEvent evento){
x1 = evento.getX();
y1 = evento.getY();
updateUI();
panelCoordenadas pC = new panelCoordenadas();
pC.mostrarCoordenadas(x1,y1);
System.out.println(x1 + " --- " + y1);
}
@Override
public void mouseDragged(MouseEvent evento){
mouseMoved(evento);
}
});
}
well, now in other class the panel which includes the text field.
public class panelCoordenadas extends javax.swing.JPanel{
JTextField txfX = new JTextField("X");
JTextField txfY = new JTextField("Y");
public panelCoordenadas() {
this.setSize(100, 100);
//this.setBounds(60,50,100,60);
this.setLocation(50, 50);
this.setBackground(Color.yellow);
JLabel coordX = new JLabel("coordX");
JLabel coordY = new JLabel("coordY");
add(coordX);
add(coordY);
txfX.setEditable(false);
txfY.setEditable(false);
txfX.setSize(40, 20);
txfY.setSize(40, 20);
add(txfX);
add(txfY);
}
public void mostrarCoordenadas(int x, int y){
txfX.setText(String.valueOf(x));
txfY.setText(String.valueOf(y));
System.out.println("mostrarCoordenadas = " + x + " --- " + y);
updateUI();
}
}
I put a System.out to know if its gets the data. The data shows by screen but not for the text field.
If anybody knows what's the problem I'd glad to tell me.