Mouse « Button « Java Swing Q&A





1. Adding a child component to a JButton    stackoverflow.com

Is it possible to place a child component inside a JButton and make it transparent to a subset of mouse events so that:

  • The child component receives MouseMotionEvents (so it can respond ...

2. jbutton.doClick() clicks the buttons but does not perform the function    stackoverflow.com

I have a jbutton which performs a function when clicked on by mouse. For doing this programatically I have this other function

void clickButton(){
      backButton.doClick();
}
When I ...

3. Using mouse Motion Listener on JButton?    stackoverflow.com

hii I have used Image as JButton for set in to panel but now i want to use mouse motion listener actions on that image for that purpose what can i do following is ...

4. JButtons don't imediatly change on mouse event    stackoverflow.com

I'm using the java swing library to develop a board game called DAO. The problem is that after the human player makes its move, by clicking on the JButton with the ...

5. Stop JButton repainting on mouse over?    stackoverflow.com

I have created a custom JButton class for representing spaces on a monopoly board. The game is multiplayer so a lot of the information needed to draw the button is held ...

6. How can I press a swing JButton using mouse events?    stackoverflow.com

I Have a JButton (or any Component, really) that I would like to trick into thinking that it has been clicked on and therefore firing its action performed event. I don't ...

7. How to detect mouse moving while left button down?    stackoverflow.com

I would like to detect mouse moving, while the left button is pressed. I simply create a drawing application. I can detect the mouse move without any mouse pressed. But I want ...

8. How to detect more than 3 mouse buttons in Java (Swing)?    stackoverflow.com

Additionally to the regular 3 buttons my mouse has a backward & forward button - how can I detect in Java if one of these two buttons is pressed?

9. Button stay "pressed" if mouseclick event is attached    stackoverflow.com

I built a Swing GUI application, and everything works quite well, except for a little detail: I have two bottons, and each of them has a mouseclick event attached. The problem ...





10. JRadioButton Will not appear until Mouse over    stackoverflow.com

import java.awt.Frame;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.*;

public class IndicatorWindow implements ItemListener {

    JRadioButton RMA, EMA, SMA, Williams, Stochastic;
    JPanel IndPan, RadioPanel, title;
    JLabel Lab;
 ...

11. Java Class to execute in JButton MouseClicked    stackoverflow.com

I am new to Java. With this class I can open a pdf file:

public class ViewPdf {
  public static void main(String[] args) throws Exception {
    Process p ...

12. MouseExited on JPanel runs when JButton in panel hovered over?    stackoverflow.com

I have a JPanel (let's call it ctrlPanel), and using null layout I have placed an JLabel in the background of it. On top of this label I have another JLabel ...

13. Java check mouse button state    stackoverflow.com

How can I check the state of the mouse buttons in Java? I cannot use mouse events, as it involves getting 'mouse released' on an element that has never received 'mouse ...

14. Can two JButton have the same mouse clicked event function?    stackoverflow.com

I am developing a calculator in Java language. The problem is that, i put ten buttons for digits(0,1,2..9) and i want that when i clicked one of them, all perform the ...

15. How to execute button by clicking on another button java?    stackoverflow.com

menuBar = new JMenuBar();
// File Menu
JMenu fileMenu = new JMenu("File");
menuBar.add(fileMenu);
// File->New
JMenuItem newMenuItem = new JMenuItem("New");
frame.setJMenuBar(menuBar);
newMenuItem.addMouseListener(new MouseAdapter() {
    @Override
    public void mousePressed(MouseEvent arg0) {
   ...

16. How do I Highlight buttons when mouse pointer is hovered upon them in Java(Like Start button highlights in XP)?    stackoverflow.com

If mouse pointer is hovered on start button in Windows XP, it highlights. I want to do the same in Java. Can anyone help me?





17. How can I make Robot press and hold a mouse button for a certain period of time?    stackoverflow.com

I am using Java to generate a mouse press using the Robot class:

robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
However, I want the Robot to press the button for a certain period of time. How can I achieve ...

18. How can I use the back and forward mouse buttons in a Swing application?    stackoverflow.com

The question is pretty simple. I couldn't find many links regarding this issue, and the ones I found didn't seemed to avoid the real question. My application must handle the mouse ...

22. JToggleButton - mouseClicked problem    coderanch.com

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 ...

23. Is it a 3 or 2 button mouse?    coderanch.com

I think the real question you need answered may be "Does java treat 2-button and 3-button mice the same". Left click is assigned BUTTON1. I think right click is assigned BUTTON3, leaving BUTTON2 for a middle click if you have one. I have to say I haven't tested this with a 2 button mouse, but I'm sure they dealt with this ...

24. While mouse button is pressed    coderanch.com

Sorry, This is not the ans. to the ques. Ali, the html file for swing namely (home1.htm) contains a serious virus. Here is what i get from Norton Antivirus :- Object Name : C:\Documents and Administrator\Locale settings\..\home1[1].htm Virus Name :HTML.Redlof.A Action Taken :Unable to repair this file upon searching the net for virus i get the foll link :-http://securityresponse.symantec.com/avcenter/venc/data/html.redlof.a.html Ali, if ...

25. Solaris SWING Middle Mouse Button    coderanch.com

26. Elevated button on mouse over    coderanch.com

Hi, Set a default border for the desired button, add a mouse listener to it. use the mouse entered and mouse exited property toggle the border property of the button. Try this code import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; public class ElevatedButton extends JFrame implements MouseListener { JButton btnMouseTest = null; ElevatedButton() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception e){} ...

27. JButton disabling mouse listeners    coderanch.com

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - ...

28. Query regarding Buttons and Mouse Events..    coderanch.com

Hi, I want to have 2 panels in my frame..one for my Buttons and other for rectangles... I have 3 buttons which correspond to a specific color... When I click on RED button and later click in the Rectangle panel...I should get a rectangle with RED color filled inside... can anyone code this for me...plzzz??? bye.

29. MouseMotionListener and JButtons    coderanch.com

Hey, I'm having difficulty getting any events generated when passing over JButtons. I've added the listener to the underlying container. Below is a trivial app designed to give the minimum code necessary to convey my larger problem. I'm sure that I'm just overlooking something, but advice/help would be appreciated. Thanks, /Aran import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; public class ...

30. Motion listener hangs while mouse button is pressed    coderanch.com

I am making a simple space shooter where you use the mouse to move and shoots with the mouse button. I am having trouble with the motion listener i.e the one that listens to mouse movement. When I press the left mouse button and hold it down the motion listener stops responding. The code for the listeners is below. public class ...

31. Problem linking button to mouse event - Please help!    coderanch.com

import java.awt.*; import java.awt.event.*; public class DTF extends Frame implements WindowListener { DrawToolCanvas myCanvas; // member variable public DTF() { setTitle("Draw Tool Frame"); addWindowListener(this); Button square, circle; Panel myPanel = new Panel(); square = new Button("square"); square.setActionCommand("square"); circle = new Button("circle"); circle.setActionCommand("circle"); myPanel.add(square); myPanel.add(circle); add("South", myPanel); DrawToolCanvas myCanvas = new DrawToolCanvas(); // local variable // myCanvas = new DrawToolCanvas(); // member ...

33. How to make Resize JButton() on mouse click...    coderanch.com

Hi, not sure if I understand or not, so I apologize in advance if this is off base. But it sounds like you are trying to resize the button without changing the size of the text in the button, i.e. if the button says "OK", then when the button gets bigger or smaller on resize, the size of the text "OK" ...

34. Creating mouse rollover for for custom drawn JButton    coderanch.com

Chris Baty wrote:Hi guys, Does anyone know how to create a rollover for a custom drawn button? It's easy if you use Icon but mine is custom drawn. If I implement the mouselistener in the myButton class where do I add the listener. If I implement the listener in the JFrame class how does that class know only to redraw that ...

35. Getting mouse button state without events    coderanch.com

Hello, I'm building a Swing program with JOGL. I use mousevents for moving in the 3D scene wich work fine. In the multipass rendering of the 3dscene the user can interrupt rendering by moving the mouse I read the mouse position at the start of the loop X = MouseInfo.getPointerInfo().getLocation().x; Y = MouseInfo.getPointerInfo().getLocation().y; Then read them again ...

36. Show image on glasspane while mouse button is down    java-forums.org

Been looking over your code, but I don't have the time yet to fully grok it. Question though, is what is it trying to accomplish with this set up? Are you trying to show the enlarged picture on click, and then get rid of it if the mouse moves away from original thumbnail rectangle boundaries? I'm betting that this problem can ...

37. how to set mousewheel and arrow button scroll speed equal    java-forums.org

It will interfere with user expectations if you tinker with the amount of wheel scrolling. That said, here's a version of JScrollPane that has a method, setUnitsToScroll(int), that sets the number of "units" that the mouse wheel moves. Typically, a unit is one line of text. Java Code: /* * cryptic comment in JavaDocs for MouseWheelListener: The MouseWheelEvent offers methods for ...

38. Location of Mouse/JRadioButton Problem    java-forums.org

Ok so I'm creating a paint-like program and I have most of it done, except that the fact that the eraser tool does not work. In short, it works all fine without the eraser JRadioButton, but with it I get an error (NullPointerException), because the RadioButton isn't set as a default (.setSelected(true); should set as a default right?) and when I ...

39. JButton doesnt show unless you move mouse over it    java-forums.org

like said so all my buttons get created... but I can't see them unless i move my mouse over the place where they are... then they are visible... this is my code Java Code: package gui; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import domein.DomeinController; public class StartFrame extends JFrame { /** * */ private static ...

40. Hovering mouse over a button and painting    java-forums.org

41. Focus Cycle for Mouse is gone after add MatteBorder for JButton    forums.oracle.com

Hi, I have a problem to get the Mouse focus cycle appeared on JButton after I add a MatteBorder. I did lot of experiments and searched old posts in forum but failed to find a way. I will appreciate greatly if anyone here could give me a clue. The code to add matteborder is like: MatteBorder matte = new MatteBorder(5, 5, ...

42. Jbuttons and right mouse button question    forums.oracle.com

I want to make a jbutton respond to the right mouse button as well as the left. It seems that the action listener cannot do this (maybe it can which is why im posting here!). So I used a mouse listener, but, that isn't working out as well as I'd like it too. I happen to have to click the button ...

43. mouse over on JButton    forums.oracle.com