• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JButton's Icon's Background is Black?

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I'm trying to get a play symbol on a JButton.
I have drawn this using fillPoly(...), but when I create the JButton the space surrounding the triangle is black, I would like it to be the same as the JButton, so that it looks like just the triangle has been drawn on it.

Here is my code...(you need to create an instance of the class though)
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No worries, I fixed it. Thought it was an interesting problem, so I haven't deleted post.
All I had to do was specify BufferedImage.TYPE_INT_ARGB,
I remember using ARGB before to create 'transparent' pixels, and to my amazement it works here.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by colin shuker:
No worries, I fixed it. Thought it was an interesting problem, so I haven't deleted post.
All I had to do was specify BufferedImage.TYPE_INT_ARGB,
I remember using ARGB before to create 'transparent' pixels, and to my amazement it works here.



Thanks for not deleting it. I hope that you never delete a thread just because you figured it out before anyone else answered. I can't count the number of times I have posted a question and was able to figure it out quicker than I thought. I always try to come back and update the thread with the solution. That's how we make this place great.

So, with regards to your solution, what about transparent pixels and TYPE_INT_ARGB made your image appear rather than be black. I don't understand.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I don't really understand ARGB yet, but with RGB, if you specify 0 then thats just black, but in ARGB it comes up as transparent.

If you run my code above, you will have to create an instance of class first, you will see the part of the icon not drawn into shows up as black on the button.
If you then use ARGB instead, you'll see it works fine.

Basically, for my chess application, I have decided to store the images in the classes by saving the pixel data, then building the image from that.
Since the pieces aren't square, eg knight, when you move them on top of another picture, you will want to see the background behind the knight, as you drag it.
But the knights' pixels are stored within a 40 by 40 rectangle, hence a 1600 element array of colors.
If I used RGB colors, then whatever colors I used for the area surrounding knight, I wud still get the whole 40 by 40 square moving with it, whenever knight is dragged.
But by saving the points in the square (exterior to the knight) as 0 using ARGB makes them transparent, and the background shows through.
So thats where I got the idea to change the code in first message to ARGB instead of RGB to get it to work.
 
Would you turn that thing down? I'm controlling a mind here! Look ... look at the tiny ad ...
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic