JMenu holding JButton instances - bug with 5.0?
- From: allen@xxxxxxxxxxxxxxxxx
- Date: 26 Apr 2005 01:51:36 -0700
Hi,
In the past I have had reasons for adding JButton (and JCheckBox)
instances to a JMenu's popup. This has worked successfully prior to
5.0. Now with 5.0 it seems the buttons and checkboxes get stuck when
clicked, with no indication of what went wrong. They get stuck before
their action listeners are even called. Does anyone have an idea why
this might be happening? Below is some basic test code to demonstrate
the problem (demo code only!). Notice how the buttons in the JPopupMenu
work fine, but the buttons in the JMenu get stuck.
thanks
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
/**
* Test Menus and popups for use with other components.
*/
public class MenuTest extends JFrame
{
private JPopupMenu popup = new JPopupMenu( );
private JMenu menu = new JMenu( "TopMenu" );
public MenuTest( )
{
super( "MenuTest" );
JMenuBar menuBar = new JMenuBar( );
setJMenuBar( menuBar );
menuBar.add( menu );
init( popup );
init( menu.getPopupMenu( ) );
final JPanel pCenter = new JPanel( );
add( pCenter, BorderLayout.CENTER );
setSize( 300, 300 );
setDefaultCloseOperation( EXIT_ON_CLOSE );
pCenter.addMouseListener( new MouseAdapter( )
{
public void mouseClicked(MouseEvent e)
{
if ( SwingUtilities.isRightMouseButton( e ) )
{
popup.show( pCenter, e.getPoint( ).x, e.getPoint( ).y );
}
}
} );
}
private void init( Container c )
{
c.add( new JMenuItem( "MenuItem" ) );
c.add( new JButton( "JButton" ) );
c.add( new JCheckBox( "JCheckBox" ) );
}
public static void main( String[] args )
{
MenuTest frame = new MenuTest( );
frame.setVisible( true );
}
}
.
- Follow-Ups:
- Re: JMenu holding JButton instances - bug with 5.0?
- From: John McGrath
- Re: JMenu holding JButton instances - bug with 5.0?
- From: John McGrath
- Re: JMenu holding JButton instances - bug with 5.0?
- Prev by Date: Re: Paint a stickman in a JTable cell
- Next by Date: BoxLayout making component too big
- Previous by thread: Re: Paint a stickman in a JTable cell
- Next by thread: Re: JMenu holding JButton instances - bug with 5.0?
- Index(es):