0

Hi,

I have a button with an image in it. When I reduced the width of the button, the image was centered in the button which I do not want to happen. I want it to be left-aligned in the button but have no idea how and searching hasn't yielded any answers so far.

The image is of size 50x67. and the button is 20x67.

Below is the relevant code that I have.

cardPics = new JButton[4][5];
fileURL = getURL("./Images/000.gif");
iconFile = new ImageIcon(fileURL);

cardPics[j][i] = new JButton(iconFile);
cardPics[j][i].setPreferredSize(new Dimension(20,67));

Thanks, any help would be appreciated.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Mr. Blank
0

Thank you very much!

Problem solved:

cardPics[j][i].setHorizontalAlignment(JButton.LEFT);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.