Generate an event from another event

Hello,
What im trying to achieve is once a user presses the enter key in a Text Area, it generates another event which is 'pressing a button' without actually physically doing it.
private JButton btn = new jButton("Submit");
private void msg_taKeyReleased(java.awt.event.KeyEvent evt) {                                  
    if(evt.getKeyCode() == KeyEvent.VK_ENTER){
       // generate event that clicks button without doing it physically
} Does anybody know how to do this?
Thanks

I would use key binding: [http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html]
Demo:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class KeyboardBindingExample {
  public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable(){
            public void run() {
                new KeyboardBindingExample().launch();
    private Action click = new AbstractAction("Submit") {
        public void actionPerformed(ActionEvent evt) {
            System.out.println("click!");
    void launch() {
        JTextArea text = new JTextArea(20,60);
        JButton submit = new JButton(click);
        JPanel south = new JPanel();
        south.add(submit);
        InputMap im = text.getInputMap();
        ActionMap am = text.getActionMap();
        Object key = click.getValue(Action.NAME);
        im.put(KeyStroke.getKeyStroke("ENTER"), key);
        am.put(key, click);
        JFrame f = new JFrame("KeyboardBindingExample");
        Container cp = f.getContentPane();
        cp.add(new JScrollPane(text), BorderLayout.CENTER);
        cp.add(south, BorderLayout.SOUTH);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
}

Similar Messages

  • Generate MSDS document from another system

    Dear All,
    We have one EHS system (HQ) with all the report templates & variants for MSDS document in place.
    Now we're going to implement roll out EHS in another server (country).
    The MSDS report must be control and same with the one in the HQ. 
    But we don't want to manually maintain the report template & variant in the country server but read it from the HQ system instead.
    Is it possible to do this?
    Or any better idea to achieve this?
    Thanks.

    Hello Peer
    assuming you would like to use system B to use "report shipping" functionalities you need to consider these topics:
    1:) first you must distribute your substance (REAL_SUB) using SUBMAS (ALE)
    2.) second you must distribute PHRASMAS (ALE) (you need phrases to prepare accompanying leter)
    3.) You must distribute the materials from REAL_SUB to B
    4.) you must distribute the Business partner information from A to B
    5.) You must link WWI servers on system B
    6.) You must make available corresponding GENVARs manually ! (if you do not change the number of GENVARs this need ot be done only once) and you must prepare report symbols (chapter 1 !)
    7.) You must prepare the "accompanying" letter in system B
    PLease refer to SAP EHS documentation (how to perform ALE transfer)
    As explained: it is very important and critical that the EHS customizing of A and B must be the same and you need a DMS/DVS or Archive in system, B as well !
    Furthermore you must prepare the whole EHS customizing to do the report shipping topic; schedule jobs (report shipping) , assign printers etc. etc. prepare access concepts (so that e.g.  cg50/cg54 can be used)
    If you have performed the necessary set up in most cases keep this in mind: you must actively mark a substance (REAL_SUB) as ALE relevant. There is to my knowledge no automatism. Therefore if new REAL_SUBs are generated with materials having MSDS which need to be distributed from system A to B then you must perform this activity manually.
    In any case: the set up described above is possible and stable. You can use the ALE( there are some Exits there) to make sure that only MSDS which are valid in e.g. FR must be distributed and not all MSDS etc.
    With best regards
    C.B.
    Edited by: Christoph Bergemann on Sep 15, 2011 4:47 PM
    Edited by: Christoph Bergemann on Sep 15, 2011 4:47 PM
    Edited by: Christoph Bergemann on Sep 15, 2011 4:48 PM
    Edited by: Christoph Bergemann on Sep 15, 2011 4:48 PM
    Edited by: Christoph Bergemann on Sep 15, 2011 4:49 PM
    Edited by: Christoph Bergemann on Sep 15, 2011 4:49 PM
    Edited by: Christoph Bergemann on Sep 15, 2011 4:50 PM

  • Generating one sheet from another.

    I am using iWork’09 and am wondering if I can do the following. I would like to create a spreadsheet of various items related to all projects. I would then like to create separate spreadsheets/tables based on the data in one row of spreadsheet #1. The selected data from spreadsheet #1 would be used as headings this is us spreadsheet #2.
    Hopefully, this will make what I want to do clear. When a project comes in, it is logged in the with, for instance, project Number, company name, location, contact, etc. I then make a worksheet for each project entry using the same information as a heading for the sheet. This looks like a duplicate a lot of work each time. Is there any way to generate a second/work sheet for each project log entry?

    Larry,
    You should be able to use LOOKUP functions to access data in your master table for use in your specific project tables. After designing a Project Table on a separate Sheet, you can save it and make a copy of it for each new project.
    Jerry

  • Causing an event in one VI when called from another

    Hi All
    I wonder if anyone could give me some advice on this. I have a VI, which displays the value of a text control, as a ‘value change’ event using an indicator. If I run this, having checked the ‘update will typing’ parameter for the control, the VI runs as expected and the indicator displays what I type. If I call the VI by reference from another and pass a string to the text control using the Set Control Value [Variant] method, the indicator remains blank, even though I can see the text control is being updated. I’m guessing this is because the event structure is expecting a user generated event which is no longer occurring. Is there any way to re-configure the code so that a value passed in this way, would be seen as an event? I've tried to get some idea from the Labview examples but not being too familiar with the way events work, I'm struggling to make sense of it. (I’m using Labview 7.1)
    Thanks
    Bruce

    knight2 wrote:
    Thanks tbob & Christian.
    Can I just check this? I need to create a new control or indicator in the main VI and create a reference to it. This would then be passed to the subvi and I’m assuming, wired to the Value (signaling) property? If not, where should it go? I'm not too clear on this bit.
    That said, I currently call the subvi from main, by reference. This was because I needed the subvi front panel to be visible before sending text to it. As I’m not passing any values via the connector pane, can the control/indicator reference still be passed?
    Thanks
    Bruce
    Yes, your first paragraph is correct.  Pass the ref to the subvi and use Value(Sgnl) property node in the subvi.  This causes an event for the control, and since it is a reference, the event gets carried to the source of the reference, which is in Main.
    To pass control references (or any object) to a subvi that is called by reference, you can use the Call by Reference method as shown in the attached Main vi.  This allows you to pass items into and out of the subvi called by reference.  If you use the standard way and use GetControlValue and SetControlValue, I don't think you can cause an event in Main by changing a value in the subvi.  If you use the method in my vi, you can use the Value(Sgnl) property in the subvi to cause an event in the Main vi.  This is the only way I know how to send events from a subvi to the main.
    Download the subvi first and put it in some directory.  Then download the main and put it in the same directory as the subvi.  Then when you open Main, it should find the subvi.
    - tbob
    Inventor of the WORM Global
    Attachments:
    MainVI_Ref.vi ‏14 KB
    SubVI_Ref.vi ‏11 KB

  • Problem with Generating SNMP traps from Windows Events

    Hi Supporter, 
    I configured some events to be translated to traps using evntwin for Service Control Manager and Local Session Manager events. But I just got traps from Service Control Manager event. There is no Local Session Manager events are generated. I checked
    with Event Viewer that events are created. Do you have any idea to fix my problem?
    Thank you!
    Here is my config file from evntwin:
    #pragma add "System" "Microsoft-Windows-TerminalServices-LocalSessionManager" 2952790037 1 0
    #pragma add "System" "Microsoft-Windows-TerminalServices-LocalSessionManager" 2952790039 1 0
    #pragma add "System" "Microsoft-Windows-TerminalServices-LocalSessionManager" 2952790040 1 0
    #pragma add "System" "Microsoft-Windows-TerminalServices-LocalSessionManager" 2952790041 1 0
    #pragma add "System" "Service Control Manager" 1073748864 1 0

    #pragma ADD<EventLogFile> <EventSource> <EventID> [<Count> [<Period>]]
    The parameter EventSource specifies the application that generates the event.
    those maybe helpful...
    http://www.questiondriven.com/2012/03/08/windows-server-20032008-event-log-snmp-traps/
    http://www.networkcircus.com/articles/20050715.html
    Best,
    Howtodo

  • Call event from another event

    I have a button where i need to call one event from another... does anyone have any ideas on what the syntax would be?
    public class PushButton extends Button
    public PushButton()
    * Mouse Pressed Event
    this.addEventHandler(MouseEvent.MOUSE_PRESSED,
    new EventHandler<MouseEvent>() {
    @Override
    public void handle(MouseEvent e) {
    System.out.println("MousePressed");
    * Mouse Released Event
    this.addEventHandler(MouseEvent.MOUSE_RELEASED,
    new EventHandler<MouseEvent>() {
    @Override
    public void handle(MouseEvent e) {
    System.out.println("MouseReleased");
              *// Make a call to the mouse pressed event????*
    }

    Hi,
    As per your requirement, i hope the below code should work. :)
    public class PushButton extends Button
         public PushButton()
               * Mouse Pressed Event
              final EventHandler<MouseEvent> mousePressedEvent = new EventHandler<MouseEvent>() {
                   @Override
                   public void handle(MouseEvent e) {
                        System.out.println("MousePressed");
              this.addEventHandler(MouseEvent.MOUSE_PRESSED, mousePressedEvent);
               * Mouse Released Event
              this.addEventHandler(MouseEvent.MOUSE_RELEASED,
                        new EventHandler<MouseEvent>() {
                   @Override
                   public void handle(MouseEvent e) {
                        System.out.println("MouseReleased");
                        // Make a call to the mouse pressed event
                        mousePressedEvent.handle(e);
    }Happy Coding !! :)
    Regards,
    Sai Pradeep Dandem.

  • Raise a button's click event handler from another event handler

    hi,
    I am trying to raise a button's click event from another button's click event.
    Automation gives a runtime error. I checked out some other forums for answers but they dont work when called from another event handler.
    Console.WriteLine(gestureData.name);
    if (s==b2) ;
    //raise button2's click event
    private void b2_Click(object sender, RoutedEventArgs e)
    MessageBox.Show("I am button2");
    private void b3_Click(object sender, RoutedEventArgs e)
    MessageBox.Show("I am button3");
    Any help will be appreciated.
    Thanks,
    Shaleen
    TheHexLord

    Hi Andy,
    I tried to implement your suggestion.
    What I am trying to do is, say there is a label whose content property needs to be updated every time a button b1 is clicked. When the button is clicked , it check if a condition is met and depending upon that condition it updates the content of the label
    . Say , if the text entered is "add" and the button is clicked and the label's content is set to "add", if the text entered is "sub" and then the button is clicked, the label's content is set to "sub".
    I understand that there is no need to fire up different methods for this as this can be done by checking for conditions in the same button click event but it seems that updating the UI is not happening. I get an error saying.:
    A first chance exception of type 'System.InvalidOperationException' occurred in WindowsBase.dll
    The program '[6660] WpfApplication8.vshost.exe: Program Trace' has exited with code 0 (0x0).
    The program '[6660] WpfApplication8.vshost.exe: Managed (v4.0.30319)' has exited with code -1073741819 (0xc0000005) 'Access violation'.
    this goes away when I remove the Label.Content="add" or Label.Content= "sub";
    I think the label's content property does not update dynamically.
    Thanks
    TheHexLord

  • How to remove an auto generated ActionPreformed Event from Netbeans?

    Hi,
    How do I remove an auto generated ActionPreformed Event from my code? I accidentally created one and want to remove it. I tried to right click on the event and refactor/delete all the dependencies in the source but it wouldn't let me remove it. There shouldn't be any DEPENDENCIES it was just created.
    Thanks,
    V$H3r

    NetBeans | Help | Help Contents | Java Applications | Building Java GUIs | Designing Java GUIs | Managing Component Events | Removing Event Handlers:
    1. In the Inspector window, select the component whose event handler you want to remove.
    2. Click the Events button at the top of the Properties window.
    3. Select the event in the property sheet and click the ellipsis (...) button to display the Handlers dialog box. Alternately, you can simply delete the name of the handler you want to remove in the Properties window.
    4. In the Handlers dialog box, select the handler to remove from the list and click Remove.
    When you remove an event handler, the corresponding code block is also deleted. If more than one handler uses the same name and same block of code, deleting a single reference to the code does not delete the code itself. Only deleting all references will delete the corresponding code block, and a confirmation dialog box is displayed first.

  • In one of my iPhoto 'event' files other photos from another event seem to have doubled up over a different photo!!!!!

    In one of my iPhoto 'event' files  (named Thailand) other photos from another event (named Filey) seem to have doubled in the Thailand event, but when I click on the image  (from filey) it shows the Thailand image!!!!!
    I hope this is understandable
    Thank you
    Sheena

    What is your iPhoto version and your MacOS X version on your MacBook Pro? It looks like the thumbnails of your photos were wrong. Make a backup copy of your iPhoto library and try to rebuild the thumbnails. in iPhoto '11 try this:
    Launch iPhoto with the key combination⌥⌘  (alt/option-command) held down and select "rebuild thumbnails" from the panel.

  • Generate action events from objects

    Is there a way to have an object generate an event for a component just as if that component had received the event from the user?
    i.e. I have a JPanel that has a MouseListener added to it. Can I have a separate object (or actually just having the JPanel do it itself would be fine) create a MouseEvent and fire it to the MouseListener so that the code in the MouseAdapter's MouseClicked method gets run?
    Thanks,
    Matt

    I think Component.dispatchEvent() is what you are looking for.

  • Generating LabVIEW events via ActiveX

    I have a Labview 2010 Vi compiled to an EXE with ActiveX server enabled.
    The VI has a single control that is a latched boolean control that is used in an Event Handler.
    When I toggle this control, remotely, via an ActiveX client, the control changes state, but does not generate an event. (non-signaled).
    I can understand this behavior if the control was not a latched control, but I would have thought that the latched control would automatically generate an event, since it doesn't make a distinction between "value" and "value (signaled)".
    Other than monitoring/polling the control status and when it changes using a Value (Signal) local variable, is there a way to generate an Event, in a LabVIEW EXE, via ActiveX?  Or is there another, more appropriate way to accomplish this.  I'm trying to remotely run an program from another program through an activeX interface.   I suppose if every control had a unique message and I had a message handler loop, then I could just use the ActiveX control to insert the appropriate message into the Queue, but this is an existing application and would take a fair effort to set that up.

    What if you tried dynamically registering the event? You could create a reference to the boolean and use the Register for Events VI. Then, wire this event into the dynamic event terminal of the event structure (right click the border and say "Show Dynamic Event Terminals").  I don't have an ActiveX program to call into LabVIEW with, so I'm not sure if this will be any different than what you're doing now, but it's something easy to try.  Perhaps you could post you ActiveX code and LabVIEW code or a modified version of both illustrating what you're mentioning?

  • How can I detect an external trigger and then generate an event or occurance

    I have a PXIe-1065 chassis with a PXIe8030 controller, PXI-6653 timing module, PXI-6542 Digital IO, and PXI-6259 DAQ board, running LabView 8.5. I need to detect a trigger (100 ns TTL pulse) from an external device then start a process on a GPIB device. Is there a way for me to detect this trigger and then generate an event, or an occurance ? Can I do this without polling a device? Can any of this hardware generate an interrupt that LabView can detect?

    My screenshot was only an example how you can approach the issue. I wasnt saying that you should try it with AI....
    Just take a closer look into the DAQmx Events and you will discover something like this:
    hope this helps,
    NorbertMessage Edited by Norbert B on 10-05-2007 02:35 AM
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.
    Attachments:
    DAQmxEvent.PNG ‏11 KB

  • Programati​cally change control focus to generate and Event.....​.

    I'm adding some user enhancement (anti-screw-it-up functions) to insure the desired process is executed.
    Primary question:  If I have an event that is handles by a value change in a text control, (event happens when you hit Enter or exit control with mouse) will the event also occur if you exit the control by programatically changing the focus to another control ?
    I'm going to try and set up a temp vi to test this but wanted to see if anyone had tried this and if it works or not.  My other option is to set up multiple event cases but I was hoping to use a single case to handle everything.
    A few details,  I have a test system that tests a product automatically when the product is placed in a cradle and the cradle is moved into position and activates a prox sensor.  At end of test, system waits for prox sensor to de-activate before resetting the system.
    If a unit fails, there are rework options and the unit can be retested.  When it fails, a label prints defining the failure modes and provides a failing serial number.  When the unit is retested, the failing serial number is entered into a text control. I want the re-test sequence (queued up in the Event) to occur when either 1, a failing serial number is entered or two a button is pressed (with mouse)  I'm pretty sure pressing a button would in turn automatically create the text control change event so my button can probably be a dummy button just for appearances.
    Where the hole is if the user enters a failed serial # and doesn't exit the control and then engages a pump to start the test.  I can use a 'Empty Path/String' function but the control will continue to show empty as if nothing was entered until the Enter key is pressed or the mouse is used to exit the control.
    If I can generate the event by changing the focus, then it will insure that if a failing s/n is entered, the re-test sequence occurs and if nothing exists in that field, it performs a first time test.
    A little long winded for sure but any thoughts are appreciated.
    Can't really post any simple code as this feature is in my top level vi and I have a really big app that doesn't warrant uploading.
    Doug
    Doug
    "My only wish is that I am capable of learning each and every day until my last breath."
    Solved!
    Go to Solution.

    Actually, changing the focus alone did not trigger the event but I was able to then utilize the Empty Path/String function to drive a Value(Signaling) node for the control.
    Doug
    "My only wish is that I am capable of learning each and every day until my last breath."
    Attachments:
    Event_Structure_Trials.vi ‏29 KB

  • Generate an event programically

    Greetings everyone!
    I am trying to create a 'splash' screen that is displayed during httpconnection calls so that the user is informed of the status of the connection (ie connecting, posting, receiving etc). I created a form that implements the runnable method so that i can call httpconnection on a seperate thread. Once the run method is called i clear up all elements in the form, display a message and proceed with the http business.
    The only problem is that the only way i found that i can move on to either a) the next form (if the data return is OK) or b) to the same form that made the call (if there is some error) is by inserting a command in the form after the connection is finalized, thus allowing the user to click his way out of the info screen.
    I was wondering if there is some way for an event to be generated automatically once the connection is finalized, which could be treated by the commandlistener, thus allowing me to avoid any further user interaction.
    thanks in advance!
    best,
    marcos

    thanks for the help guys, i apologize if i did no make myself clear, but i think i can try out the call back method you guys suggested.
    my problem was the following, i would:
    1) generate an event that would call my connection thread
    2) the main thread would then finish
    3) the connection thread would get started
    4) the form would be cleared up and a new message (ie connecting etc) would be appended
    5) the connection thread would finish
    i guess what i forgot to explain is that at this point i was hoping i could 'generate' an event so that i could call back my CommandHandler class (which implements commandlistener). i could probably change the code around in all my forms so that the result from the connection gets treated in the same thread that calls the connection. but by what i understood i could call commandlistener(command c, displayable d) directly, which would result in an event being generated and thus i could stick to my current logic whereby all events get treated in the main thread.
    so the next step would be
    6) i save the result of my connection
    7) i call back my commandhandler
    8) i treat the result of the connection and move on to the next Form by calling display.setDisplay...
    is that correct or did i misinterpret your answer?
    thanks again for the all the help guys, much appreciated!

  • Generate an Event based on Counter Trigger

    Hello,
    I have the following part that is already working: a counter (used for period measurement) which is triggered by a digital input. After that I'm reading the data and I'm puting them in a Queue. Here I get an error. The Enqueue Element Vi is providing an error. (Error 1, something with a @  character that is illegal). I've notice that if I disable the trigger for the counter I don't get the error. I'm thinking that this is cause by the delay between the moment in which the Enqueue Block tries to enqueue and the moment in which the counter provides something to its ouptut.
    What I want to do is to Generate an Event based on the Counter Trigger Signal and to put all the reading and Enqueue part in an Event Structure. I've tried to do that using an Export Signal - Property Node, but I didn't manage to make it work.
    If you have any solution for this (with or without events -  I just want to get rid of that error) please let me know.
    PS: I have Labview 8.5.1 and the USB-6210.
    Thanks,
    LostInHelp

    Hello Mike,
    Thanks for your replay.
    I've attached two vi files. In one you can find how I've tried to generate an event based on the counter trigger (test.vi).
    The second one (test1.vi) is the vi where I get the queue error. I've deleted from the second vi the part where the data are dequeue and handled.
    Thanks
    LostInHelp
    Attachments:
    test41.vi ‏50 KB
    test110.vi ‏35 KB

  • Generate dynamic event of producer loop in multiple consumer loop

    I have one producer loop which used event case to interface with FP controls and 5 consumer loops
    If I have to use the fifth consumer loop to generate dynamic event which send to event case in produer loop. 
    I have to wire register event with dynamic event terminal in producer loop . Also I need to wire user event to consumer loop (at the bottom of screen window) which is far away from producer loop. It is hard to wire them. 
    Is there any other method to let many consumer loop to communicate with one producer loop through dynamic event (the same user event)?

    I like to use an Action Engine to hold control my Event Reference.  Then anybody can send the event commands.
    You may also want to look at the VIs I recently submitted for OpenG here.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

