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?
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())
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.
There are no new questions, but there may be new answers.