Mouse event problem in jLabel
I don't want to change the Text of a label once i click on it for the second time.This is the code i wrote for it
private void display(java.awt.event.MouseEvent evt) {
try{
if(evt.getSource().equals(jLabel1) && evt.getSource().getText(""))
jLabel1.setText("X");
........but here even for the first time don't change the text.How can i modify the code.Can i write event for the label.Thanks
I don't want to change the Text of a label once i
click on it for the second time.You don't want to change the text? I assume that you mean that you DO want to change the text. And do you mean double-click?
private void display(java.awt.event.MouseEvent evt) {
try{
if(evt.getSource().equals(jLabel1) &&
evt.getSource().getText(""))
jLabel1.setText("X");
but here even for the first time don't change the text.Well, I assume that you're using a MouseListener added to the label to cause this code to execute? Anyway, you're not checking evt.getClickCount() to check to see whether it is a double-click.
Similar Messages
-
Mouse event problem (NEW problem)
Sorry guys...
The last problem was solved, yes... but another one has shown
up!
Remember the code:
txt82.visible = false;
botao82.addEventListener(MouseEvent.MOUSE_OVER, botao82over);
botao82.addEventListener(MouseEvent.MOUSE_OUT, botao82out);
botao82.addEventListener(MouseEvent.CLICK, botao82click);
function botao82over(event: MouseEvent)
txt82.visible = true;
function botao82out(event: MouseEvent)
txt82.visible = false;
function botao82click(event: MouseEvent)
gotoAndPlay("video82");
where i wanted a texto to show or hide depending on the mouse
event?
Ok...
Now, when i CLICK, i'll go over to "video82" allright, but
i'll ALSO get an error!
"Cannot access a property or method of a null object
reference" - on botao82out
which means that: when i click and move up to "video82", the
mouseout is also called to make the text dissapear but the function
is no more available because we've moved up to another time.
Any possibilities?
Erik.Hi Haran,
bota82 IS the movieclip, which has to be like that because of
the naming of it's instance, used to get called in the code.
But anyway, guys, i found the solution! YEP! Increases
tremendously the code, but... well... it works!
i had the button layer extended all over the time.
The problem with this is that when i clicked and went to the
frame video82, for example, all the buttons still showed as
clickable.
How did i solve that?
More magic! Disappearing magic!
at the beginning of the code i certify the buttons to be
visible:
botao82.visible = true;
and so on with all of them...
then, right before the click function, i turned them all OFF
! :D
function botao82click(event: MouseEvent)
botao82.visible = false;
botao83.visible = false;
botao84.visible = false;
botao85.visible = false;
botao86.visible = false;
botao87.visible = false;
botao88.visible = false;
botao89.visible = false;
botao90.visible = false;
gotoAndPlay("video82");
Phew! It worked!
Know what? I think clearer when i discuss the problem with my
fellows here in the forum! Thanks everyone.
Hope this helps others in the future!
Erik. -
I need to implement the pseudocode below into a method called cursorNearVertex (xMouse, yMouse). This method should return either a true or false value depending on what part of the canvas the user clicks on. If the user clicks near a graphical vertex (defined in another part of the application not listed) it will return a true value, if they don't click near the vertex it should return a false value. However I don't know what part of the code the method should go in. Any ideas?
/* Simple polygon selection test
xMouse, yMouse: coordinates of cursor when mouse was clicked
xArray, yArray: arrays containing the x and y coordinates of a polygon's vertices
distance: distance between a vertex and the mouse position
presetMaxDistance: preset distance below which the cursor is considered to be near enough to a vertex
cursorNearVertex(xMouse, yMouse) {
for each vertex {
distance = (xMouse - xArray[vertex]) * (xMouse - xArray[vertex]) +
(yMouse - yArray[vertex]) * (yMouse - yArray[vertex]);
if (distance < presetMaxDistance)
return true;
return false;
// Code for mouse click event
public void serviceMouseEvent(int eventID, int xMousePosition, int yMousePosition)
switch(eventID)
case MouseEvent.MOUSE_CLICKED:
// TO DO: service MOUSE_CLICKED as approriate
break;
case MouseEvent.MOUSE_DRAGGED:
// TO DO: service MOUSE_DRAGGED as approriate
break;
case MouseEvent.MOUSE_PRESSED:
// TO DO: service MOUSE_PRESSED as approriate
break;
case MouseEvent.MOUSE_RELEASED:
// TO DO: service MOUSE_RELEASED as approriate
break;
case MouseEvent.MOUSE_MOVED:
// TO DO: service MOUSE_MOVED as approriate
break;
default:
// TO DO: service "all-other-mouse-states" as approriate
break;
Skeleton app: http://student.soc.staffs.ac.uk/~cmtccc/2dg/SkelApp2DGrel1.zipThis looks like a Java3D question. In which case you might getting better answers to your question if you post it in the Java3d forum.
http://forum.java.sun.com/forum.jsp?forum=21
On my limited Java3d knowledge it looks as though you need to call cursorNearVertex(xMouse, yMouse) method everytime there is a MOUSE_CLICKED event. -
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... -
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 -
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. -
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. -
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. -
Mouse events don't work on a button from a panel ran in a DLL
Hi.
I have a DLL that loads a panel.
Since it's a DLL I can't do the RunUserInterface() function, because the DLL would be stuck waiting for the panel events.
I only do the LoadPanel().
When I click with the mouse on one of the buttons, the pushing down event (simulating the button being pressed) doesn't happen and the callback doesn't run.
But if I press the tab button until the focus reaches the button and press Enter, the callback of the button is executed.
An even more interesting aspect is that this happens when I call the DLL on TestStand, but on an application of mine that calls the DLL just for debug everything works fine.
How can I enable the mouse events?
Thanks for your help.
Daniel Coelho
VISToolkit - http://www.vistoolkit.com - Your Real Virtual Instrument Solution
Controlar - Electronica Industrial e Sistemas, Lda
Solved!
Go to Solution.Hello Daniel,
I got surprised when I read your post, because I am experiencing something almost the same as you do.
I have a DLL (generated by an .fp instrument driver I wrote) which performs continious TCP communication with the UUT.
It starts 2 threads, each for reading from one of the 2 different IPs the UUT has.
Another DLL tests this UUT (with the help of the communication DLL above) by exporting functions to be called by TestStand steps.
If the second DLL wants to display a CVI panel in order to wait for the user response or displays a popup (MessagePopup, ConfirmPopup, etc), user cannot press the buttons.
Actually, there is a point your program and mine differ. I call RunUserInterface and the button's callbacks call QuitUserInterface, so the execution continues after a button is pressed. The problem is buttons cannot be pressed. I also tried looping on GetUserEvent but it did not solve the problem.
There are 2 findings:
1. I had a small exe to test my instrument driver DLL and the popups in it worked pretty well (this coincides with Daniel's findings).
2. We workedaround the problem by shutting down the communication threads in the instrument driver DLL before the popup appears and restrating them afterwards. Although they are separate threads in another DLL, they were somehow blocking user events on another DLL running.
S. Eren BALCI
www.aselsan.com.tr -
Hello everyone,
I'm currently working on an standard as3 (1024x768) app that
is running inside a chromeless Air window to take advantage of the
transparency.
All my tests where done using windows XP professional and AIR
1.0 (the same problem existed in beta3).
The issue I'm having is related with Mouse Events. Somehow
the events take a lot of time to reach the swf file when the user
clicks inside the transparent window.
It's natural that the app runs slower inside a transparent
window (the framerate drops) but I wasn't expecting the clicks to
suffer from such delay (it takes sometimes 2-5sec).
The app is very CPU intensive and the transparencies make it
worse. Something inside the AIR framework is not dispatching the
events properly.
I say this because I tried using the virtualMouse class from
senocular together with a socket to simulate the mouse clicks and
that did the trick.
In conclusion:
Something in the AIR framework for windows XP is messing up
the dispatch of the Mouse events when the app is under heavy cpu
usage inside a chromeless window. I click on the window and it
takes 1-2sec to receive the click event.
However when I dispatch the MouseEvent.CLICK myself using
the virtual mouse class the application immediately receives the
event.
I know this is a strange bug and not many people will have
this problem, but I would like to know from someone with knowledge
of the runtime why this could be happening.
Thank you
Tiago BilouHello everyone,
I'm currently working on an standard as3 (1024x768) app that
is running inside a chromeless Air window to take advantage of the
transparency.
All my tests where done using windows XP professional and AIR
1.0 (the same problem existed in beta3).
The issue I'm having is related with Mouse Events. Somehow
the events take a lot of time to reach the swf file when the user
clicks inside the transparent window.
It's natural that the app runs slower inside a transparent
window (the framerate drops) but I wasn't expecting the clicks to
suffer from such delay (it takes sometimes 2-5sec).
The app is very CPU intensive and the transparencies make it
worse. Something inside the AIR framework is not dispatching the
events properly.
I say this because I tried using the virtualMouse class from
senocular together with a socket to simulate the mouse clicks and
that did the trick.
In conclusion:
Something in the AIR framework for windows XP is messing up
the dispatch of the Mouse events when the app is under heavy cpu
usage inside a chromeless window. I click on the window and it
takes 1-2sec to receive the click event.
However when I dispatch the MouseEvent.CLICK myself using
the virtual mouse class the application immediately receives the
event.
I know this is a strange bug and not many people will have
this problem, but I would like to know from someone with knowledge
of the runtime why this could be happening.
Thank you
Tiago Bilou -
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]] -
Non modal PopUpManager blocking mouse events
In our application we have a header, footer and center area. We have a situation where we want to block the header and center area with a popup, but leave the footer area so it can be clicked on. The code works fine and it all looks good, except the mouse events are blocked to the footer. If we slightly resize the window (either with the mouse or programatically) it all "wakes up" and starts working. I have tried all sorts of invalidateDisplayList, validateDisplayList, validateNow, etc. I am throwing this out there to see if anyone else has had this problem and if there is something I am missing. I can't easily share my code, but if I don't get a reply I'll put together a code example to see if I can recreate it. Any ideas are very welcome. Been scratching my head at this one for 3 days now.
I should point out that we are using "false" for the modal flag, just in case anyone was thinking that. It all works fine once it "wakes up" through resizing, but I need to make that happen without the resizing.
And we have tried all sorts of "callLater" behavior in conjuction with the invalidate/validate calls. -
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);
} -
Event case missing mouse events on active-x component
I am using a Treeview and capturing selections in the tree using mouse events (event structure). I have a problem where approx 3 out of 15 mouse events are not actioned by the event structure - has anyone else had this problem or is there any suggestions?
Thanks.Could you post a copy of your code that demonstates this?
I have experimented with this control and its events.
We may be able to help if we have soething to look at.
Ben
Ben Rayner
I am currently active on.. MainStream Preppers
Rayner's Ridge is under construction -
Finding Screen Location of the Cursor without a Mouse Event
How can I find the absolute screen location of the mouse cursor if I do not have a mouse event? I have an application where I need to warp the location of the mouse cursor using the robot class and would like to return the mouse cursor to its original location once I'm done.
I had similar problem and asked in the forums a while back, basically what I did was to set the mouse to a "Start" position and go from there.
I know this will not get it back to your current location.
Maybe you are looking for
-
Trouble printing to a HP PSC750 All-in-One Printer
I have a HP PSC750 all in one printer and it seems to work only on occasion. Every so often though when I boot up and try to print something the print queue says the following: GenericClass: waiting for device If I unplug then plug the USB cable, wai
-
This question will seem redundant, but I haven't found a question like it in the forum, nor a question that has been answered that comes close to it. I just switched to a Mac over a month ago. I installed a second internal drive for video capturing.
-
I have a problem with Safari on my iPhone 6 where Safari freezes, just cannot move the page up or down. After a while it works ok, then moments later freezes. This repeats over & over. If you keep page constantly moving it does not freeze. I thoug
-
Package does not exist even though I set classpath right!
Hi, my JSP got an error message saying "Package does not exist" at line <% import ="org.jfreechart.*"%> And I have put the myjar.jar file containing the above classes into blabla\WEB-INF\classes,(where blabla is my current working directory) and set
-
History Documents, Change Documents and Potential documents in PGS
What are History Documents, Cleared documents, Change Documents and Potential documents in PGS. I need to retrieve history documents from tables BSIK, VBKPF and RBKP. Which fields are considered as History documents from these tables? How to retrieve