-
Bug
-
Resolution: Fixed
-
P4
-
1.3.1
-
beta
-
generic
-
generic
-
Verified
Name: rmT116609 Date: 08/10/2001
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)
The drop-down menu sticks on the screen when the top-level item gets disabled.
The sample code below demonstrates the problem.
==================================================
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class TopMenu extends JFrame
{
JTextArea m_ta;
Action m_actCopy, m_actPaste, m_actEdit;
TopMenu() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
setBounds(100, 100, 300, 200);
createMenu();
createPanels();
}
private void createMenu() {
JMenuItem mni;
JMenuBar mnb = new JMenuBar();
JMenu mnu = new JMenu(m_actEdit = new EditAction());
mnu.addChangeListener((ChangeListener)m_actEdit);
mni = new JMenuItem(m_actCopy = new CopyAction());
mnu.add(mni);
mni = new JMenuItem(m_actPaste = new PasteAction());
mnu.add(mni);
mnb.add(mnu);
setJMenuBar(mnb);
}
private void createPanels() {
JTabbedPane pane = new JTabbedPane(JTabbedPane.BOTTOM);
pane.addTab("Editor",m_ta=new JTextArea());
pane.addTab("Options",new JCheckBox(new WrapAction()) );
pane.addChangeListener(new TabChanged());
getContentPane().add(pane);
}
class TabChanged implements ChangeListener
{
public void stateChanged(ChangeEvent e) {
JTabbedPane pane = (JTabbedPane)e.getSource();
boolean bEnableEdit = pane.getSelectedComponent() instanceof JTextArea;
m_actEdit.setEnabled(bEnableEdit);
}
}
class WrapAction extends AbstractAction
{
WrapAction() {
super("Line Wrap");
}
public void actionPerformed(ActionEvent e) {
JToggleButton btn = (JToggleButton)e.getSource();
m_ta.setLineWrap(btn.isSelected());
}
}
class EditAction extends AbstractAction implements ChangeListener
{
EditAction() {
super("Edit");
}
public void actionPerformed(ActionEvent e) {
}
public void stateChanged(ChangeEvent e) {
if( ((AbstractButton)e.getSource()).isSelected() )
m_actCopy.setEnabled(m_ta.getSelectionStart() < m_ta.getSelectionEnd());
}
}
class CopyAction extends AbstractAction
{
CopyAction() {
super("Copy");
}
public void actionPerformed(ActionEvent e) {
m_ta.copy();
}
}
class PasteAction extends AbstractAction
{
PasteAction() {
super("Paste");
}
public void actionPerformed(ActionEvent e) {
m_ta.paste();
}
}
public static void main(String[] args) {
new TopMenu().setVisible(true);
}
}
=====================================================
Compile and run the TopMenu class.
When the application window pops up select "Edit" menu -- a drop-down menu
appears. Don't close it, but instead move mouse cursor down and click on
tab "Options" in the bottom.
Pop up menu will stick on screen!
There is no way get rid of it untill the top level menu item will be enabled.
(Review ID: 129482)
======================================================================