I have 2 JTabbedPane
. I am unable to refresh the data. PLease help, here is my code:
pane1:
//.. some codes...
// This is the ButtonListener
private class ButtonListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
userInput = tf.getText(); // tf is JTextField
//System.out.println("the input is "+ finalInput);
pane2.updateData(userInput);
}
}
pane2:
public void updateData(String s){
System.out.println("Update data function is called");
labelUser.setFont(new Font("Arial", Font.BOLD, 30));
labelUser.setText("Updated text here " + s);
}
Here is my main class:
import java.awt.*;
import javax.swing.*;
public class Main {
public static Pane2 p2 = new Pane2();
public static void main(String[] args) {
JFrame f= new JFrame ("My Frame");
f.setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE);
JTabbedPane tp = new JTabbedPane();
p2 = new Pane2();
tp.addTab("Pane1", new PaneFirst(p2));
tp.addTab("Pane2", new PaneSecond());
f.add(tp);
f.pack();
f.setVisible(true);
}
}
The labelUser
never updates, but I trace the updateData
function, its being called. Why is the text in labelUser
not being updated?
EDIT:
"labelUser
" come from pane2.java
class.