How to create a different shape JButton?
posted 12 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I am a beginner in java programming, I almost try all examples on net in creating Java Components, and it is pretty well. Now my teacher wants me to work on a project. I am sick of the look of JButton.
My question is: "Is it possible for me to change the JButton's shape?"
I've heard of something like overriding paintComponent() method and extending JButton. However, I am not sure how to do it.
Another thing I read is that I can use JPanel and add some mouseListener to it. I tried to draw a .png file using photoshop and add it to my panel, but the thing is the panel's background remains
intact (the rectangle border). How can I remove that if I want my button to be for example circle?
Please send a simple code regarding this.
Thanks in advance.
My question is: "Is it possible for me to change the JButton's shape?"
I've heard of something like overriding paintComponent() method and extending JButton. However, I am not sure how to do it.
Another thing I read is that I can use JPanel and add some mouseListener to it. I tried to draw a .png file using photoshop and add it to my panel, but the thing is the panel's background remains
intact (the rectangle border). How can I remove that if I want my button to be for example circle?
Please send a simple code regarding this.
Thanks in advance.
posted 12 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Welcome to the Ranch.
Custom painting could be one of the possible solutions. More on it here http://docs.oracle.com/javase/tutorial/uiswing/painting/
Another approach could be to provide an image icon to the button and make it borderless and transparent so that only the image shows. Of course you need to consider that the button is still a clickable rectangle. In other words if your image is a red circle at the center of the button the corners of the original button would still exist.
This is similar to the panel approach you mentioned. To make things transparent use setOpaque (or in case of button setContentAreaFilled())
Custom painting could be one of the possible solutions. More on it here http://docs.oracle.com/javase/tutorial/uiswing/painting/
Another approach could be to provide an image icon to the button and make it borderless and transparent so that only the image shows. Of course you need to consider that the button is still a clickable rectangle. In other words if your image is a red circle at the center of the button the corners of the original button would still exist.
This is similar to the panel approach you mentioned. To make things transparent use setOpaque (or in case of button setContentAreaFilled())
posted 12 years ago
If you're crazy about fancy effects, I suggest you abandon Swing in favor of JavaFX.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Jc Frane wrote:I am a beginner in java programming, I almost try all examples on net in creating Java Components, and it is pretty well. Now my teacher wants me to work on a project. I am sick of the look of JButton.
If you're crazy about fancy effects, I suggest you abandon Swing in favor of JavaFX.
luck, db
There are no new questions, but there may be new answers.
| There is no greater crime than stealing somebody's best friend. I miss you tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |








