Add mouse event on JLabel?

Hi there!
Can i add a mouse event on JLabel? 'Coz i thought of when I'm double-clicking the label, i could capture the text on the label and open a new sub-frame that displays information of the captured text. Your replies would be appreciated! Thanks ;)

Why don't you just add a MouseListener to you label and wait for the user to click it. Shouldn't be that hard to accomplish.
JLabel myLabel = new JLabel("some text");
myLabel.addMouseListener(new MouseAdapter() {
  public void mouseClicked(MouseEvent e) {
    if (e.getClickCount() > 1) {
      // user double-clicked the label
    } else {
      // user single-clicked it
});cheers,
kelysar

Similar Messages

  • Add mouse event in JLabel

    Hello!
    I have a Jtable in wich I inserted some JLabels. This labels are inside a Vector, and I use this TableCellRender to show them.
    Here is the code of my TableCellRenderer.
    public class JLabelCellRender extends JLabelsPanel implements  TableCellRenderer {
        Border b;
        /** Creates a new instance of PLIconLabel */
        public JLabelCellRender() {
            super(); /* null indicates no layour manager */
            setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
            b=BorderFactory.createLineBorder(Color.black);
        public java.awt.Component getTableCellRendererComponent(JTable table,
                Object value,
                boolean isSelected,
                boolean hasFocus,
                int row, int column) {
            removeAll();
            setBackground(getCor());
            Vector modulos=(Vector)value;
            JLabelModuloTurmaMouseEvents me=new JLabelModuloTurmaMouseEvents();
            if(modulos.size()==0)
                return this;
            for(int i=0;i<modulos.size();i++){
                JLabelModuloTurma x=(JLabelModuloTurma)modulos.elementAt(i);
    //add the event to label       
        x.addMouseListener(me);
                x.setAlignmentX(CENTER_ALIGNMENT);
                x.setAlignmentY(BOTTOM_ALIGNMENT);
                if(!x.getText().equals(""))
                    x.setBorder(b);
                add(x);
            return this;
    }Now I want to add a mouse event to labels but it doesn't work.
    Is possible to do that? Please help me.
    Thanks in advance.

    Well thanks for your suggestions. By now I'm trying to write a TableCellEditor. I think if I can return a component like the rendered compononent of each cell with the method getTableCellEditorComponent I have access to do whatever I want. Here is my TableCellEditor class:
    import java.awt.Color;
    import java.awt.Component;
    import java.util.Vector;
    import javax.swing.*;
    import javax.swing.border.Border;
    import javax.swing.table.TableCellEditor;
    import javax.swing.BoxLayout;
    public class GrelhaHorariosCellEditor extends AbstractCellEditor implements TableCellEditor {
        Vector labels;
        JPanel painel;
        Border b;
        public GrelhaHorariosCellEditor(){
            painel=new JPanel();
            painel.setLayout(new BoxLayout(painel, BoxLayout.Y_AXIS));
            b=BorderFactory.createLineBorder(Color.black);
        public Component getTableCellEditorComponent(JTable table, Object value,
                boolean isSelected, int r, int c) {
            labels=(Vector)value;
            if(labels.size()==0){
                stopCellEditing();
                return null;
                else{
            for(int i=0;i<labels.size();i++){
            JLabelModuloTurma li=(JLabelModuloTurma)labels.elementAt(i);
            painel.add(li);
            return painel;
        public Object getCellEditorValue() {
            return labels;
    }What you think of my ideia? Thanks for reply.

  • DISABLE MOUSE EVENT on jlabel

    Dear all,
    I have a jlabel on which i perform a click and the embbeded image switch between start and stop image.
    My problem consists in preventing from performing multiples click/or disabling mouse event while the application starts loading some parameters.
    switchViewLabel.addMouseListener(new MouseAdapter() {
                   public void mouseClicked(MouseEvent e) {
                        //it takes a long time
                                   onSwitchViewButtonClick();
    protected void onSwitchViewButtonClick() {
              System.out.println("onSwitchViewButtonClick");
              if (canGo) {
                   System.out.println("canGo");
                   canGo = false;
                   MainWindowPeer.getInstance().setCursorToWait();
                         //this action load parameter
                            CommandWindow.getInstance().switchView();
                         refreshSwitchViewButton();
                   MainWindowPeer.getInstance().setCursorToDefault();
                   canGo = true;
         } But on my console i have noticed :
    canGo
    onSwitchViewButtonClick
    canGo
    onSwitchViewButtonClick
    canGo.....
    It looks like we store mouse event anywhere and for each event we execute onSwitchViewButtonClick code and consume event.(it seems to not be asynchronous)....
    How to do ???
    Thanks for any helps..

    Dear all,
    yes i want to ignore mouse events until the processing is done.But how to perform process in separate thread and what is a semaphore.Is it possible to have much more explanation...
    Shall i do following code..
    mouseAdapter = new MouseAdapter() {
                   public void mouseClicked(MouseEvent e) {
                        SwingUtilities.invokeLater(new Runnable(){
                             public void run() {
                                  //switchViewLabel.removeMouseListener(mouseAdapter);
                                  onSwitchViewButtonClick();
                                  //switchViewLabel.addMouseListener(mouseAdapter);
              };Thanks you in advance...

  • How to call mouse event on particular treecell

    how to call a mouseevent on a particular Treecell of a Treeview
    I have tried with setcellfactory but the effect is applied to the whole TreeView. How can i apply it to a particular TreeCell

    How can it be? It seems not.
    Please allow me to clarify my problem-
    I have jcomponents on a layer of jlayeredpane.
    Now I can use MouseListener on the layeredpane.
    Like to get coordinates of the mouse and showing in a textfield -
    private void jLayeredPane1MouseDragged(java.awt.event.MouseEvent evt) {
             projectNameID.setText("Mouse dragged");      
        private void jLayeredPane1MouseEntered(java.awt.event.MouseEvent evt) {
            projectNameID.setText("Mouse entered");
        private void jLayeredPane1MouseExited(java.awt.event.MouseEvent evt) {
            projectNameID.setText("Mouse exited");       
        private void jLayeredPane1MouseMoved(java.awt.event.MouseEvent evt) {
            projectNameID.setText("Mouse moved");       
        private void jLayeredPane1MousePressed(java.awt.event.MouseEvent evt) {
            projectNameID.setText("Mouse pressed");
            currentPoint.setText("("+evt.getX()+" , "+evt.getY()+")");
        }                                          But when my mouse moves on the jcomponent created on a layer then the mouse events don't work.
    That means I need to add mouse event for that component.
    Now how can I do that?
    Edited by: fireball003 on Feb 28, 2008 1:12 PM

  • Having picked up a mouse event, pass it to parent component.

    This is further to my table cell hover, which is otherwise working.
    I track the mouse accross the table using an invisible child component, and when the mouse leaves it, move the child onto the new cell position.
    The problem is that, while the mouse is over the invisible component, that component is grabbing all the mouse events. My table also wants to detect mouse events (though it's interested in clicks).
    The obvious thing is, after they've been dealt with and the child component level, to transfer the events to the table (having mapped the mouse coordinates). However all the processEvents methods in components like JTable are protected.
    I suppose I could extend JTable and add a method to get arround protected, but that's nasty, especially since a lot of my JTables are already subclassed.

    I had to do just this. I have JLabel's in a JPanel. The JPanel is in a LayeredPane. When I mouse over the JLabels, they grab the mouse events... which I don't want. I want the LayeredPane to get it.
    So in the JLabel, I do:
          * Don't send to parent what you don't have to. Things like tooltips will
          * be broken if this is not handled carefully...
         public void mouseClicked(MouseEvent e) { }
         public void mouseMoved(MouseEvent e) { }
         public void mouseEntered(MouseEvent e) { }
         public void mouseExited(MouseEvent e) { }
         public void mouseReleased(MouseEvent e) { machine.dispatchToParent(e);}
         public void mouseDragged(MouseEvent e) { machine.dispatchToParent(e);}
         public void mousePressed(MouseEvent e) { machine.dispatchToParent(e);}(the "machine" above is a JPanel). Now in the JPanel, aka "machine", I do:
    Point point; int comp_x, comp_y; // for component with respect to this machine
    public void dispatchToParent(MouseEvent e) {
         point=((JComponent)e.getSource()).getLocation();
         //System.out.println("Dispatching: " + e.getX() + " " + e.getY());
         //System.out.println("Component position: " + ((JComponent)(e.getSource())).getLocation());
         if (e.getButton() > 0) MsgIFrame.println("ME at: " + comp_x + "," + comp_y + " button: " + e.getButton() );
         if (e.getButton() > 1) {
              popup(e);
              return;
         comp_x=(int)point.getX(); comp_y=(int)point.getY();
         comp_x+=this.getX(); comp_y+=this.getY();
         e.translatePoint(comp_x, comp_y);
         room.getLayeredPane().dispatchEvent(e);
    }Above, the "room" is a JInternalFrame with a LayeredPane inside it, as you can see. I do a little translating so the LayeredPane gets the event in its coordinate space, not those of its Components.

  • How to throw the mouse event to a upper level component?

    For example: a panel using absolute layout, and there is a label on it.
    Now when mouse clicked on the label, i do not want the label but the panel to get the mouse event , so that i can get the mouse click point's x and y in the panel.
    How to implement it?
    Thanks a looooooooooooot for ur help
    Best Regards

    try this
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class Testing extends JFrame
      public Testing()
        setSize(100,75);
        setLocation(300,200);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        final JPanel p = new JPanel();
        JLabel lbl = new JLabel("Click Me");
        lbl.setToolTipText("OK");
        lbl.setBorder(BorderFactory.createLineBorder(Color.BLACK));
        p.add(lbl);
        getContentPane().add(p);
        lbl.addMouseListener(new MouseAdapter(){
          public void mousePressed(MouseEvent me){//match method name
            p.dispatchEvent(me);}});
        p.addMouseListener(new MouseAdapter(){
          public void mousePressed(MouseEvent me){//with this method name
            System.out.println("Panel clicked");}});
      public static void main(String[] args){new Testing().setVisible(true);}
    }

  • Mac java - no mouse event

    I am having trouble with my app where when you are at the login screen and you enter your login name, then click on the password text field the focus will not go there but remains on the user name field. You can tab ok to the password field. Has anyone encountered this with mac's. I am not sure if it's the code ( I have taken it over from someone else).
    At one point the tab didn't work either, but I found some code that was specific to 1.4 and newer versions of Java, but it was only looking for Sun's 1.4 or better, not Apple's, so I was able to fix that by checking to see if the Java being used was Apple's. So I'm not sure if this is another code-specific exclusion, but if it is, I just can't find it. The mouse click works fine if I use Apple's 1.3 java.
    So I guess my question is, does anyone know of any issues with mouse events and Apple's java 1.4 version.
    Thanks.

    Something isn't right with your code. The code below works fine on OSX 10.3.2:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class SignInDialog extends JDialog {
       private JTextField serverJTextField = new JTextField("server");
       private JTextField userNameJTextField = new JTextField("username");
       private JPasswordField passwordField = new JPasswordField("password");
       public static void main(String args[]) {
          new SignInDialog();
       public SignInDialog() {
          super();
          try {
             init();
             setVisible(true);
          } catch (Exception ex) {
             ex.printStackTrace();
       private void init() {
          this.setTitle("Login");
          this.setResizable(false);
          this.setSize(new Dimension(270, 187));
          this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
          JLabel serverJLabel = new JLabel("Server:");
          JLabel usernameJLabel = new JLabel("Username:");
          JLabel passwordJLabel = new JLabel("Password:");
          JButton loginJButton = new JButton("Login");
          JButton cancelJButton = new JButton("Cancel");
          // (int x, int y, int width, int height) 
          serverJLabel.setBounds(new Rectangle(10, 12, 130, 25));
          serverJTextField.setBounds(new Rectangle(84, 12, 167, 25));
          usernameJLabel.setBounds(new Rectangle(10, 49, 130, 25));
          userNameJTextField.setBounds(new Rectangle(84, 49, 167, 25));
          passwordJLabel.setBounds(new Rectangle(10, 86, 130, 25));
          passwordField.setBounds(new Rectangle(84, 86, 167, 25));
          loginJButton.setBounds(new Rectangle(90, 123, 75, 25));
          cancelJButton.setBounds(new Rectangle(176, 123, 75, 25));
          this.getContentPane().setLayout(null);
          this.getContentPane().add(serverJLabel, null);
          this.getContentPane().add(serverJTextField, null);
          this.getContentPane().add(usernameJLabel, null);
          this.getContentPane().add(userNameJTextField, null);
          this.getContentPane().add(passwordJLabel, null);
          this.getContentPane().add(passwordField, null);
          this.getContentPane().add(loginJButton, null);
          this.getContentPane().add(cancelJButton, null);
          loginJButton.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(ActionEvent e) {
                System.out.println("loginJButton.actionPerformed");
          loginJButton.addKeyListener(new java.awt.event.KeyAdapter() {
               public void keyPressed(KeyEvent e) {
               if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                  System.out.println("loginJButton.keyPressed");
          cancelJButton.addActionListener(new java.awt.event.ActionListener() {
             public void actionPerformed(ActionEvent e) {
                dispose();
    [/code[                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Firefox mouse event not behaving the same on PC and Mac computers

    I use the FCKEditor and having a very strange problem. When I click on the FCKEditor's editing area, the keyboard gets disabled untill I click the mouse somewhere outside of the editing window. The problem only happen on Firefox (3.6.10) on Mac computer (Snowleopard 10.6.4). Doing exactly the same steps on PC works without any problem.
    What I want to know:
    - Is it possible that the Firefox on Mac is different than the PC in handling mouse events? Or some other areas?

    Sounds more that Firefox is treating that editor area as read-only.
    Start Firefox in [[Safe Mode]] to check if one of your add-ons is causing your problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    See [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]]

  • Mouse Events at the icon in systray.

    My program call library function to add, modify or delete icon into systray.
    Additionaly I'd like to get back information when any mouse event had happen under icon in systray like move mouse, right/left button click etc. to display popup menu (as an standart behaviour).
    I've tried Windows Message Queue, but it only works inside application window area.
    How could I do it ?
    Any suggestions, examples or advises ?
    Rumcajs.

    Requirements    Price: $29.95
     Application Software:
    LabVIEW 7.0+
     Toolkits Software:
     Additional Software:
     Language's:
    LabVIEW
    INVtray LabVIEW Toolkit allows the programmer to create a LabVIEW program that can be hidden from the task bar and accessed through the System Tray.  Comes with a sample VI that demonstrates all the features of the toolkit.

  • How to catch the mouse event from the JTable cell of  the DefaultCellEditor

    Hi, my problem is:
    I have a JTable with the cells of DefaultCellEditor(JComboBox) and added the mouse listener to JTable. I can catch the mouse event from any editor cell when this cell didn't be focused. However, when I click the editor to select one JComboBox element, all the mouse events were intercepted by the editor.
    So, how can I catch the mouse event in this case? In other word, even if I do the operation over the editor, I also need to catch the cursor position.
    Any idea will be highly appreciated!
    Thanks in advance!

    Hi, bbritta,
    Thanks very much for your help. Really, your code could run well, but my case is to catch the JComboBox event. So, when I change the JTextField as JComboBox, it still fail to catch the event. The following is my code. Could you give me any other suggestion?
    Also, any one has a good idea for my problem? I look forward to the right solution to this problem.
    Thanks.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test3
    extends JFrame {
    // JTextField jtf = new JTextField();
    Object[] as = {"aa","bb","cc","dd"};
    JComboBox box = new JComboBox(as);
    public Test3() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = getContentPane();
    String[] head = {
    "One", "Two", "Three"};
    String[][] data = {
    "R1-C1", "R1-C2", "R1-C3"}
    "R2-C1", "R2-C2", "R2-C3"}
    JTable jt = new JTable(data, head);
    box.addMouseListener(new MouseAdapter() {
    // jtf.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e)
    System.out.println("-------------------JComboBox mouseclick....");
    jt.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e)
    System.out.println("-------------------JTable mouseclick....");
    // jt.setDefaultEditor(Object.class, new DefaultCellEditor(jtf));
    jt.setDefaultEditor(Object.class, new DefaultCellEditor(box));
    content.add(new JScrollPane(jt), BorderLayout.CENTER);
    setSize(300, 300);
    public static void main(String[] args) {
    new Test3().setVisible(true);
    }

  • Inappropriate mouse event coordinates in the WebKit of HTMLLoader/StageWebView

    Hi,
    We have a desktp application which incorporates an HTMLRichTextEditor (implemented in HTML/JS and loaded into AIR).
    We have run into a big problem with text selection though. It seems that the both the HTMLLoader and the StageWebView are passing wrong mouse coordinates to the WebKit when the cursor is outside of the component.
    I've created a sample application which uses mx:HTML (which is a wrapper of the HTMLLoader) and a WebView class (a wrapper aroun StageWebView reference to which is given here).
    The application is located here in Dropbox. The source code of the app is here.
    The app was built with Flex 4.6 and ran in AIR 3.7
    The sample app has a WebView which loads loremipsum and HTML loading some dummy local HTML page. The HTML page uses the JS->AIR bridge to report the mouseevents to a function in AIR. In the snapshot below the selection was started from the first row and then slowly continued to the left. As soon as it reaches the green area the selection changes unexpectably. As it can be seen in the bottom right -> the WebKit has received a mouse event with incorrect coordinates. The reported mouse coordinates seem to be the mouse coordinates within the green component and the selection behaves like that. If the mouse is moved to the blue - the selection changes again (according to the coordinates in the blue area).
    The component which uses the StageWebView behaves in absolutely the same way.
    I'd assume that I have to post a bug but I decided to post here at first.
    I've tried a few workarounds in order to stop and ongoing selection or to change it's behaviour but none of them with any relevant success. Even disabling mouse children for the entire application has no effect on the selection once it's started.
    Any help and/or comments would be much appreciated.
    Thanks !

    Thank you for the heads up.  Do you know if this is a recent change in behavior with AIR (ie. does this occur in previous versions)?  Regardless, could you please open a new bug report on this over at bugbase.adobe.com? 
    Once added, please post back with the URL so that others affected can add their comments and votes and I can follow up internally.
     

  • Working with mouse events in Strobe's Widget classes

    I'm adding a caption on/off toggle button (classname CaptionButton) to the ControlBar class of Strobe Media Playback 1.5.1, and I'm having a difficult time understanding how mouse events are passed to child widgets of a ButtonWidget. In my CaptionButton class (which extends ButtonWidget), I add an instance of another widget, ListWidget, that extends Widget, and I show/hide this ListWidget with a mouse click event in the CaptionButton. The ListWidget is a composite class with a List component from Flash CS5, and the cell renderers in the List component do not respond to mouse events (over, selected, etc). How do I enable this type of mouse interaction within a Widget class? With the VolumeWidget, it looks like all mouse events are recreated and then controls are manually positioned according to the event properties, but this would be rather difficult with a component that has a virtual layout like List component. Any suggestions would be greatly appreciated.
    -Robert

    Ok, found that WidgetHint sets mouseChildren = false, etc. But I have a new problem---how do I stop autoHide timer while the user is interacting with a child widget? I was looking at the VolumeWidget that is used from the MuteButton widget, but I don't see how it stops the autoHide timer from enacting.

  • Need More Mouse Events

    [http://forums.sun.com/thread.jspa?messageID=10811388|http://forums.sun.com/thread.jspa?messageID=10811388]
    During search over net I found the above thread and it seems to be describing the same problem which I am also facing. For my application also I need to capture all the mouse events while dragging. I tried the soluiotn mentioned at this thread to solve this problem by overrinding the below method in several ways:
    protected AWTEvent coalesceEvents(AWTEvent existingEvent,AWTEvent newEvent);
    Even after several attempts, I could not succeed. Can you please suggest how to do that. I was not able to reply to above thread so creating this new thread.
    Thanks

    I wanted to see if a timer based approach does indeed produce a smoother curve than just simply listening for mouse drag events. What I came up with below was the resulting test code. Lo and behold, using a timer does indeed produce a smoother curve. But it wasn't because it was capturing more mouse positions, it was because it was capturing less. Ain't that a kicker? Another interesting thing is that according to the source code, coalesceEvents is a no-op. The documentation, however, would have you believe that it coalesces mouse events as I thought it did.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.GeneralPath;
    import javax.swing.SwingUtilities;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.Timer;
    import javax.swing.BorderFactory;
    public class Test {
        private static class TimerBasedPanel extends JPanel implements MouseListener {
            private GeneralPath line;
            private Timer mousePosQuerier;
            private Component mouseEvtSource;
            private int pointCount;
            public TimerBasedPanel(Component mouseEventSource) {
                mousePosQuerier = new Timer(15, new ActionListener() {
                    Point lastMousePoint = new Point(-1, -1);
                    public void actionPerformed(ActionEvent e) {
                        Point p = MouseInfo.getPointerInfo().getLocation();
                        if (p.x != lastMousePoint.x || p.y != lastMousePoint.y) {
                            lastMousePoint.setLocation(p);
                            SwingUtilities.convertPointFromScreen(p, mouseEvtSource);
                            line.lineTo(p.x, p.y);
                            pointCount++;
                            repaint();
                mouseEvtSource = mouseEventSource;
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                if(line != null) {
                    ((Graphics2D) g).draw(line);
            public void mousePressed(MouseEvent e) {
                line = new GeneralPath();
                line.moveTo(e.getX(), e.getY());
                pointCount = 1;
                mousePosQuerier.start();
            public void mouseReleased(MouseEvent e) {
                mousePosQuerier.stop();
                repaint();
                System.out.println("Timer Based, Points Captured: " + pointCount);
            public void mouseEntered(MouseEvent e){}
            public void mouseExited(MouseEvent e){}
            public void mouseClicked(MouseEvent e){}
        private static class DragEventsPanel extends JPanel
                implements MouseListener, MouseMotionListener{
            private GeneralPath line;
            private int pointCount;
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                if(line != null) {
                    ((Graphics2D) g).draw(line);
            public void mousePressed(MouseEvent e) {
                line = new GeneralPath();
                line.moveTo(e.getX(), e.getY());
                pointCount = 1;
            public void mouseDragged(MouseEvent e) {
                pointCount++;
                line.lineTo(e.getX(),e.getY());
                repaint();
            public void mouseReleased(MouseEvent e){
                System.out.println("DragEvent Based, Points Captured: " + pointCount);
            public void mouseEntered(MouseEvent e){}
            public void mouseExited(MouseEvent e){}
            public void mouseClicked(MouseEvent e){}
            public void mouseMoved(MouseEvent e) {}
        public static void main(String args[]) {
            JFrame frame = new JFrame();
            JPanel drawPanel = new JPanel() {
                @Override
                protected AWTEvent coalesceEvents(AWTEvent existingEvent,
                                                  AWTEvent newEvent) {
                    if(newEvent.getID() == MouseEvent.MOUSE_DRAGGED) {
                        return null;
                    }else {
                        return super.coalesceEvents(existingEvent, newEvent);
            TimerBasedPanel timerPanel = new TimerBasedPanel(drawPanel);
            DragEventsPanel dragPanel = new DragEventsPanel();
            drawPanel.setBorder(BorderFactory.createTitledBorder("Draw here"));
            timerPanel.setBorder(BorderFactory.createTitledBorder("Uses a timer"));
            dragPanel.setBorder(BorderFactory.createTitledBorder("Listens for drag events."));
            drawPanel.addMouseListener(timerPanel);
            drawPanel.addMouseListener(dragPanel);
            drawPanel.addMouseMotionListener(dragPanel);
            frame.setLayout(new java.awt.GridLayout(0,3));
            frame.add(drawPanel);
            frame.add(timerPanel);
            frame.add(dragPanel);
            frame.setSize(600,200);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
    }Edited by: Maxideon on Sep 16, 2009 9:56 PM
    Minor error, but now fixed.

  • Swing Mouse Event Propagation

    Hello,
    I'm developing my first Swing application.
    One of the components is a thumbnail image panel (ext. JPanel) containing several other components (mostly ext. JLabel). I have the image panel receiving mouse events so as to allow the user to see when the image panel is 'in focus' (rollover effect basically) and to allow the image panel to be selected by clicking.
    I added a tooltip to one of the contained labels, and it now 'consumes' my mouse enter/exit event so that now it is as if the label is not part of it's container. This is not what I want.
    Is there not some simple way to allow mouse events to be listened for by a child component but yet to 'fall through' to a listener in the parent component?
    Any insight into this little problem would be most appreciated.
    Thanks.

    You can listen to all MouseEvents generated:
    Toolkit.getDefaultToolkit().addAWTEventListener( new AWTEventListener()
         public void eventDispatched(AWTEvent e)
              System.out.println(e);
    }, AWTEvent.MOUSE_MOTION_EVENT_MASK + AWTEvent.MOUSE_EVENT_MASK);You would then need to determine if the source component is a descendent of your main panel.

  • Disable JTree and stop it from receiving mouse events

    Hi,
    I have a JTree which has a mouse listener associated with (which is used for right-click operations)..,..anyway I am trying to disable the tree, so I call setEnabled(false)...which, as documented, disables the tree but it will still receive mouse events. I also tried, setEditable(false)..... the only way I can think of is to remove the mouse listener, and then when I want to re-enable the tree, I have to add it back.
    is there some other way?
    thanks

    Hi,
    I have a JTree which has a mouse listener
    ner associated with (which is used for right-click
    operations)..,..anyway I am trying to disable the
    tree, so I call setEnabled(false)...which, as
    documented, disables the tree but it will still
    receive mouse events. I also tried,
    setEditable(false)..... the only way I can think of
    is to remove the mouse listener, and then when I want
    to re-enable the tree, I have to add it back.
    is there some other way?Why do you want another way? This seems like a perfectly viable way to accomplish what you want.

Maybe you are looking for

  • Error while uploading Transport request

    Hi friends, Error while uploading transport request to the transport directory, we downloaded the trasnport request from one sap system which have a set of developments for example downloaded files are; control file: K900470.SAD and Data file: R90047

  • How to read messages longer than network buffer size

    The logic of my application is: the client sends a request to the server and wait, in blocking mode, for its response. The server can responde with strings longer than 64KB (size of their sending and receiving buffer size), so under the hood, can als

  • What is the difference between component and sub-assebly?

    Experts, What is the diffence between sub-assembly and a component? in my report if user enters component it should display sub-assembly. if it is reverse should not get component for that. is there any function module for this? I tried in CS15 but n

  • Quicktime movies saved on mac have sound but no video in QTpro (windows)

    I have QT files saved on a hard drive by someone on mac (hard drive formatted to be compatible with both mac and windows) The QT files wouldn't open initially, I upgraded to QT pro and now they open and play, but only sound, no video.   When I try to

  • Direct Quote

    Hi all, May I know what is Direct Quote in foreign currency transactions? Thanks in advance Shravan