Note that there are some explanatory texts on larger screens.

plurals
  1. POButton action to change the color of all tabbedpane panel java swing
    text
    copied!<p>I have 2 tab(A and B) in tabbedpane. In A, I write only setBackground(Color.RED);</p> <p>In B, I put a Button. and the codes likes that:</p> <pre><code>A a=new A(); jButton1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub a.setBackground(Color.BLUE); } }); </code></pre> <p>I want to change the color of A from B's button action. But I failure. How can i solve this problem??</p> <p>Thanks in advance...</p> <hr> <p>still my problem not solved. I am posting the whole code:: I used 2 package: "ok","ok1". "ok" contains 1 file named save.java and the code is: </p> <pre><code>public class Save extends javax.swing.JFrame { private JPanel panel1; private JPanel panel2;A a=new A();B b=new B(); public Save() { initComponents(); } //GEN-BEGIN:initComponents // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt; private void initComponents() { panel1=a.initComponents(); panel2=b.initComponents(); jTabbedPane1 = new javax.swing.JTabbedPane(); jScrollPane1 = new javax.swing.JScrollPane(); jScrollPane2 = new javax.swing.JScrollPane(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jTabbedPane1.addTab("Tab 1", null, panel1, "Just Panel"); jTabbedPane1.setMnemonicAt(0, KeyEvent.VK_1); jTabbedPane1.addTab("Tab 2", null, panel2, "Button"); jTabbedPane1.setMnemonicAt(1, KeyEvent.VK_2); </code></pre> <hr> <p>"ok1" contains 2 file: A.java and B.java..... A.java:::::::: </p> <pre><code> public class A extends javax.swing.JPanel { /** Creates new form A */ public A() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ //GEN-BEGIN:initComponents // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt; public JPanel initComponents() { jPanel11 = new javax.swing.JPanel(); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout( jPanel11); jPanel11.setLayout(jPanel1Layout); </code></pre> <hr> <p>B.java:::::::: </p> <pre><code> public class B extends javax.swing.JPanel { A a = new A(); /** Creates new form B */ public B() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ //GEN-BEGIN:initComponents // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt; public JPanel initComponents() { jPanel1 = new javax.swing.JPanel(); jButton1 = new javax.swing.JButton(); jButton1.setText("Action"); jButton1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub a.jPanel11.setBackground(Color.RED); } }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload