| View previous topic :: View next topic |
| Author |
Message |
011121
Joined: 14 Apr 2011 Posts: 2
|
Posted: Thu Apr 14, 2011 8:31 pm Post subject: Question- Irregularly shaped buttons? |
|
|
Hello, I'm trying to create a GUI that has some irregularly shaped buttons, and so far I'm failing. I've tried using Jbuttons and replacing the button with an image, unfortunately I end up with a square button large enough to contain my irregular image. Is there a way to set a transparent background color so that when you import the image it knows to treat any pixel that color as "empty"? I've seen that function in another IDE but I'm not sure Java supports it. Is there a better choice than using a Jbutton that would allow me to do what I'm wanting?
More specifically I have a background made up of tessellating shapes and the buttons are shaped to fit into this pattern, but that only works if the button is the right shape, of course  |
|
| Back to top |
|
 |
Thomas Wolf Posted via mailing list.
|
Posted: Fri Apr 15, 2011 12:10 pm Post subject: Question- Irregularly shaped buttons? |
|
|
On Apr 14, 2011, at 4:32 PM, 011121 wrote:
| Quote: | Hello, I'm trying to create a GUI that has some irregularly shaped buttons, and so far I'm failing. I've tried using Jbuttons and replacing the button with an image, unfortunately I end up with a square button large enough to contain my irregular image. Is there a way to set a transparent background color so that when you import the image it knows to treat any pixel that color as "empty"? I've seen that function in another IDE but I'm not sure Java supports it. Is there a better choice than using a Jbutton that would allow me to do what I'm wanting?
More specifically I have a background made up of tessellating shapes and the buttons are shaped to fit into this pattern, but that only works if the button is the right shape, of course
|
The rectangle (border) appears because you haven't told the button not to use it. You also need to tell the button to be transparent. Try some or all of these (can't remember off the top of my head):
JButton.setOpaque(false);
JButton.setBackground(null);
JButton.setBorderPainted(false);
JButton.setBorder(null);
The "clickable region" will still be rectangular, though.
Tom |
|
| Back to top |
|
 |
011121
Joined: 14 Apr 2011 Posts: 2
|
Posted: Fri Apr 15, 2011 7:05 pm Post subject: |
|
|
| hrrrm. The clickable area remaining square is less than ideal but at least this gives me a starting point. Thank you! |
|
| Back to top |
|
 |
Tony Posted via mailing list.
|
Posted: Sat Apr 16, 2011 12:02 pm Post subject: Question- Irregularly shaped buttons? |
|
|
The only alternative to the rectangular area is pretty complex.
You'd have to define a 'mask' that exactly matches the shape/size of your
irregular image, then over-ride the mouse listener on the button to test
whether the mouse action occurred over the masked area. If so, proceed with
normal action, if not, bubble the mouse action up to the background
component (ie the componenent on which the button is sitting.).
Tony
-----Original Message-----
From: 011121 [mailto:address-removed]
Sent: 15 April 2011 20:05
To: address-removed
Subject: [nbusers] Question- Irregularly shaped buttons?
hrrrm. The clickable area remaining square is less than ideal but at least
this gives me a starting point. Thank you! |
|
| Back to top |
|
 |
Dani
Joined: 25 Dec 2010 Posts: 11 Location: pakistan
|
Posted: Sat Apr 16, 2011 3:05 pm Post subject: Hello |
|
|
Hello bro!
if u r using netbeans then simply go to properties window(on right hand side of the netbeans UI) and uncheck the apaque property box.! it will make your button transparent ! |
|
| Back to top |
|
 |
Thomas Wolf Posted via mailing list.
|
Posted: Sun Apr 17, 2011 2:55 pm Post subject: Question- Irregularly shaped buttons? |
|
|
On Apr 16, 2011, at 11:05 AM, Dani wrote:
| Quote: | Hello bro!
if u r using netbeans then simply go to properties window(on right hand side of the netbeans UI) and uncheck the apaque property box.! it will make your button transparent !
------------------------
Dani
| ...and doing that does nothing more than generate the code "buttonName.setOpaque(false);" as my earlier post stated. Not trying to rag on you, but I think it's important that people who want to program in Java actually know the Java way to address a problem. Sadly, the GUI Builder sometimes gets in the way of actually having to learn the language.
Tom |
|
| Back to top |
|
 |
areeda
Joined: 28 Aug 2008 Posts: 469 Location: Los Angeles
|
Posted: Mon Apr 18, 2011 1:45 am Post subject: |
|
|
Just an idea but how about using the click event on the background image?
It seems like you have to figure out all the mappings of pixels and regions to build the buttons anyway. |
|
| Back to top |
|
 |
prabu86
Joined: 18 Apr 2011 Posts: 2
|
Posted: Mon Apr 18, 2011 6:41 am Post subject: |
|
|
| It is a interesting sharing............ |
|
| Back to top |
|
 |
judy07ward
Joined: 01 Oct 2012 Posts: 1
|
Posted: Mon Oct 01, 2012 9:27 am Post subject: NetBeans Users |
|
|
hi,
i agree with Thomas Wolf that , the coding he shares to create a Jbutton transparent i think the coding will be helpful to you to create transparent button , and on the other hand the idea of using the click event on the background image is also a great idea , i appreciate your creativity
Cambridge Locksmith
Mount Laurel Locksmith
Locksmiths West palm beach |
|
| Back to top |
|
 |
|