• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JToggleButton - mouseClicked problem

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
I found a bug in JToggleButton and I want to know if it is a more general bug, and how can it be bypassed.
I have some JToggleButtons grouped in a ButtonGroup. On each of them I registered an action listener and a mouse listener.
By clicking back and forth ,I noticed that occasionally, the JToggleButton does not receive a mouseClicked event - although the mousePressed and mouseReleased are received as expected.
I am running on W2K using j2sdk1.4, and I noticed that happen also in j2sdk 1.3, but now it happens much often.
In the following example code below, the output messages:
Pressed
Released
Clicked
...
Pressed
Released
Clicked
Will soon become:
Pressed
Released
Pressed
Released

It is easy to reproduce the bug:
1.Create some JToggleButtons, group them with a ButtonGroup.
2.Register an action listener and a mouse listener.
3.Start clicking on each other.
4.Soon enough, the mouseClicked method will not be called periodically.
Example Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test extends JApplet
{
public void init()
{
JToggleButton button1 = new JToggleButton("Beep1");
JToggleButton button2 = new JToggleButton("Beep2");
ButtonGroup group = new ButtonGroup();
group.add(button1);
group.add(button2);
JPanel contentPane = new JPanel();
contentPane.add(button1);
contentPane.add(button2);
button1.addMouseListener
(
new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
System.out.println("Clicked");
}
public void mousePressed(MouseEvent e)
{
System.out.println("Pressed");
}
public void mouseReleased(MouseEvent e)
{
System.out.println("Released");
}
}
);
button2.addMouseListener
(
new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
System.out.println("Clicked");
}
public void mousePressed(MouseEvent e)
{
System.out.println("Pressed");
}
public void mouseReleased(MouseEvent e)
{
System.out.println("Released");
}
}
);
button1.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Toolkit.getDefaultToolkit().beep();
}
}
);
button2.addActionListener (
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
Toolkit.getDefaultToolkit().beep();
}
}
);
setContentPane(contentPane);
}
}
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't duplicate the problem. The code you supplied works fine with the appletviewer on my machine (I'm using JDK 1.3.1_02 on Win98SE). The only thing that I can possibly think of is that the events are getting out of order possibly due to system lag. I'm not completely sure that there is any guarantee of events ariving in the exact order that they were received.
Sorry I can't help any more with this
 
Think of how stupid the average person is. And how half of them are stupider than that. But who reads this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic