これは良いと思います。ラベルのテキストが変更されないのはなぜですか? メインクラスは 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
}
}