From: Kevin B. <kb...@ca...> - 2002-01-16 16:49:35
|
"McDonald, Ross" wrote: > > Hi list members, > > please could somebody give me a pointer on how to do a mouseover and > mouseout on a JButton, > in my particular case I just want to be able to display a message in a > status bar when these events occur for a range of buttons, You can either do it the Java way (addMouseListener on the JButton), or can use a jython shortcut syntax of passing 'mouseEntered' & 'mouseExited' as properties to the JButton constructor: from java.awt import * from javax.swing import * f = JFrame( "MoveOverButton" ) cp = f.contentPane mOff = "Move over the button" mOn = "Mouse is over the button" l = JLabel( mOff ) cp.add( l, BorderLayout.SOUTH ) def on( event ): l.setText( mOn ) def off( event ): l.setText( mOff ) b = JButton( "MoveOverMe", mouseEntered=on, mouseExited=off ) # could also addMouseListener cp.add( b, BorderLayout.NORTH ) f.setSize( Dimension(300, 300) ) f.show() kb |