Mouse 1 « Event « Java Swing Q&A





1. Swing, mouseClicked and Z-Order    stackoverflow.com

I have a JFrame with null layout and two one character JLabels on the same position. When I add a MouseListener the MouseClicked event always goes to the first JLabel even if ...

2. Java MouseListener - Events    stackoverflow.com

Does any know if the following is the expected behaviors in terms of what MouseEvents are fired? One seems to be missing or consumed elsewhere.

  1. Right-click on JPanel and display JPopupMenu MousePressedjava.awt.event.MouseEvent[MOUSE_PRESSED,(469,347),absolute(2214,490),button=3,modifiers=Meta+Button3,extModifiers=Button3,clickCount=1] MouseReleasedjava.awt.event.MouseEvent[MOUSE_RELEASED,(469,347),absolute(2214,490),button=3,modifiers=Meta+Button3,extModifiers=Meta,clickCount=1] MouseClickedjava.awt.event.MouseEvent[MOUSE_CLICKED,(469,347),absolute(2214,490),button=3,modifiers=Meta+Button3,extModifiers=Meta,clickCount=1] So far ...

3. How do I determine which monitor a Swing mouse event occurs in?    stackoverflow.com

I have a Java MouseListener on a component to detect mouse presses. How can I tell which monitor the mouse press occurred in?

