Lost focus event litesner vs Mouse event litesner
hi all, I having problem with JSwing components in window environment. Below is the phenomenon.
1.) create a JFrame.
2.) drag JTextField and JButton put onto the JFrame.
3.) Add FocusLostEvent into the JTextField lostFocusListener.
4.) At the event code this:-
if (lostFocusEvent.isTemparory())
return;
javax.swing.JOptionPane dialog = new javax.swing.JOptionPane(
"Error", javax.swing.JOptionPane.INFORMATION_MESSAGE, javax.swing.JOptionPane.DEFAULT_OPTION
dialog.createDialog(this,reslabels.getString("Error_Input_Error") ).show();
5.) run the program.
6.) focus your cursor in the JTextField. Next, use your mouse click on the JButton.
7.) You should see this. Message Dialog pop-up.
8.) Well, don't click the OK/NO button from the Dialog box.
9.) Now, point your mouse to the button and see what will happen to your JButton.
10.) The JButton is Armed.
By right the Jbutton should not be armed because the focus should has gained by the dialog box.
After all, we try create the same program using MS VC++. It does not have this problem because logical enough the focus has obtained by the dialog Box. Jbutton should not perform any action. Otherwise, it is some kind of degrade the dialog show modal.
If you has above experience and solutions, please do share with me. Thanks.
regards,
elvis
scjp
WWWizard, It doesn't work. below is the source code. Please take a look and compile it and run at your window environment.
1.) Focus you cursor at the JTextField.
2.) Once ready, click on the JButton. You should see the Dialog msg pop up. Do not close the Dialog at this moment.
3.) Move your mouse pointer to the JButton that you just clicked. Why the JButton is Armed? It shouldn't happen in window environment.
========start==========
package test.lib;
import java.awt.*;
import javax.swing.*;
* This type was generated by a SmartGuide.
public class TestCustLib extends JFrame {
private JPanel ivjJFrameContentPane = null;
private JPanel ivjTestCustLibPane = null;
IvjEventHandler ivjEventHandler = new IvjEventHandler();
private JTextField ivjJTextField1 = null;
private JButton ivjJButton1 = null;
class IvjEventHandler implements java.awt.event.FocusListener {
public void focusGained(java.awt.event.FocusEvent e) {};
public void focusLost(java.awt.event.FocusEvent e) {
if (e.getSource() == TestCustLib.this.getJTextField1())
connEtoC1(e);
private lib.ButCus ivjaa = null;
* TestCustLib constructor comment.
public TestCustLib() {
super();
initialize();
* TestCustLib constructor comment.
* @param title java.lang.String
public TestCustLib(String title) {
super(title);
* connEtoC1: (JTextField1.focus.focusLost(java.awt.event.FocusEvent) --> TestCustLib.jTextField1_FocusLost(Ljava.awt.event.FocusEvent;)V)
* @param arg1 java.awt.event.FocusEvent
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void connEtoC1(java.awt.event.FocusEvent arg1) {
try {
// user code begin {1}
// user code end
this.jTextField1_FocusLost(arg1);
// user code begin {2}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
* Return the aa property value.
* @return lib.ButCus
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private lib.ButCus getaa() {
if (ivjaa == null) {
try {
ivjaa = new lib.ButCus();
ivjaa.setName("aa");
ivjaa.setLocation(243, 160);
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
return ivjaa;
* Return the JButton1 property value.
* @return javax.swing.JButton
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JButton getJButton1() {
if (ivjJButton1 == null) {
try {
ivjJButton1 = new javax.swing.JButton();
ivjJButton1.setName("JButton1");
ivjJButton1.setText("JButton1");
ivjJButton1.setBounds(60, 146, 85, 25);
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
return ivjJButton1;
* Return the JFrameContentPane property value.
* @return javax.swing.JPanel
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JPanel getJFrameContentPane() {
if (ivjJFrameContentPane == null) {
try {
ivjJFrameContentPane = new javax.swing.JPanel();
ivjJFrameContentPane.setName("JFrameContentPane");
ivjJFrameContentPane.setLayout(new java.awt.BorderLayout());
getJFrameContentPane().add(getTestCustLibPane(), "Center");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
return ivjJFrameContentPane;
* Return the JTextField1 property value.
* @return javax.swing.JTextField
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JTextField getJTextField1() {
if (ivjJTextField1 == null) {
try {
ivjJTextField1 = new javax.swing.JTextField();
ivjJTextField1.setName("JTextField1");
ivjJTextField1.setBounds(54, 64, 126, 20);
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
return ivjJTextField1;
* Return the TestCustLibPane property value.
* @return javax.swing.JPanel
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JPanel getTestCustLibPane() {
if (ivjTestCustLibPane == null) {
try {
ivjTestCustLibPane = new javax.swing.JPanel();
ivjTestCustLibPane.setName("TestCustLibPane");
ivjTestCustLibPane.setLayout(null);
getTestCustLibPane().add(getJTextField1(), getJTextField1().getName());
getTestCustLibPane().add(getJButton1(), getJButton1().getName());
getTestCustLibPane().add(getaa(), getaa().getName());
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
return ivjTestCustLibPane;
* Called whenever the part throws an exception.
* @param exception java.lang.Throwable
private void handleException(java.lang.Throwable exception) {
/* Uncomment the following lines to print uncaught exceptions to stdout */
// System.out.println("--------- UNCAUGHT EXCEPTION ---------");
// exception.printStackTrace(System.out);
* Initializes connections
* @exception java.lang.Exception The exception description.
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initConnections() throws java.lang.Exception {
// user code begin {1}
// user code end
getJTextField1().addFocusListener(ivjEventHandler);
* Initialize the class.
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initialize() {
try {
// user code begin {1}
// user code end
setName("TestCustLib");
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setSize(460, 300);
setTitle("TestCustLib");
setContentPane(getJFrameContentPane());
initConnections();
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
// user code begin {2}
// user code end
* Comment
public void jTextField1_FocusLost(java.awt.event.FocusEvent focusEvent) {
if (focusEvent.isTemporary())
return;
//int li_Ok = javax.swing.JOptionPane.showConfirmDialog(this,"Don\'t click me!!! Move your mouse to JButton1.","Oops", javax.swing.JOptionPane.DEFAULT_OPTION,javax.swing.JOptionPane.QUESTION_MESSAGE);
javax.swing.JOptionPane.showMessageDialog(this,"Don\'t click me!!! Move your mouse to JButton1.");
//javax.swing.JOptionPane.showInputDialog(this,"Don\'t click me!!! Move your mouse to JButton1.");
//javax.swing.JOptionPane.showOptionDialog(this,"Don\'t click me!!! Move your mouse to JButton1.","Don\'t click me!!! Move your mouse to JButton1.",javax.swing.JOptionPane.YES_NO_OPTION,javax.swing.JOptionPane.WARNING_MESSAGE,null,null,null);
//javax.swing.JOptionPane.showInternalMessageDialog(null,"ta");
return;
* Starts the application.
* @param args an array of command-line arguments
public static void main(java.lang.String[] args) {
try {
/* Set native look and feel */
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
/* Create the frame */
TestCustLib aTestCustLib = new TestCustLib();
/* Add a windowListener for the windowClosedEvent */
aTestCustLib.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosed(java.awt.event.WindowEvent e) {
System.exit(0);
aTestCustLib.setVisible(true);
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of TestCustLib");
exception.printStackTrace(System.out);
========end==========
Similar Messages
-
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 -
Mouse events during Thread.sleep
hi.
I have an applet .
I have a alghoritm simulator.
Everytime I find a solution I call the method Thread.sleep .
I want to pause the application and I create a JToggleButton Pause .
When I press the Pause during sleep mouse event are managed at the end of alghoritm.
How can I manage mouse events during sleep?All UI events (such as mouse events) occur on the event dispatch thread (EDT).
That means if you sleep on the EDT, you lock up the UI. For this reason, you shouldn't be sleeping on the EDT.
I'm not sure what your sleep is trying to do but you need to manage your threads a little more carefully. For instance, any time consuming process which is invoked as a result of a UI event needs to be fired on a new thread to prevent the UI freezing. The fun starts when you have to update the UI as a result of that process, because you should then hook back onto the EDT to avoid the risk of deadlock.
Some utility classes are provided, such as SwingUtilities, and other example code is provided on Sun's site, such as SwingWorker - but if you do much UI work you'll probably end up with your own core set of threading tools and so on to make life easier. -
Hello,
I just wanted to ask if there is an easy way to obtain mouse events (such as mouse down, scroll wheel etc.) within an event structure (as it is possible with the keyboard). Now I'm using a while loop to continuously acquire the mouse state. It would be much more convenient however if I could use events to detect the mouse state.
Thanks a lot in advance for any help!WernerGobel wrote:
Hi Nishant,
unfortunately, there is no option for mouse events under <this vi>, only keyboard. Do I have to install an additional package?
Regarding my application:
With the mouse scroll-wheel I want to interactively scale analog output data, i.e.: when I scroll in one direction data for an analog output task is multiplied by a specific value and given to the AO write vi (upscaled), when I scroll in the other direction the data is divided (downscaled).
When I keep the right mouse button pressed and the mouse is moved, an offset is being added to the data corresponding to the length of the mouse move (with the right button pressed).
When the left button is pressed and the mouse is moved, a rotation operation is being done on the data.
I have this implemented using the initialize mouse vis within a continuously running while loop, now I'm rewriting our application and I just realized that it would be very nice, if I could use mouse events just the same as keaboard events can be monitored within an event structure.
Hope I was clear and thank you very much for any help!
Look for pane (or control events) they have mouse events.
I haven't tested the scroll wheel, looking at your code I would register for the mouse move event as soon as a mouse down event is happening as I have shown in my nugget.
Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas
LabVIEW, programming like it should be! -
HTML/JS: Capturing mouse events while Air is out of focus
Hi,
I've been trying to determine if it is possible to receive mouse events (like MOUSE_WHEEL) if the Air window does not currently have focus. I'd like my application to support the mouse wheel for scrolling while the cursor is over the application, without requiring the user to click the application and gain focus. My application uses JavaScript to scroll an unordered list within a DIV set to overflow:hidden (to prevent the native scrollbar from appearing).
Thanks for your help!
AndrewI doubt that AIR would pick up events fired while not having focus. Perhaps you could fake it by creating an AIR project that runs "fullscreen", but has a smaller active window. Anywhere your mouse went it would still capture the scrolling event, but you could conditionalize it so that it only worked in certain areas.
-
ALV Grid Handle Edit Event (Lost Focus)
Hi all,
I have some problems with the ALV Grid.
Target:
I have an ALV Grid with editable Column. If the user insert, update or delete the content of the column and leave the column (column lost focus) i'd like to do somthing - this means I need a event for this action. Can anybody help me to solve this problem?
Thanks StefanUse Event data_changed and data_changed_finished of the cl_gui_alv_grid.Then all you have to do is registering your event to the ALV and fill the methods with what you want to do.In ALV Grid, There is no event to capture the lost focus of a column if you don't modify it.
CLASS lcl_event_receiver DEFINITION.
METHODS:
*$ Check the change
handle_data_changed FOR EVENT data_changed
OF cl_gui_alv_grid
IMPORTING er_data_changed
e_ucomm
e_onf4
e_onf4_before
e_onf4_after,
handle_data_changed_finished
FOR EVENT data_changed_finished
OF cl_gui_alv_grid
IMPORTING e_modified
et_good_cells
sender,
ENDCLASS. "LCL_EVENT_RECEIVER DEFINITION -
How to catch cell lost focuse event of matrix
Dear all
can you tell me how to catch the cell lost fouc event of matrix.
i want to check the value is entered the that cell, which is not greter than the extising value..
thanks in advance......Hi
For that you can use either validate or lost focus event
Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent
' BubbleEvent sets the behavior of SAP Business One.
' False means that the application will not continue processing this event.
' Validate event
If (pVal.FormType = 133) And (pVal.ItemUID = 38) And (pVal.ColUID = 1) And _
(pVal.EventType = SAPbouiCOM.BoEventTypes.et_VALIDATE) Then
If (pVal.Before_Action) Then
'write your code
End If
End If
'Lost focus event
If (pVal.FormType = 133) And (pVal.ItemUID = 38) And (pVal.ColUID = 1) And _
(pVal.EventType = SAPbouiCOM.BoEventTypes.et_LOST_FOCUS) Then
If (pVal.Before_Action) Then
'write your code
End If
End If
End Sub
Hope this helps
Regards
Arun -
InputField's Lost Focus Event?
Dear All,
The input field does not seem to support an onLostFocus event.
Is there a work around?
How can the lost focus be detected?
Thanks and regards,
MayureshHi,
As far as i know no work arounds, If you try work arounds it will be too costly in terms of performance.
Only option is users mercy and handle it in onEnter
Regards
Ayyapparaj -
ItemEvent - Event Type - Lost Focus Event
Hi,
Just want to ask whether what eventtype i should use for this situation.
I want to do something when the itemcode in marketing document been key in correctly.
At first i use the lost focus event. but i after i find that the lost focus event will keep on check where the itemcode is key in correct or not when it lost focus. Actually I want this effect but this will caurse the scoll bar cannot move.
For example. when i put the cursor in item code column. then i go and scoll the bar. it will keep on fire the lost focus event make me cannot scoll the bar or the matrix become wrong disappeared. Any idea on it?
Sorry i maybe not explain well. But i don know how to explain on it. Hope you all understand what I mean la.
Regards
WongHi Wong
1st Try to split them
2nd use beforeAction=true and ItemChanged = True
If you have 2005/2007 version on the item code et_choose_from_list and validate are similar...
If pVal.ItemUID = "38" then
if pVal.ColUID = "1" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_VALIDATE then
if pVal.ItemChanged=True And pVal.BeforeAction = True then
**** do something
end if
end if
end if
or
If pVal.ItemUID = "38" then
if pVal.ColUID = "1" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_choose_from_list then
if pVal.BeforeAction = True then
**** do something
end if
end if
end if
Regards,
J. -
Hi all,
I have written some code in lost focus event.But the lost focus event is not firing.i didn't set any filters.please help me to sollve my problem.
Regards
MohanaHi,
try this
If pVal.ItemUid = "Uid" And pVal.EventType = SAPbouiCOM.BoEventTypes.et_LOST_FOCUS And pVal.BeforeAction = False and pval.charpressed=9 Then
end if
'9' is the item which gets fired when tab is pressed
it's better to write keydown if ur using tab
and coming to firing a event i gave the code before._refere to ur previous replie's_ -
Is there something like a lost focus event (like onBlur in JS)?
It is supposed to inherit InteractiveObject events such as flash.events.FocusEvent.FOCUS_OUT ("blur" in JS)
-
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 -
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);
} -
I have this error message on a button that I am trying to
apply this script to:
on(release){
gotoAndPlay("still1");
**Error** Scene=Scene 1, layer=button1, frame=35:Line 1:
Mouse events are permitted only for button instances
on(release){
Total ActionScript Errors: 1 Reported Errors: 1
It is a button, it is on it's own layer, and nothing else is
happening on that layer.
So what is happening here?
Kevinkevin raleigh wrote:
> I have this error message on a button that I am trying
to apply this script to:
>
> on(release){
> gotoAndPlay("still1");
> }
> **Error** Scene=Scene 1, layer=button1, frame=35:Line 1:
Mouse events are
> permitted only for button instances
> on(release){
The action is applied to frame not button, make sure you
select the right thing
before applying your action, sometimes flash loses focus and
accidentally you
can select frame instead. The error actually clearly state
that:
You asing button action to Scene 1, layer named 'button' and
frame 35.
Best Regards
Urami
!!!!!!! Merry Christmas !!!!!!!
Happy New Year
<urami>
If you want to mail me - DO NOT LAUGH AT MY ADDRESS
</urami> -
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.
Maybe you are looking for
-
Office 2013 Click-to-Run Event Logs
Anyone know what the event logs are (Source, Event ID, etc) for Office 2013 Click-to-Run version? Specifically, I'm trying to find out when my installation was last updated (automatic updates are enabled). In general it would also be nice to know wha
-
Need help!!!!!! I've forgotten my security questions. My rescue address is not available anymore. So I can't get the instructions to reset my security questions. <E-mail Edited by Host>
-
OES2 SP3 AFP How to empty AFP log file
Hello All, i find no information how i can empty the AFP log file in /var/log/afptcpd/afptcp.log. It has grown to 1,2 Gigabyte and is very uncomfortable to look for information in this big file. Any ideas ? Thank you Andreas
-
Can you search through text in an InDesign book?
I need to do a find/replace on a certain string of text throughout my book in InDesign (made up of multiple document chapters). Is this possible? Or do I need to open each document individually and do a find/replace? Thanks.
-
Problem in loading analytics page
Hi friends, when i started the BI services in obiee 11g, i didnt see the line as the 'RUNNING MODE' in the command window. Since i can able to see the weblogic and em page but i couldnt able to see the analytics page,as it is saying as "problem loadi