-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
1.2.1, 1.2.2, 1.4.1
-
generic, x86
-
generic, windows_95, windows_2000
Name: vi73552 Date: 04/04/99
Under certain circumstances, some reproducible, and
some not, clicking on a JButton fails to produce a
mouseClicked event.
The bug can be demonstrated by the test class ButtonTest2,
the code of which is given below. The class has a label,
the text of which displays the five MouseListener events
that can be produced:
MOUSE_ENTERED
MOUSE_EXITED
MOUSE_PRESSED
MOUSE_RELEASED
MOUSE_CLICKED
The class has a button named "Button" which reports the
events that occur in it to the label.
The following two circumstances always fail to produce
a mouseClicked event in the test class ButtonTest2:
1) Move the mouse into the JButton and press the mouse on
the letter "B"; while holding down the mouse button
move the mouse to the letter "n" and then release
the mouse button; no mouseClicked event is reported.
(To get a mouseClicked event, the mouse may not be moved
more than a few pixels between the press and the release
of the mouse button; there are times when even this
is not sufficient to generate a mouseClicked event, though
this is not consistent.)
2) Move the mouse into the JButton and press the mouse;
while holding down the mouse button move the mouse
outside of the JButton and then release the mouse button;
AS EXPECTED NO mouseClicked event is reported. Then,
move the mouse into the JButton and press and release
the mouse button, without moving the mouse; no mouseClicked
event is reported.
--
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.UIManager;
public class ButtonTest2 extends JPanel
{
JButton button;
JLabel label;
public ButtonTest2()
{
super();
button = new JButton("Button");
button.setVerticalTextPosition(AbstractButton.CENTER);
button.setHorizontalTextPosition(AbstractButton.CENTER);
button.addMouseListener(new MouseAdapter()
{
public void mouseEntered(MouseEvent e)
{
label.setText("Mouse Entered.");
}
public void mouseExited(MouseEvent e)
{
label.setText("Mouse Exited.");
}
public void mousePressed(MouseEvent e)
{
label.setText("Mouse Pressed.");
}
public void mouseReleased(MouseEvent e)
{
label.setText("Mouse Released.");
}
public void mouseClicked(MouseEvent e)
{
Toolkit.getDefaultToolkit().beep();
label.setText("Mouse Clicked.");
}
});
label = new JLabel("");
label.setFont(new Font("Helvetica", Font.BOLD+Font.ITALIC, 24));
label.setHorizontalAlignment(SwingConstants.CENTER);
Border loweredbevel = BorderFactory.createLoweredBevelBorder();
label.setBorder(loweredbevel);
Dimension labelSize = new Dimension(200,25);
label.setPreferredSize(labelSize);
//Add Components to this container, using the default FlowLayout.
add(label);
add(button);
}
public static void main(String[] args)
{
try
{
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e)
{
}
/*
* Create a window. Use JFrame since this window will include
* lightweight components.
*/
JFrame frame = new JFrame("ButtonTest2");
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
frame.getContentPane().add(new ButtonTest2(), BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
}
(Review ID: 56483)
======================================================================
Name: skT88420 Date: 08/18/99
=20
A button is in a ToolBar.
The action associated with the button cause the toolbar to
be modified (buttons are added or removed).
If the user click on the button, the action is triggered and
the toolbar updated, but if he clicks again, nothing happens,
unless he moves the mouse between the clicks. If he clicks
a third time, the action is triggered, and so on....
Here is a sample code showing this behavior:
---
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class ButtonTest extends JFrame {
=20
JToolBar tb;
ButtonTest() {
tb =3D new JToolBar();
getContentPane().add(tb);
installButton();
pack();
show();
}
=20
void installButton() {
SwingUtilities.invokeLater(new Runnable() {
=09public void run() {
=09 tb.removeAll();
=09 JButton b =3D new JButton("click me");
=09 b.addActionListener(new ActionListener() {
=09 public void actionPerformed(ActionEvent e) {
=09=09installButton();
=09 }
=09 });
=09 tb.add(b);
=09 System.out.println("CLICKED");
=09}
});
}
=20
public static void main(String[] args) {
new ButtonTest();
}
}
(Review ID: 94092)
======================================================================
- relates to
-
JDK-4731797 Mouse click/drag zone is not read correctly from Win32
- Resolved