开发者

JLabel opaque and alpha

In JPanel I have few JLabels created like this:

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

When I click on any JLabel (mouseClicked(MouseEvent e)) I can get information about it in JOptionPane. In the same JOptionPane I have checkBox to mark selected label (check-> setBorder(BorderFactory.createLineBorder(Color.red)), uncheck -> setBorder(null). When I check and then uncheck jLabel, somethink like this is happened:

JLabel opaque and alpha

How to rid of these 开发者_开发技巧checkBoxes from labels?

edit: checkBoxes on labels are only pictures, not real checkBoxes. Maybe this picture will help:

JLabel opaque and alpha

This square with red border is now check by chechBox Mark on JOptionPane. And this one on left (with checkBox picture on it) was checked earlier. I don't know how explain this, it just happens after I click on checkBox Mark on JOptionPane. After click I set red border or set border null on label, nothing more.


As an aside, (this probably should be a comment, but I'm using an answer for the code blocks) this..

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

..is equivalent to..

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


Those check boxes won't 'just appear' there so precisely. Are you drawing them somewhere at the labels?! Please check this thoroughly!

A little more code would be useful.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