NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Question- Irregularly shaped buttons?

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
011121



Joined: 14 Apr 2011
Posts: 2

PostPosted: Thu Apr 14, 2011 8:31 pm    Post subject: Question- Irregularly shaped buttons? Reply with 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 Smile
Back to top
Thomas Wolf
Posted via mailing list.





PostPosted: Fri Apr 15, 2011 12:10 pm    Post subject: Question- Irregularly shaped buttons? Reply with quote

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 Smile





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

PostPosted: Fri Apr 15, 2011 7:05 pm    Post subject: Reply with quote

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.





PostPosted: Sat Apr 16, 2011 12:02 pm    Post subject: Question- Irregularly shaped buttons? Reply with quote

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

PostPosted: Sat Apr 16, 2011 3:05 pm    Post subject: Hello Reply with 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 !
Back to top
Thomas Wolf
Posted via mailing list.





PostPosted: Sun Apr 17, 2011 2:55 pm    Post subject: Question- Irregularly shaped buttons? Reply with quote

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: 484
Location: Los Angeles

PostPosted: Mon Apr 18, 2011 1:45 am    Post subject: Reply with quote

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

PostPosted: Mon Apr 18, 2011 6:41 am    Post subject: Reply with quote

It is a interesting sharing............
Back to top
judy07ward



Joined: 01 Oct 2012
Posts: 1

PostPosted: Mon Oct 01, 2012 9:27 am    Post subject: NetBeans Users Reply with quote

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
jasaseomurah



Joined: 14 Feb 2014
Posts: 8

PostPosted: Fri Feb 14, 2014 12:27 am    Post subject: Reply with quote

Reported post
唯一的替代矩形区域是相当复杂的。

你必须定义一个“面具”的形状/大小完全符合您的
不规则图像,然后在骑鼠标监听器上的按钮,以测试
是否鼠标动作发生在掩蔽区域。如果是这样,请继续
正常的动作,如果没有,泡沫的鼠标动作到背景
组分(即按钮被坐在其上componenent)。



jasaseojepara.com | jasaseoterbaik.org | vimax-indonesia.org
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo