I am looking to create an ATM
style application, in the sense that they will enter a pin and then will check their amount of money, etc. I would like to create a pin system and was looking to use Jbuttons for this. However, I am not too fond of the default skin for the buttons, the sort of orb
look. i was wondering if there was a way in which I could apply custom skins to these buttons. I have heard of something like DefaultLookandFeel
or something similar but am not sure if this is what I am looking for. I hope someone could direct me in the correct direction, thanks!

- 255
- 1
- 2
- 8
-
Add an image of what you want the button to look like. – Java42 May 16 '14 at 17:58
-
I do not have an exact design as of yet, but I was just hoping for a flat looking button with a ring on the out side. similar to that of which you would find at a real ATM. – Harry Kitchener May 16 '14 at 18:00
-
Well, once you create the image - add the image to a JButton and your good-to-go. – Java42 May 16 '14 at 18:02
-
So it would be just like adding an image or colour to a JPanel? Just with a JButton? – Harry Kitchener May 16 '14 at 18:03
-
Would you like `Button` better? (package java.awt) – Alexandru Severin May 16 '14 at 18:04
-
read this--> http://stackoverflow.com/questions/4801386/how-do-i-add-an-image-to-a-jbutton – Java42 May 16 '14 at 18:07
-
@Java42 what? I don't use Buttons, I asked him if he would prefer those – Alexandru Severin May 16 '14 at 18:10
3 Answers
You can override the paint(Graphics g)
method of the JButton
and draw anything you want instead of it. Or, if preferred, you can call super.paint
first and then draw in addition over default image. You can check the text and state of the button you are drawing by simply calling the state check methods like getText()
or isSelected()
.
The simplest way seems to ask your graphic designer to provide button images for the different state, and the draw these images instead of the button. Just do not resize, otherwise the text may not look well.
You are right it is also possible to implement a pluggable looks and feel but for your case seems overkill.

- 20,936
- 12
- 75
- 93
Depending on your situation, you could create a separate custom button class that extends JButton or simply create a new JButton.
Your code will look very similar to something like this:
ImageIcon yourImage = new ImageIcon(imageLocation);
JButton buttonDeposit = new JButton(yourImage);
frame.add(button);

- 125
- 1
- 10
this link will direct you to the most usable look and feel libraries in java Java Look and Feel (L&F)
but to use them you should include the jar file of each one in your project library these look and feel files will manage the skin of all the component in your GUI
you should use some code in the main method. if you want i can write an example for you.