0
votes

Currently I use Netbeans IDE 8. 0, I want to replace skin JPanel when I choose a radio button. The problem which I faced two strong panel in form1 with radio button in form2. Two of them are not in a form. I tried to research in Google but no answer.

In source code, which have I recognized in error since the panel in other form, then what can I do?

Then source code radio button which I created:

private void rwhiteMouseClicked(java.awt.event.MouseEvent evt) {                                    
        rgreen.setSelected(false);
        rred.setSelected(false);
        rblack.setSelected(false);
       jPanel1.setBackground(new java.awt.Color(255, 255, 255));
    }                                   

    private void rgreenMouseClicked(java.awt.event.MouseEvent evt) {                                    
        rwhite.setSelected(false);
        rred.setSelected(false);
        rblack.setSelected(false);
    jPanel1.setBackground(new java.awt.Color(0, 204, 0))
    }                                   

    private void rredMouseClicked(java.awt.event.MouseEvent evt) {                                  
        rgreen.setSelected(false);
        rwhite.setSelected(false);
        rblack.setSelected(false);
         jPanel1.setBackground(new java.awt.Color(255, 0, 0));
    }                                 

    private void rblackMouseClicked(java.awt.event.MouseEvent evt) {                                    
        rgreen.setSelected(false);
        rred.setSelected(false);
        rwhite.setSelected(false);
          jPanel1.setBackground(new java.awt.Color(0, 0, 0));
    }  
Perhaps there is a language barrier, but at least for me, I am having difficulty understanding your question and your problem. Please consider clarifying both, telling more, and showing more pertinent code, preferably a minimal reproducible example.Hovercraft Full Of Eels
Side note: you almost never want to use a MouseListener with a JRadioButton. ActionListener, yes sometimes, ItemListener, but MouseListener, very rarely.Hovercraft Full Of Eels
Side note 2: No need to call setSelected on the other JRadioButtons. Add them all to the same ButtonGroup to have this effect. That you're doing this suggests that you've not yet read the JRadioButton Tutorial. Please check this out.Hovercraft Full Of Eels
@GaneshPatel "Can you post your code what is formA and formB" Better to post an MCVE / SSCCE as I mentioned in my comment. "you have to add ItemListener" That's less optimal than an ActionListener in that it will fire two events for every time a single button is clicked on. "don't forget to call the setOpaque(true) method on your panel" It's the default state of a JPanel. Perhaps you're thinking of JLabel.Andrew Thompson
If the buttons are in a ButtonGroup as suggested by @HovercraftFullOfEels 8 hours ago, there would be no need to check! The button that fires the event would be selected. You've implemented that advice, right? Otherwise we're just wasting our time trying to help.Andrew Thompson