@Override
public void mousePressed(MouseEvent e) {
  // I want ...

4. Difference between mouseListener and mouseMotionListener in Java?    stackoverflow.com

Is mouseMotionListener going to trigger an event once the mouse moves over the component, whereas mouseListener only triggers if I press a button? So if I have only a mousePressed event, then ...

5. Points not being properly read by MouseListener    stackoverflow.com

I'm having a problem where I can't properly access my instance Point data. I create an multi-dimensional array of GridPanels, and instantiate each with a Point. When first created, everything works as expected.

6. Checking for a series of clicks in java swing GUI    stackoverflow.com

I'm working on a GUI for a chess game and I was wondering if there's any way to check for a series of clicks, for example: user clicks on jPanel THEN ...

7. Java MouseEvents not working    stackoverflow.com

This may be a stupid question, but I have to ask! I have the following code snippets that are supposed to run their corresponding methods when the user interacts with objects. For some ...

8. Java swing how to do when mouse over pop out a small box to show details    stackoverflow.com

I have a JTable displays the event accordingly, I want to do like when mouse over the table cell will pop out a small box show the event details. Something like ...

9. How can I use two NotifyIcons in C# without the second one disappearing when i hover the mouse over?    stackoverflow.com

I Have a VS2008 app that needs to display two notifyIcons in the System tray. One is the main application icon, which allows quick access to the GUI. The second is ...





10. Java swing JComponent "size"    stackoverflow.com

I'm doing a project where i need some custom swing components. So far I have made a new button with a series of images (the Java Metal look doesn't fit with ...

11. Using the mouse wheel with JSpinner in Java    stackoverflow.com

I would like to use my mouse wheel to increment and decrement a JSpinner. Is this possible?

12. Getting the EXACT coords of Mouse in Java    stackoverflow.com

Alright, I know HOW to do but It's doing something weird. I am trying to get the correct X Y coords for a JMenu to appear. I've found a way but it's ...

13. Change the random draw line here for a mouseListener draw    stackoverflow.com

im working on a "paint" program. So far, i have a GUI with 1 button "Ligne" and one drawable panel. in my class Paint_Dessin, theres a method call TracerLigne(). this method ...

14. How can I get mouse location out of my java application?    stackoverflow.com

I've used class MouseInfor,but it can only help get location on the interface of my app. How can I get mouse location out of the app? And I read similar questions on ...

15. MouseListener Help Java    stackoverflow.com

I am trying to write a program in Java Swing that outputs a 10 x 10 grid of geometric rectangles filled with randoms colors. However, when the user clicks on one ...

16. MouseListener event not working in Java    stackoverflow.com

I'm creating an application in which a list of images will be displayed in JList. Each image will be displayed as embedded in a panel. When user moves cursor over the images, ...





17. Tooltip stealing mouse events    stackoverflow.com

When I have buttons near the button of the screen, the tooltip appears underneath the mouse. Clicking will then make the tooltip disappear, instead of clicking the button. Tooltip Example

 ...

18. Drawing a Rectangle using MouseListener & MouseMotionListener    stackoverflow.com

I've created two packages, Display and paint_core, which contain five Java files: Displayable.java, Drawing.java, NewCordinates.java, OldCordinates.java and Main.java. I am facing some coordinates issues and the output is not coming as desired. ...

19. Drawing/plot is not continuous (mouse events involved)    stackoverflow.com

I'm having issues with a java class project. The first step consist in drawing a pattern, so I thought well, this can't be hard. And it isn't, but there one thing ...

20. Proper way to implement mouse events    stackoverflow.com

I have code, it's below, that displays a photograph in the JPanel. Actually, the JPanel is walking through a photo album and I have it so that when the JPanel ...

21. How can I do a "mouse out" effect in Java?    stackoverflow.com

I'm trying to mouse over a JButton (javax.swing.JButton) and set the border color, Now I can get this to work I with a mouse move event on the button, I just ...

22. Play beep sound or any customized sound on all mouse click event in java    stackoverflow.com

I have an application which i am going to install on Linux touch system. The touch system is not giving me the touch sound so i decided to have that feature ...

23. Java Swing painting & Mouse event flicker    stackoverflow.com

I have a class that extends JPanel (below), this panel sits inside a JScrollPane. It listens (to itself) for mouse events and tries to reposition itself (on drag) and rescale itself ...

24. Drawing rectangle using mouse    stackoverflow.com

Possible Duplicate:
How to draw a rectangle on a java applet using mouse drag event and make it stay
Hello. I would like to know how ...

25. freehand drawline using mouse events    stackoverflow.com

may i know if there is any formula for drawing lines? currently i am implementing a freehand draw line in java, however the code below when drawn it is not what ...

26. What causes an endless recursion in AWTEventMulticaster.mouseEntered()?    stackoverflow.com

I've been doing JFrame for a little bit now, and ever since I started using Mouselistener (or any eventlistner for that matter) things would run smooth for about 2 mins or ...

27. mouse events on multiple polygons in java swing    stackoverflow.com

i am trying to write a code for my task. my task is, i have draw may polygons on a single panel by giving coordinate values. and aplly mouse moved event to ...

28. Redirecting Swing mouse events    stackoverflow.com

I am trying to make it possible to display and interact with Java Swing components on top of a Java3D canvas. I am displaying the components by painting a transparent ...

29. Java mouse picking on diamond tiled map    stackoverflow.com

Ok, im at my wits end. I am trying to create a small isometric tile map thats bigger then the screen witha viewpoint i can modify with mouse dragging. I got the ...

30. Swing: How to create a custom JToolTip like widget that moves with the mouse    stackoverflow.com

Java Swing question. I have a JPanel which displays a graph. When I move the mouse over this graph, I want certain information to be displayed on a tooltip-like widget that ...

31. JDateChooser : MouseClicked event doesn't get fired    stackoverflow.com

I want to double click on a JDateChooser to make it enabled. So I use a MouseListener :

jDateChooser1.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) ...

32. How to make MouseClicked event work in java    stackoverflow.com

I am pretty sure this is very easy and that I am only missing one line or two but I just cannot make this work despite searching for solutions over the ...

33. What's the easiest way to draw a (monochrome) array using a mouse with Swing?    stackoverflow.com

I've been searching for a way to draw a black-and-white array on screen. It's a simple array, just 20x20. What I plan to do is to draw on an array with ...

34. java drawing a circle when mouse clicked    stackoverflow.com

i am writing a program that when the mouse is clicked, a circle will be drawn. The below code i've wrote so far.

import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.event.*;
import ...

35. ImageIcon + MouseListener not working after build    stackoverflow.com

I've been doing some coding to learn more stuff and to just try and to just remember a few things but I've run into a problem. I am developing in Netbeans IDE ...

36. How to make a shape appear on top of an image when mouse is clicked?    stackoverflow.com

