Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MouseListener problem 1

Status
Not open for further replies.

229257

Programmer
Apr 23, 2002
54
GB
I need to change properties of JButton when right clicked, need a Image change on the button, seem to have tryed mouselisteners and event listeners.

Any help would be great..
 
Check here (look down the screen for the functions which return a boolean based on which mouse-button was clicked)


...or go straight here:


Scan down the page for the link to the isRightMouseButton method or add the parenthetical (java.awt.event.MouseEvent) to the URL (the link above wouldn't include it).

'hope that helps.

--Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
This is the code

private class MyMouseAdapter extends MouseAdapter
{
MyMouseAdapter (){}

public void mouseClicked(MouseEvent event)
{
if(event.isMetaDown())
{
JOptionPane.showMessageDialog(null,"RIGHT");
}
else
{
JOptionPane.showMessageDialog(null,"LEFT");
}
}
I want to access methods of the clicked JButton such as .setIcon.

Any advice
 
Take a look at

Code:
event.getSource()

That will return your Jbutton.

Cheers,
Dian
 
eg.
Code:
JButton button = (JButton)event.getSource();
button.setEnabled(false);

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top