我认为这更好。为什么标签文本没有改变?主类是NewJFrame形式
public class NewJFrame extends javax.swing.JFrame {
public NewJFrame() {
initComponents();
NewJPanel jpanel = new NewJPanel();
anotherPanel.add(jpanel);
//there is also a label in this frame outside of the anotherPanel
}
}
这是一个JPanel 表单。我将此 jpanel 添加到 NewJFrame (anotherPanel)
public class NewJPanel extends javax.swing.JPanel {
public NewJFrame newJFrame;
public NewJPanel() {
initComponents();
this.setSize(200, 200);
//there is a button here
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
this.newJFrame = newJFrame;
newJFrame.jLabel1.setText("Need To change the text from here"); // this is not working, text is not changing
}
}