Detect a change in jtextpane

Well, is there an easy way to detect if the user has changed the content in a jtextpane?
Need to know if anything has been alterered so we know if to force a save dialog.
Any hints?

i think you can use the .addKeyListener method to detect a key event (for example the event keyPressed()), in this case you can see if the text has been modified.
Bye!

Similar Messages

  • Detect Note Changes in MIDI Sequencer

    Hi all,
    I’m trying to detect when the MIDI Sequencer changes notes using some kind of a listener to detect when the note changes occur. My example program is able to detect the end of the sequence and I’d like to be able to detect note changes and print a message in a similar way. Here is my example code.
    import javax.swing.*;
    import javax.sound.midi.*;
    public class SequencerTestApplet extends JApplet
        public void init()
            SequencerTest seqTest = new SequencerTest();
            seqTest.play();
            System.out.println("Print from init()");
    class SequencerTest
        Sequencer sequencer=null;
        Sequence seq=null;
        Track track=null;
        public SequencerTest()
            try
            {   sequencer = MidiSystem.getSequencer();
                sequencer.open();
                // detect END OF SEQUENCE
                sequencer.addMetaEventListener(
                    new MetaEventListener()
                    {   public void meta(MetaMessage m)
                        {  if (m.getType() == 47) System.out.println("SEQUENCE FINISHED");
                sequencer.setTempoInBPM(40);
                seq = new Sequence(Sequence.PPQ, 16);
                track = seq.createTrack();
            catch (Exception e) { }
        public void play()
            try
            {    // NOTE 1
                ShortMessage noteOnMsg = new ShortMessage();
                noteOnMsg.setMessage(ShortMessage.NOTE_ON, 0, 60, 93);
                track.add(new MidiEvent(noteOnMsg, 0));
                ShortMessage noteOffMsg = new ShortMessage();
                noteOffMsg.setMessage(ShortMessage.NOTE_OFF, 0, 60, 93);
                track.add(new MidiEvent(noteOffMsg, 16));
                // NOTE 2
                ShortMessage noteOnMsg2 = new ShortMessage();
                noteOnMsg2.setMessage(ShortMessage.NOTE_ON, 0, 68, 93);
                track.add(new MidiEvent(noteOnMsg2, 16));
                ShortMessage noteOffMsg2 = new ShortMessage();
                noteOffMsg2.setMessage(ShortMessage.NOTE_OFF, 0, 68, 93);
                track.add(new MidiEvent(noteOffMsg2, 32));
                sequencer.setSequence(seq);
                sequencer.start();
            catch (Exception e) { }
    }In this program the init() method starts the sequencer through the play() method and then continues on so that the “print from init()” statement is printed from the init() method while the sequencer is still playing. Then after the sequencer is finished, it uses the MetaEventListener to detect the end of the sequence and print the “sequence finished” message. I’d like to be able to make it also detect when the sequence changes notes in a similar way... Start the sequence and move on, but then be able to detect each time a note change occurs and print a message.
    Since I am putting the notes at specific midi ticks (multiples of 16, or “quarter notes”) I could poll the Sequencer using getTickPosition() to see if the Sequencer’s tick position matches a particular multiple of 16. However, the problem with this is it would lock up the program since it would be constantly polling the sequencer and the program wouldn’t be able to do anything else while the Sequencer is playing (and I also have a loop option for the Sequencer so that would lock up the program indefinitely).
    Here’s what I’ve found out and tried so far...
    I read in this [this tutorial|http://java.sun.com/docs/books/tutorial/sound/MIDI-seq-adv.html] on the java sun site (under “Specifying Special Event Listeners”) that The Java Sound API specifies listener interfaces for control change events (for pitch-bend wheel, data slider, etc.) and meta events (for tempo change commands, end-of-track, etc.) but it says nothing about detecting note changes (note on/off). Also in the [EventListener API|http://java.sun.com/j2se/1.3/docs/api/java/util/class-use/EventListener.html] (under javax.sound.midi) it only lists the ControllerEventListener and the MetaEvenListener.
    I also read here that MIDI event listeners listen for the end of the MIDI stream, so again no info about detecting note changes.
    It seems like the sequencer should have some way of sending out messages (in some fashion) when these note changes happen, but I’m not sure how or even if it actually does. I’ve looked and looked and everything seems to be coming back to just these two types of listeners for MIDI so maybe it doesn’t.
    To be sure the MetaEventListener doesn’t detect note changes I changed the MetaMessage from:
    public void meta(MetaMessage m)
    {    if (m.getType() == 47) System.out.println("SEQUENCER FINISHED");
    }to:
    public void meta(MetaMessage m)
    {    System.out.println("" + m.getType());
    }so that it would print out all of the MetaMessages it receives. The only message that printed was “47” which indicates the end of the sequence. So the MetaEventListener doesn’t appear to do what I need it to do.
    I realize this is a rather odd problem and probably not many people have had the need to do something like this, but it never hurts to ask. If anyone has any suggestions on how to solve this problem it would be greatly appreciated.
    Thanks,
    -tkr

    Tekker wrote:
    As another idea, since I can't do it with a listener like I originally wanted to, would adding a separate thread to poll the sequencer and send an interrupt when it matches a particular midi tick be a good route to try? My thinking is this essentially act kind of like a listener by running in the background and reporting back when it changes notes.Yep, that worked! :)
    import javax.swing.*;
    import javax.sound.midi.*;
    public class ThreadTestApplet extends JApplet
         public void init()
              ThreadTest threadTest = new ThreadTest();
              threadTest.play();
              MIDIThread thread = new MIDIThread(threadTest.sequencer);
              thread.start();
              System.out.println("  Print from init() 1");
              try { Thread.sleep(1000); } catch (InterruptedException ie) {}
              System.out.println("  Print from init() 2");
              try { Thread.sleep(1000); } catch (InterruptedException ie) {}
              System.out.println("  Print from init() 3");
              try { Thread.sleep(1000); } catch (InterruptedException ie) {}
              System.out.println("  Print from init() 4");
    class ThreadTest
         Sequencer sequencer=null;
         Sequence seq=null;
         Track track=null;
         public ThreadTest()
              System.out.println("Sequencer Started");
              try
              {     sequencer = MidiSystem.getSequencer();
                   sequencer.open();
                   // detect END OF SEQUENCE
                   sequencer.addMetaEventListener(
                        new MetaEventListener()
                        {  public void meta(MetaMessage m)
                             {     if (m.getType() == 47) System.out.println("SEQUENCER FINISHED");
                   sequencer.setTempoInBPM(40);
                   seq = new Sequence(Sequence.PPQ, 16);
                   track = seq.createTrack();
              catch (Exception e) { }
         public void play()
              try
              {     // NOTE 1
                   ShortMessage noteOnMsg = new ShortMessage();
                   noteOnMsg.setMessage(ShortMessage.NOTE_ON, 0, 60, 93);
                   track.add(new MidiEvent(noteOnMsg, 0));
                   ShortMessage noteOffMsg = new ShortMessage();
                   noteOffMsg.setMessage(ShortMessage.NOTE_OFF, 0, 60, 93);
                   track.add(new MidiEvent(noteOffMsg, 16));
                   // NOTE 2
                   ShortMessage noteOnMsg2 = new ShortMessage();
                   noteOnMsg2.setMessage(ShortMessage.NOTE_ON, 0, 68, 93);
                   track.add(new MidiEvent(noteOnMsg2, 16));
                   ShortMessage noteOffMsg2 = new ShortMessage();
                   noteOffMsg2.setMessage(ShortMessage.NOTE_OFF, 0, 68, 93);
                   track.add(new MidiEvent(noteOffMsg2, 32));
                   sequencer.setSequence(seq);
                   sequencer.start();
              catch (Exception e) { }
    import javax.sound.midi.*;
    public class MIDIThread extends Thread
         Sequencer sequencer=null;
         long midiTick=0;
         long midi_progressionLastChord=32;
         boolean print = true;
         public MIDIThread(Sequencer sequencer)
              this.sequencer = sequencer;
         public void run()
              System.out.println("Thread Started");
              while (midiTick<midi_progressionLastChord)
              {     midiTick = sequencer.getTickPosition();
                   if (midiTick == 0 || midiTick == 16)
                   {     if (print)
                        {     System.out.println("NOTE CHANGE");
                             print = false;
                   else
                        print = true;
    }I put in several print statements (with pauses in the init method) and the init print statements continue to be printed while the sequencer is playing, so it's not locking up the system and the "note change" statements happen when the sequencer changes notes. So this part is working perfectly! :)
    Here's what I got for my output:
    Sequencer Started
    Print from init() 1
    Thread Started
    NOTE CHANGE
    Print from init() 2
    NOTE CHANGE
    Print from init() 3
    SEQUENCER FINISHED
    Print from init() 4
    The only problem I'm having is how to "throw" this action back up to the main init method and have it do the print statement instead of the thread class. Throwing an interrupt apparently won't work as you have to poll it to see if it has been interrupted (so it'd be no different than just polling the sequencer to see if it equals the specific midi tick). Maybe throw an ActionEvent? But how to attach it to my applet? Would I need to create an instance of my applet and then pass that into the thread class so it can catch the ActionEvent? And if I do that will it stop the thread or will it keep the thread running so can detect the other notes?... Or is there a better/simpler way to do this?
    Thanks again,
    -tkr

  • Vbscript - detect config changes

    not sure if this is the right community to post this kind of question but i am after some example of vbscripts to detect routing change for example like to know when someone add a new route entry, advertised in to our campus networks, would like to know the no of routing entries being added, now of routes in the routing table /etc including vlan changes, RPF failures within the environment and number of entries in our multicast table including new additions.
    any example you can provide will be useful. thanks in advance.

    Config Changes are Changes to Customizing Objects (e.g. through IMG). Config changes are usually settings that a functional user would do in comparison to technical changes that involve ABAP which would require a developer.
    In general you could say that config changes are usually done by functional consultants whereas anything that involves ABAP coding is not config related.
    E.g. You set up order types in IMG and transport those settings. If you would now make changes to your DEV config but didn't transport this you will have config differences between DEV and Q.
    Hope that helps,
    Michael

  • Vbscript - detecting configuration changes

    Hi,
    not sure if this is the right community to post this kind of question but i am after some example of vbscripts to detect routing change for example like to know when someone add a new route entry, advertised in to our campus networks, would like to know the no of routing entries being added, now of routes in the routing table /etc including vlan changes, RPF failures within the environment and number of entries in our multicast table including new additions.
    any example you can provide will be useful. thanks in advance.

    Configure your web application to use file-based persistence. See
    http://docs.sun.com/source/817-6251/pwasessn.html#wp31960 and
    http://docs.sun.com/source/817-6251/pwadeply.html#wp28498
    Something like the following in your WEB-INF/sun-web.xml should do the trick
    <sun-web-app>
            <session-config>
               <session-manager persistence-type=�file�>
                  <manager-properties>
                     <property name="reapIntervalSeconds" value="1" />
                  </manager-properties>
                  <store-properties>
                    <property name="reapIntervalSeconds" value="1" />
                  </store-properties>
               </session-manager>
            </session-config>
    </sun-web-app>

  • Detection of changes in the context prior saving a document

    Original thread title: IS_CHANGED_BY_CLIENT and RESET_CHANGED_BY_CLIENT methods / selection change
    Does anyone know, why is that the RESET method is recursive, but the IS method isn't?
    The problem is, I need to trigger a save of a document only when there is some change made by the user, but to do that i'm being forced to implement myself a recursive method which uses both IS_CHANGED_BY_CLIENT and GET_CHILD_NODES methods. While I simply call the RESET_CHANGED_BY_CLIENT method of the root node and it affects all subnodes.
    Another problem is that, the selection changes (e.g. in a dropdownbyindex) don't get accounted as changes by the IS_CHANGED_BY_CLIENT method.
    Is there any simpler way to implement this?
    Thanks

    Thanks for your comments Manish. I've already programmed the recursive method and it is working ok, seems to be the only way then.
    But how did you solve detection of selection changes? Currently i'm thinking of having an event handler for each dropdown, which will mark a flag to be evaluated additionally to the method's result. You did the same, or selection changes didn't matter in your case?
    Thank you
    Solved: The context change log seems to be a far better alternative, it also detects selection changes.
    Check DEMO_CONTEXT_CHANGES example. If you need only to detect changes, you can use just the enable_context_change_log and get_context_change_log methods.
    It may be a little bit taxing when the context is large though, I'd like if anyone which has had this experience could comment.

  • Detect value change in a wire

    Hi, this seems pretty trivial, but I cannot find a clean way to do it, and i couldn't find anything in the forums. I want to detect a change in the value in a wire coming out of a "Get timestring VI", from iteration to iteration, and I dont think event structures quite help, because they detect changes only in front panel controls. I prefer not to use shift registers because they bring in unnecessary clutter. Is there a cleaner way to do this?
    Thanks!

    A feedback node is a little less clutter because it is more localized.
    Here's the code to detect a change in a numeric, but it works with any datatype. Modify as needed.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Changed.png ‏3 KB

  • Mx:datagrid detect itemeditor change

    I've got a datagrid with a checkbox renderer/editor like
    this. I've tried several alternatives but I cannot get
    click="myFunction()" to see myFunction even though it is
    defined in the same file. I want to detect each change and send
    that change to the server so I don't have to worry about the user
    forgetting to save changes.
    I've allso tried listening to the ArrayCollection, but my
    listener only gets called on initial startup.
    <mx:ArrayCollection id="AttendanceArray"
    collectionChange="attendanceEventHandler(event)"/>
    This can't be that hard, but I sure can figure it out.
    Anyone?

    Based on your description this code may get you
    started:

  • JTabel, detecting data changes

    Hi,
    I am new to the JTable component... I have set up a JTabel which displays some sample information. I have to display results I get from one of my methods... There is the Swing/JTable tutorial at http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#modelchange ("Detecting Data Changes"), however, the necessary code has been removed from the tutorial! I hope you can help me...
    I have set up the following table:
    public class InfoDialog extends JDialog {
         String[] columnNames = {"Type", "Value"};
         Object[][] data = {
                   {"Angle", "90"},
                   {"Speed", "50"},
         public InfoDialog() {
              Container cp = this.getContentPane();
              setLayout(new BoxLayout(cp, BoxLayout.PAGE_AXIS));
              JTable table = new JTable(data, columnNames);
              table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              JPanel tablePanel = new JPanel();
              tablePanel.setLayout(new BorderLayout());
              tablePanel.add(table.getTableHeader(), BorderLayout.PAGE_START);
              tablePanel.add(table, BorderLayout.CENTER);
    (...)From one of my other classes, GameStart, one of the methods, calculateAngle, returns the measured angle. I would like to display this result in the appropriate cell.
    In the Swing tutorial I just can read "You can see the code for that method in [PENDING: The Bingo example has been removed.]"
    So I am a little bit confused. I think I have to first extend AbstractTableModel, then I have something to do with fireTableCellUpdated... Can you maybe show me a working example or is this "Bingo example" from the Swing available elsewhere?
    Thanks for your help!

    so I can't extend AbstractTableModel... Why are you trying to do this?I first followed the example given by Sunan.N (reply #6).
    Here is a complete working example:
    http://forum.java.sun.com/thread.jspa?forumID=57&threa
    dID=566133Thanks for this example. As a newbie I still have one problem: how can I set the a new value? I use the table.getModel().setValueAt(...) method... but which code goes into the tableChanged method and which into the setValueAt method?
    Here is my code:
    public class InfoDialog extends JDialog implements TableModelListener {
         private static final long serialVersionUID = 1L;
         public JTable table;
            String[] columnNames = {"Type", "Value"};
         Object[][] data = {
                   {"Angle", "90"},
                   {"Speed", "50"},
         public InfoDialog {
              Container cp = this.getContentPane();
              setLayout(new BoxLayout(cp, BoxLayout.PAGE_AXIS));
              Dimension dim_topPanel = new Dimension(300, 150);
              JPanel topPanel = new JPanel();
              topPanel.setPreferredSize(dim_topPanel);
              topPanel.setBackground(Color.YELLOW);
              DefaultTableModel model = new DefaultTableModel(rowData, columnNames);
              model.addTableModelListener(this);
              table = new JTable(model);
              table.setPreferredScrollableViewportSize(table.getPreferredSize());
              JPanel tablePanel = new JPanel();
              tablePanel.setLayout(new BorderLayout());
              tablePanel.add(table.getTableHeader(), BorderLayout.PAGE_START);
              tablePanel.add(table, BorderLayout.CENTER);
              cp.add(topPanel);
              cp.add(tablePanel);
              setDefaultLookAndFeelDecorated(false);
              try {
                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              } catch(Exception e) {
                   e.printStackTrace();
              setResizable(false);
              setDefaultCloseOperation(DISPOSE_ON_CLOSE);
              pack();
              setLocationRelativeTo(null);
              setVisible(true);
         public void tableChanged(TableModelEvent e) {
              System.out.println("Table change");          
         public void setValueAt(Object aValue, int row, int column) {
    }What do I have to do to change, e.g., "Speed" from 50 to 60? I call the setValueAt method like this: table.getModel().setValueAt(60, 2, 2); but what do I have to write into my setValueAt method? I thought that my table will automatically change the value when calling the setValueAt method...?
    The tableChanged method is being called when a value in my table changes... OK, but what should I do with this method? I just would like to set a new value...
    :confused:

  • How to detect dataprovider change in spark List ?

    The problem is : when the dataprovider changes, the List unselects its items. I want the selected item of the List to stay selected, even if the dataprovider has a new item, for example.
    So I try to detect a change in the dataprovider, to be able to re-select the item that was selected before the change.
    I tried to listen several events but it didn't work :
    - change is dispatched by user, not by code.
    - updatecompleted is dispatched when the dataprovider changes but it is triggered also when the list is resized, and I don't want that.
    - collectionChange is not dispatched
    I don't understand why valueCommit is not dispatched when the dataprovider changes.
    Can you help me ???

    There is a dataProviderChange event fired whenever dataProvider is set,
    but it may not be listed in the metadata so you may not be able to access
    from MXML.
    Flex harUI,
    Why isn't this event exposed publicly through the metadata of the class?
    The easy fix I can come up with is to extend the List, by simply exposing the event, like:
              [Event(name="dataProviderChange", type="flash.events.Event")]
              public class ExtendedList extends List
    But I don't know if it's good practice...

  • Detecting a change in a system matrix - cnt'd

    Hello,
    This is from one of my previous questions:
    [quote]
    When an order or any other sales document is created, I want to detect if a change is made to the quantity, price, etc. of any of the lines of the document, and then change or add another line. For example, when the quantity of 'Item A' is changed from 1 to a value equal to or above 5, another item 'Item B' is required for the sale and should be added (or it's quantity increased).
    [/quote]
    My previous problem is solved now, but I directly encountered another. So when I detect a change in the matrix, I need to add a new document line, with item code 'Item B'. I have tried in various different ways but I don't seem to be able to add a line to the matrix. When I use oMatrix.AddRows(1), an empty line is added, but whenever I try to change the column values, an error occurs. Can anybody help me cracking this problem?
    Thanks

    Hello,
    If the problem still exists - what about "activating" menu item "1292" ("Add Row")?
    Did you try that + then move to this row?
    HTH

  • How to use event to detect the change of a array variable?

    I have a main application that includes a lot of sub
    components. the main app mxml file import a public class that
    includes an array variable. Each of the values in the array can be
    updated in the sub components.
    I would like to have the main mxml be able to detect the
    change of the values of the array. Is it possible to use event? And
    how? Is there a good example to follow?

    See this FB3 help topic, particularly watchers:
    Defining data bindings in ActionScript

  • Tomcat fails to detect jsp change

    I have a folder called myjsp in witch I have many jsp pages. I often make changes to these jsp pages and copy folder myjsp to many servers (Tomcat 5 and Tomcat 6).
    SOME of these Tomcat would fail to detect my changes.
    All tomcat are configured the same way. Reload is set to true.
    Any ideas?
    Thanks

    The files have a newer date compared to what?
    The date that the JSP file would be compared to would be the date of the generated servlet sitting in the work directory.
    Executing the unix "touch" command on all the JSPs you are updating will ensure that they get the current date/time and that they will be newer than the generated page.
    Alternatively you can delete Tomcat's work directory (where it stores all the generated/compiled servlets) and you can be absolutely certain that no old ones remain.
    cheers,
    evnafets

  • Event structure to detect value change of a control within a cluster in an array

    I have 1D array that contains a cluster. The cluster contains a numeric and a boolean control.
    If the user starts to edit the numeric control value i would like to call one subVI, and if the boolean control value is changed, call a different subVI.
    The array control on the front panel allows the user to edit a number of the array elements. 
    I would like to use an event structure to detect a value change in the cluster. When editing the Events, in the Event Sources panel i get the option to select only the array, not the cluster within the array or the controls within the cluster. Can the Event structure be opened up to show controls within clusters and arrays?
    The solution i am using is to detect a mouse up event on the array and then use property nodes to  determine if the key focus is on the numeric, and  a case structure to determine which subVI to call. This works, but is there a better (simpler) way?
    Thanks, Blue.

    Thanks for the responses guys.
    The tricky bit was that i wanted the numeric control values to flag they were going to be edited, so i could call a subVI, before their values were changed by the user. This is done by using the key focus property node, - i need to detect changes on the fly rather than post the event.  Probably didn't make this clear enough in my original post. 
    The array is of variable size depending on if the user decides to insert or delete elements. The user also has the option to click and edit the array without having to do to much scrolling through the array index, as the FP shows several elements at a time. The Event Structure does a good job of automatically determining which element in the array is being edited, and returning those values to the property nodes. Turned out simpler than i thought it might be at one point!
    Cheers, Blue. 
    Message Edited by BlueTwo on 01-15-2009 06:52 AM
    Attachments:
    evstrct1.jpg ‏63 KB

  • Detecting cursor change

    Hello,
    does anybody know how I can detect a cursor change in a XY graph?
    Lars

    I think I used mouse down and mouse up events to trigger when to do these checks.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Odiwaitfordata refused to detect data change after 24 hours

    hi all,
    I created a package that run circularly which begins from a odiwaitfordata(wait for the flag to be 1) and ends to it . But when i update the flag to be 1 24hours after the package started, the odiwaitfordata did not detect the flag change.
    my environment is:
    RHEL 5, ODI 11g
    the command of OdiWaitForData :
    OdiWaitForData "-CONTEXT=GLOBAL" "-GLOBAL_ROWCOUNT=1" "-LSCHEMA=ORACLE_PANORAMA" "-POLLINT=1000" "-SQLFILTER=FLAG='1'" "-TIMEOUT=0" "-INCREMENT_DETECTION=NO" "-TABLE_NAME=ODI_STATUS_TABLE" "-OBJECT_TYPE=T"
    Did the parameter POLLINT(1s) too small?
    plz try to help me , thanks a lot!
    ps:the same problem happened on odifilewait.
    jun

    I wrote a program to do this job instead of using ODIFileWait.
    The program waits for the trigger file infinitely and uses the command "startscen" to run the etl procedure.
    The trigger file is created by "crontab".
    Still don't know why ODIFileWait ODIWaitForData can not run infinitely after started...

Maybe you are looking for

  • Media encoder time remaining stops decreasing and processor drops to zero. Time elapsed keeps going up! File won't complete!

    Please help anyone who can. Firstly I know I have very little RAM on my system, only 4GB but I've been rendering the same kinds of files for weeks with no problems until the last few days. They biggest issues is as follows: My timeline in Premiere Pr

  • Sensors in BPEL (JMS Adapter)

    Hi there! I'm trying to send Sensor-Data into a MQQueue, but this always results in an error. The results are in the following Error-Log (sorry, some messages are german but the messages are nearly equal to english): Caused by: ORABPEL-12141 ERRJMS_C

  • Accessing ADF UI components programmatically

    How can I locate an ADF UI component by its ID and get access to it programmatically, without using the Binding property? What's wrong with the following code? public void onButtonPressed(ActionEvent actionEvent) { FacesContext fc = FacesContext.getC

  • Fatal error: fail to load library dxva2.dll

    My PC has Windows XP Professional SP3 and I installed the latest version of Skype. Installation was OK but when I tried to open Skype, the error I've described in the topic's subject appears (the same as the image). How can I fix this problem? Attach

  • Emergency help please

    MX2004 closes down after error message. "Cache file missing or corrupt and will be recreated". Isn't there a certain file I can find and delete, and DW will create a new file? Assistance will really be appreciated.