Nel mio problema ho un JPanel opaco e un altro JPanel traslucido (semitrasparente) che si trova sul primo JPanel. Quando ho aggiunto i pulsanti radio sul JPanel in alto. Il problema è che ogni volta che passo il mouse sopra l'area dell'etichetta di ciascun pulsante di opzione (e ogni volta che allontano il mouse dall'etichetta), diventa sempre più scuro.Oscillante: mouse sopra l'etichetta del pulsante radio su JPanel traslucido
package trial;
import java.awt.Color;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
public class Test {
public static void main(String arg[]){
JFrame rootframe = new JFrame("Test panel");
rootframe.setSize(800, 550);
rootframe.setExtendedState(JFrame.MAXIMIZED_BOTH);
JPanel basePanel = new JPanel(); //fills rootFrame
basePanel.setOpaque(true);
basePanel.setBackground(Color.yellow);
JPanel panelContainingRadioButtons = new JPanel();//wraps radio buttons
panelContainingRadioButtons.setOpaque(true);
panelContainingRadioButtons.setBackground(new Color(0,0,0,100));
ButtonGroup buttonGroup1 = new ButtonGroup();
JRadioButton jRadioButton1 = new JRadioButton();
jRadioButton1.setText("Text A...............................");
jRadioButton1.setOpaque(false);
jRadioButton1.setForeground(Color.white);
buttonGroup1.add(jRadioButton1);
JRadioButton jRadioButton2 = new JRadioButton();
jRadioButton2.setOpaque(false);
jRadioButton2.setForeground(Color.white);
buttonGroup1.add(jRadioButton2);
jRadioButton2.setText("Text B.......................");
JRadioButton jRadioButton3 = new JRadioButton();
jRadioButton3.setOpaque(false);
jRadioButton3.setForeground(Color.white);
buttonGroup1.add(jRadioButton3);
jRadioButton3.setText("Text C................................");
panelContainingRadioButtons.add(jRadioButton1);
panelContainingRadioButtons.add(jRadioButton2);
panelContainingRadioButtons.add(jRadioButton3);
basePanel.add(panelContainingRadioButtons);
rootframe.add(basePanel);
rootframe.setVisible(true);
}
}
Credo che questo non è un problema con i pulsanti di scelta perché, in un'altra occasione ho osservato che nelle stesse condizioni, se ho aggiunto un JLabel verso l'alto JPanel, e aggiungi gli ascoltatori al pannello superiore in modo che il colore del testo di JLabel cambierà quando il mouse passa sopra, e ripristinare il colore originale quando le uscite del mouse, il testo diventa ridisegnati in luoghi diversi, come nell'immagine qui sotto: -
Se necessario Pubblicherò anche quel codice. Penso che sia lo stesso problema che c'è in entrambi i casi.
+1 Buon articolo. – trashgod
Esattamente quello che ho bisogno .. Grazie mille signore! –