2012-07-17 18 views
6

पर रेडियो बटन लेबल पर माउस को घुमाएं मेरी समस्या में मेरे पास एक अपारदर्शी जेपीनल और दूसरा जेपीनल है जो पारदर्शी (अर्द्ध पारदर्शी) है जो पहले जेपीनेल पर बैठता है। जब मैंने शीर्ष जेपीनल पर रेडियो बटन जोड़े हैं। समस्या हर बार जब मैं प्रत्येक रेडियो बटन के लेबल के क्षेत्र में माउस दर्ज करता हूं (और जब भी मैं लेबल से माउस को दूर ले जाता हूं), यह गहरा और गहरा हो जाता है।स्विंग: पारदर्शी जेपीनेल

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); 

} 
} 

मेरा मानना ​​है कि इस रेडियो बटन के साथ एक समस्या नहीं है क्योंकि, एक अन्य अवसर में मैं देखा है कि इन्हीं परिस्थितियों में, अगर मैं शीर्ष JPanel करने के लिए एक JLabel जोड़ा, और शीर्ष पैनल में श्रोताओं जोड़ सकते हैं ताकि JLabel के पाठ का रंग जब माउस पर होवर किया है बदलने के लिए, और मूल रंग पर सेट हो जाएंगे जब माउस बाहर निकलता है, पाठ नीचे छवि में के रूप में अलग अलग स्थानों में दोबारा बनाई हो जाता है: -

http://s13.postimage.org/6yn3cw48n/Untitled.png

यदि आवश्यक हो मैं भी उस कोड को पोस्ट करूंगा। मुझे लगता है कि यह वही समस्या है जो दोनों मामलों में है।

उत्तर

8

आपको पृष्ठभूमि के लिए उपयोग किए जाने वाले पारदर्शी रंग की वजह से ये चित्रकारी कलाकृतियां मिलती हैं। JComponents पृष्ठभूमि रंग के रूप में पारदर्शी रंगों का समर्थन नहीं करते हैं। यहां @camickr द्वारा एक अच्छा article है जो इस मुद्दे का विवरण देता है और एक वैकल्पिक समाधान भी प्रदान करता है।

+1

+1 अच्छा लेख। – trashgod

+1

बिल्कुल मुझे क्या चाहिए .. बहुत बहुत धन्यवाद श्रीमान! –

4

आपका परिणाम अप्रत्याशित नहीं है, क्योंकि डिफ़ॉल्ट Graphics2Dसमग्रAlphaComposite.SRC_OVER है। यदि आप एक अलग परिणाम चाहते हैं, तो आपको एक अलग मोड का उपयोग करने की आवश्यकता होगी; AlphaComposite.SRC, उदाहरण के लिए, योजक नहीं है। संबंधित उदाहरण here, here और here पाए जा सकते हैं।

+0

महान उदाहरण, +1 – tenorsax

1

लाल, हरा, नीला, और अल्फा एजी का उपयोग करने के बजाय: सेटबैकग्राउंड (नया रंग (236, 233, 216, 220)); सेटबैकग्राउंड का उपयोग करें (नया रंग (236,233,216)); जो लाल, हरा, नीला है। यह पूरी तरह से काम करेगा।

संबंधित मुद्दे