Maybe you are looking for

  • Distorted video after export

    Hello. I have exported a video using AVCHD mp4 format. 25 fps. 1280x720 px. Aspect "Square Pixels(1.0) 1:1. Both tried CBR and VBR. With target bitrate 1.6 Mbps. See the attached pic for settings. And also see the distorted video problem I have. Can

  • LSO 600 Configuration - Central Storage Location for XSLT Files

    Hi, We are implementing LSO 600 with enhancement pack 2 and I am haiving trouble figuring out what do do with the configuration steps Enter Address of Central Storage Location for XSLT Files and Enter Address of Central Storage Location for Templates

  • Adobe OnLocation won't run after updating to Mavericks

    I use Adobe OnLocation, the reason I bought a Mac, and after upgrading to Mavericks the system hangs everytime I start OnLocation.  I have reinstalled the program numerous times.  After a visit to the "Genius Bar" I decided to wipe the drive clean an

  • Posting in Frameset

    I am in desperate need of wisdom and insight. I have a simple Captivate simulation in which users tab from field to field and enter data. It works fine when we run it locally, but when we post it to our LMS (which displays programs in a frameset), th

  • HP Officejet All In One 7310x1

    I have a new G5 and am a new Mac user having finally seen the light and switched from windows. I have a HP 7310xi that I am using over a home network. The network settings are accurately applied and the printer is responding. However, the page is not