2011-06-07 90 views
1

在JPanel中我有這樣幾個創建的JLabel:的JLabel不透明和Alpha

... 
Random rand = new Random(); 
Color col = new Color(rand.nextFloat(), 
rand.nextFloat(), 
rand.nextFloat(), 
rand.nextFloat()); 
Color playColor= new Color(col.getRed(), col.getGreen(), col.getBlue(), col.getAlpha()); 
sqr.setOpaque(true); 
sqr.setBackground(playColor); 
sqr.setLayout(null); 
... 

當我點擊任何一個JLabel(的mouseClicked(的MouseEvent e)條)我可以得到關於它的信息的JOptionPane。在同一個JOptionPane中,我有checkBox來標記選定的標籤(check-> setBorder(BorderFactory.createLineBorder(Color.red)),取消選中 - > setBorder(null)。當我檢查並取消選中jLabel時,發生這樣的事情:

enter image description here

如何從標籤擺脫這些複選框

編輯:?在標籤上的複選框只有圖片,沒有真正的複選框也許這幅畫將幫助: enter image description here

此方用紅邊框現在由chechBox檢查在JOptionPane上標記。左邊的這個(上面有checkBox圖片)被更早的檢查過了。我不知道如何解釋這一點,只是在點擊JOptionPane上的複選框標記後發生。點擊後,我在標籤上設置紅色邊框或設置邊框空白,僅此而已。

+2

SSCCE會很好。我不完全明白這個問題。 – jzd 2011-06-07 17:28:03

+0

多一點的代碼在這裏會有所幫助。 – Paul 2011-06-07 17:28:16

+0

順便說一句,爲什麼使用 - >運算符?這是Java而不是C++ – ignis 2011-06-07 19:03:05

回答

1

這些複選框將不會「精確地出現」在那裏。你是否在標籤上的某處繪製它們?請徹底檢查!

稍微多一點的代碼會很有用。

+0

標籤上的複選框只是真正的checkBox的圖片。它們出現在我檢查並取消選中jPanel中的複選框後。我不畫他們。 – czy 2011-06-07 18:43:53

+0

請給我們展示更多代碼!我不關心顏色的東西和一切。準確地向我們展示這些元素是如何在JPanel等中展開的。 – 2011-06-08 13:19:24

2

順便說一句,(這可能應該是一個評論,但我使用的代碼塊回答)這個..

Color col = new Color(
    rand.nextFloat(), 
    rand.nextFloat(), 
    rand.nextFloat(), 
    rand.nextFloat()); 
Color playColor= new Color(col.getRed(), col.getGreen(), col.getBlue(), col.getAlpha()); 

..是相當於..

Color playColor = new Color(
    rand.nextFloat(), 
    rand.nextFloat(), 
    rand.nextFloat(), 
    rand.nextFloat());