I'm aiming for the appearance of a rectangle when the mouse is clicked. Here's a snippet of my current code:

    try{
         ...

37. Why isn't my paintComponent working?    stackoverflow.com

What I want to do with my program is when I click the image, the rectangle will come out, together with the JOptionPane. However, the JOptionPane is the only thing popping ...

38. Swing and Mouse Cursur Artifacts    coderanch.com

39. MouseMotionListener Help!!    coderanch.com

Hi! All! well I have a project @ hand that has a Scratch card on it. Well I have thought about implementing the scratch card using Applets / Swing. Well Please letr me know if some has done that and how to go about it. Right now I have captured the mouse dragged event and I need to reveal an image ...

40. Trapping mouse movement    coderanch.com

Yeah, it would go something like this: // image is on myCanvas int mouseX, mouseY; myCanvas.addMouseMotionListener( new MouseMotionAdapter(){ public void mouseMoved( MouseEvent me ) { mouseX = me.getX(); mouseY = me.getY(); // do something with new coordinates } }); you'd need to import java.awt.event.* (I haven't checked that code, but I think it's right). You need to watch this, because when ...

41. Mouse Events    coderanch.com

Ok people, let me see if I can describe what I have and make sense at the same time. I have a Window with internal Frames. Inside one of these internal frames I have a canvas where I need to listen for mouse events. I have another class file that implements the listener. So far, everything works. But what I need ...

42. mouselistener problem    coderanch.com

How can I implement something like this: There're 2 buttons. When click the first one, the pointer will change to wait cursor unless button2 is pressed. When it enters the second one, it will change to default cursor. I know I have to use mouselistener, but the compiler keep on complaining: gui.java uses or overrides a deprecated API What's the problem? ...

43. Attaching MouseListeners.....    coderanch.com

Hi everyone, I'm trying to write an app whereby a user can click on any one of a number of rectangles (all drawn by the Graphics.drawRect(.....) method) move the mouse and click again and the rectangle will move to the new place. The problem is that I can't find a way to identify whether the user has clicked inside a rectangle ...

44. MouseEvent handling.    coderanch.com

45. wanting a mouseListener    coderanch.com

46. mouseOver    coderanch.com

Here's how you'd do something like that... import java.awt.*; import java.awt.event.*; public class RectDrawer extends Panel { Rectangle rect; Color rectColor; public static void main( String[] arg ) { Frame f = new Frame( "Test RectDrawer" ); f.add( new RectDrawer() ); f.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { System.exit( 0 ); } } ); f.setSize( 200, 200 ...

47. MouseMotionListener question    coderanch.com

48. mouselistener/IE    coderanch.com

49. Mouse Wheel Support in Swing Application    coderanch.com

Hi In my mouse, i am having mousewheel to support scrolling.With the help of the wheel, i can scroll the pages in IE browser or any other appliction. In swing application ,i have scroll bar inside a JFrame.I want to have mousewheel action in my swing application to support scrolling. any idea ???

50. MouseMotionListener    coderanch.com

You have a naming conflict. Don't name your class the same name as a class in the standard API that you are also importing and using within the program. This is your program with the name of the class changed:import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Whatever extends JFrame { public Whatever(){ setSize(250,200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container pane = getContentPane(); setVisible(true); addMouseMotionListener(new ...

51. Problem with MouseEvents    coderanch.com

52. what if i dont like where mouse gets clicked    coderanch.com

yellow, i have written many programs which involve non rectangular components and these components overlap each other. For each of these components i have registered mousemotion and mouse listeners but now when mouse gets clicked in the region of the component which is not the valid region for my non rectangular-component the eventhandler for it still gets called. What i want ...

53. Current mouse location...    coderanch.com

If you have a component, then this component can catch every mouse event, for example mouse moved event. This event keeps the information of the current position. You can hold this information in a member (Point) and if the time comes, where you need the information, you will have it. This is the way I would go.

54. Mouse Over?    coderanch.com

hi again. I am having a difficult time trying to define my own color for background of a button. void jBtnReports_mouseEntered(MouseEvent e) { jBtnReports.setBackground(Color.white); } I have done the above, one to change the color on mouse eneter, and once to change it on mouse out. But for mouse out I would like to set the color by either HEX, or ...

55. MouseListener    coderanch.com

Hi, i want that my application would be able to get the position of the mouse every time it is beeing moved. So this is what i get, but it is not working import javax.swing.*; import java.awt.*; import java.awt.event.*; public class proDisplay extends Frame implements MouseListener,MouseMotionListener, ActionListener,Runnable { public proDisplay (String t) { title = t; initializeDisplay(); } private void initializeDisplay ...

56. mouse event    coderanch.com

Hi Hiep, Double clicks are difficult to catch in Swing. You need to check for a double click in the "mouseReleased()" method (of the "MouseListener" interface). In (your implementation of) that method, you need to invoke the "getClickCount()" method (of class "MouseEvent"). Note that each click of the mouse button will fire a "mouse event", so your "mouseReleased()" method will get ...

57. mouse click    coderanch.com

58. JComobBox mouse problem    coderanch.com

59. mouseEntered() doesn't catch the event    coderanch.com

61. Mouse Click Opens Web Browser?    coderanch.com

63. mouse clicks    coderanch.com

64. mouse event redispaching    coderanch.com

my problem is simple but the solution might not be, description: i have a jpanel(inside a JFrame) which is large(300,300) , and has a mouse listner added to it, it contains a label, which also has a mouselistener added to it. now, what i want is whenever i click on the label its mouse pressedevent gets called, inside that method it ...

65. How to do a Mouseover..    coderanch.com

66. URGENT! Cant use mouse in swing application    coderanch.com

Hi i developed a swing application and it works fine and i installed it on some other machines. But on one machine when the screen comes up i cant use my mouse but the key board works but when i move my mouse and try to select a value from the Jlist or any component it doesn't work and i cant ...

67. mouseListener problem in a cardGame    coderanch.com

Hi, I have cards displayed on the contentPane and each of card has mouseListener. The problem part is, when I click one of the cards, my contentPane is also gotten clicked. I`m specifically adding the mouseListener to the card object, how come the contentPane affects from it? I`m using JBuilderX Foundation. I appreciated your time, best regards, burcu bayhan

68. Mouse Clicks in AWT/Swings    coderanch.com

Here's a couple of ways import javax.swing.*; import java.awt.*; import java.awt.event.*; class MouseEX extends JFrame implements MouseListener { public MouseEX() { super("MouseEX"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(300,100); setLocation(400,300); Container frame = getContentPane(); frame.addMouseListener(this); } public void mousePressed(MouseEvent me) { String btn = me.isMetaDown()?"Right":"Left"; JOptionPane.showMessageDialog(null,"isMetaDown method, btn = "+btn); btn = me.getModifiers() == 4? "Right":me.getModifiers() == 16? "Left": "Nothing"; JOptionPane.showMessageDialog(null,"getModifiers method, btn = "+btn); } ...

69. Painting dissappears during resizing (with mouse)    coderanch.com

The getGraphics method is a onetime deal. It just borrows the current graphics context for query or the occasional use. Once java decides to repaint the component (triggered by minimize/restore, maximize, restore events or after a partial/full covering/uncovering by another window) all is lost. One solution is keep a reference to the objects you have created for rendering and arrange for ...

70. Mouse Events Not Registering    coderanch.com

Hello There I'm trying to draw lines on a drawing panel using the mouse to press, drag and release to draw a line. I also need to add functionality to allow the user to change the color of the line. I've just started on this and somehow I cannot get the mouse events to register. I've enclosed the code below. Could ...

71. Mouse motion problems    coderanch.com

72. Mouse Location    coderanch.com

73. Mouse events    coderanch.com

I was trying to store circles in a vector when the mouse is clicked. However, I did not understand how to use the MouseEvent method to detect that this was happening. Can anyone help me? public class CircleDrawer3 extends JFrame { VectorStorage = new Vector(); //declares a vector of shapes public CircleDrawer3 () { Container content = getContentPane(); // Set size, ...

74. Rectangle drawn when mouse is dragged    coderanch.com

75. Mouse event on table header in S.W.T    coderanch.com

76. Mouse Click Madness!    coderanch.com

this is a bit of a dodgy workaround for a double-click of a button it might give you something to play around with import java.awt.*; import java.awt.event.*; import javax.swing.*; class Testing extends JFrame { boolean singleClick = true; public Testing() { setLocation(300,100); setDefaultCloseOperation(EXIT_ON_CLOSE); JPanel jp = new JPanel(); JButton btn = new JButton("Click me once, or twice"); btn.addActionListener(new ActionListener(){ public void ...

77. Mouse busy    coderanch.com

78. Basic MouseListener question    coderanch.com

79. mouseEntered and exited events to paint    coderanch.com

im trying to create a program what when the mouse enters the left side of my window the background should change to red; if the mouse moves into the right side i need to change it to green. once i find the size of my window by saying d = yourFrame.getSize(); where do i calculate to find which side my mouse ...

80. Problem with MouseListener    coderanch.com

You can perform your actions in sequence like this: on mouse click result = doFirstAction(); show result; result = doSecondAction(); show result; result = doThirdAction(); show result; The tricky bit is showing the result on a Swing UI. If you code something to update a text box inline with your operations it won't update the UI reliably. And if you do ...

81. MouseListener    coderanch.com

84. mouse event    coderanch.com

i want to create a simple window with a button that when it is pressed to show a new windows with a ok confirmation in it. here is what i have don until now: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class pb1 { public static void main(String [] args) { JFrame a=new JFrame("Click window!"); JLabel lab=new JLabel("Click the button"); JButton ...

85. Can't make mouse disappear in Java 1.4    coderanch.com

Hi all, I have a program that worked fine when I was using the Java 1.5 libraries, but now that I've changed it to 1.4.2 (Java HotSpot) I get an odd error that I haven't been able to fix. I want to get my mouse cursor to disappear when it's inside a JFrame. The short program below replicates the problem on ...

86. a little confusion with mouseListener    coderanch.com

have you added any components to the frame? if so, do these components have anything that is likely to consume mouseEvents e.g. toolTips both listeners work fine in this simple demo import javax.swing.*; import java.awt.*; import java.awt.event.*; class Testing { public void buildGUI() { JFrame f = new JFrame(); f.setSize(100,100); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); //f.addMouseListener(new GeneralMouseListener());//don't need 2 instances //f.addMouseWheelListener(new GeneralMouseListener()); GeneralMouseListener ...

87. Drawing (mouse events)    coderanch.com

I've created six ellipses labelled p1, p2...up to p6. I'm trying to make it so that on a mouse click (if a p object is selected), an unfilled rectangle will be drawn around it. As a way of letting someone know the object was selected. I haven't had much luck. I don't want the rectangle to be drawn until the mouse ...

88. match parenthesis on mouse click    coderanch.com

89. Copy Text By mouse Event    coderanch.com

Hello all, Suppose i am working on any editor,say for example notepad and i have a text area on my frame suppose i have to copy the text from the editor to my frame's text area just by ....i select the text on the editor by dragging the mouse cursor on it.as soon as i release the cursor over the editor ...

90. Simulate mouse click    coderanch.com

91. drawing with the mouse and zooming    coderanch.com

i am currently making a basic drawing program. i currently have it so that when the mouse button is pressed its xy co-ordinates are passed to a variable and again when the button is released. these four are then used with drawrect etc to produce the shapes. the canvas is currently a image icon on a jLabel on a scrollplane. I ...

92. Simple Mouse Event Question    coderanch.com

I've recently started working with Java and am working with the acm.graphics Package. I'm trying to understand mouse events but am having some difficulty finding resources on them. Do mouse events work in a way that everything inside my mouseClicked(MouseEvent e) method completes once? Because that is what I had expected, but this does not seem to be the case. Is ...

93. weird mouse icon change    coderanch.com

94. mouselistener    coderanch.com

You can still use your mouse - just not in your application. Which would mean that your application can't fire any MouseEvents. (If you're using JDK 1.5+ you can use the MouseInfo class to find the current mouse pointer position at any time - even if your mouse is outside of the frame, or if it is minimized. However, you can't ...

95. MouseMotionListener    coderanch.com

96. mouse event    coderanch.com

import java.awt.*; import java.awt.event.*; import java.awt.geom.Ellipse2D; import java.text.NumberFormat; import javax.swing.*; public class GraphicOption extends JPanel { double[] data = { 20.2, 12.7, 19.0, 35.75, 16.2, 48.9, 31.0, 10.2 }; final int PAD = 20; final int PROX_DIST = 10; Point[] dataLocs; NumberFormat nf; GraphicOption() { nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(1); nf.setMaximumFractionDigits(2); dataLocs = new Point[data.length]; for(int j = 0; j < dataLocs.length; ...

97. tooltip and mouse event    coderanch.com

98. mouseadapter vs mouselistener    coderanch.com

99. SYSTEM mouse events?    coderanch.com

100. mouse event for drawing    coderanch.com