Swing Pushed Button ImageIcon

J

johnston_58

Hi,

I am trying to create a pushed button image for a button.
I cannot get the setPressedIcon() method to work for me.

I tried using the setIcon method for the button, but the icon shows up
with a grey border around it, however setPressedIcon() does work .
I have now tried the method below - the problem is that the
setPressedIcon() now won't work.

Does anyone know a way around this or have any suggestions?

Thanks in advance for any help.

Kind Regards and Happy Holidays,
Johnston

/****************** code ************************/
JButton bSend;
ImageIcon sendIcon = new ImageIcon("sendBtn.jpg");
ImageIcon pSendIcon = new ImageIcon("pSendBtn.jpg");
....
bSend = new NewButton("Send",sendIcon.getImage());
bSend.setPressedIcon( pSendIcon);
......
}

class NewButton extends JButton {
Image image;

public NewButton(String Text, Image Image) {
super(Text);
setOpaque(false);
image=Image;
}

public void paint(Graphics g) {
g.drawImage(image, 0,0, getWidth(), getHeight(), this);
super.paint(g);
}
}
/***************** End code *****************************/
 
J

johnston_58

Andrew,

Thanks for the reply.

I have now re-written this and have it working now.
I used setInsets which laid out the button images nicely.

Thanks again for the help,
Johnston
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top