JTextField & Document Event

Hi I need to create a GUI like a calculator with number buttons. When I press 2 if this is the first character on the text field, I should set tp "B " [B and space]. I saw many examples of DocumentFilter and Document Event using to modify the data or generate events when pressing the keys. Then I need to add special characters after few more numbers are eneterd, eg for an input is "B 34.5567" using only keys 0-9.
Another example was to use JFormattedTextField, I posted another question on the this and got some help to use DocumentFileter.
I am facing a problem here on how to bind the keys from the GUI to these document events. When I press the keys, I can see events are fired, but cant use it to modify the JFormattedTextField. How should I do this? I am new to JAVA Swing. I am using the examples from the net to get this done.
Thanks for help in any advance.

user4071312 wrote:
Another example was to use JFormattedTextField, I posted another question on the this and got some help to use DocumentFileter.
what did you try so far? What happened when you used the suggestions in the other thread? Show us that you are trying, that infamous small runnable ... <g>
BTW, personally, I think it rather impolite to ask a question, get some suggestions and then simply start over again in a new thread.
I am facing a problem here on how to bind the keys from the GUI to these document events. please get your technical vocabulary right: in the context of Swing "bind keys" is a standing term. It's unrelated to document events.
When I press the keys, I can see events are fired, but cant use it to modify the JFormattedTextField. assuming with "events" you mean the documentEvents in a DocumentListener: you don't modify the view, you modify the model (and preferably in a DocumentFilter, as you were already advised)
How should I do this? I am new to JAVA Swing. Boils down to a very general question: How to learn :-) First you have to learn the basics. Start simple, read tutorials, read code, try to modify what you see, experience how it works (and fails <g>)
I am using the examples from the net to get this done. not enough - you have to understand them. Now go ahead, choose a simple starter (like the one in snoracles online tutorial) and tweak until it works like you want
Cheers
Jeanette

Similar Messages

  • Document events for text replacement

    Hello!
    This is a question about Document events in JTextComponent.
    Two document events in a row are fired when the user performs a text replacement (some text is selected and the user inserts or pastes new text): first, DocumentListener.removeUpdate is called for the selected text being removed; second, insertUpdate for the text being inserted or pasted.
    The question is: how can I be aware that both events are related and exist in response for the same and unique action?
    More specifically, I need to know that the remove event is part of a two-step edition in order to bypass execution flow.
    I have some bizarre ideas in mind, like proxing the original ActionMap "paste" action (for pasting) and tracking the keyboard (for inserting), but I don't think this is a too elegant approach.
    Please let me know if you would find helpful some sample code.
    Thank you!

    That's from JTextComponent replaceSelection() method source
       public void replaceSelection(String content) {
            Document doc = getDocument();
            if (doc != null) {
                    if (doc instanceof AbstractDocument) {
                        ((AbstractDocument)doc).replace(p0, p1 - p0, content,null);
                    else {
                        if (p0 != p1) {
                            doc.remove(p0, p1 - p0);
                        if (content != null && content.length() > 0) {
                            doc.insertString(p0, content, null);
    ...As you can see it calls ((AbstractDocument)doc).replace() in the most cases all the default EditorKits uses AbstractDocument extensions.
    Then from AbstractDocument's replace
        public void replace(int offset, int length, String text,
                            AttributeSet attrs) throws BadLocationException {
            DocumentFilter filter = getDocumentFilter();
                if (filter != null) {
                    filter.replace(getFilterBypass(), offset, length, text,
                                   attrs);So I think you can set your own DocumentFilter and override the filter's replace. Set the flag replaceStarted=true and call super.replace(). In the DocumentListener just check the flag.

  • Combining "allowMultipleInstances" with "OS Open Document" event = Catastrophe!

    Hey folks,
    I'm combining two somewhat "off-book" LabVIEW features here. Hoping I can get some help from the experts!
    I have an application (named APT) which has been built into an executable. In the .ini file, "allowMultipleInstances=TRUE". So calling the application more than once results in multiple instances.
    I also have the "OS Open Document" event, which triggers when the user opens .csv files from Windows Explorer.
    "OS Open Document" has been workingly splendidly for a couple months. I was recently asked to add the multiple instances case by the enduser, which I did. Now with both features, I get the following behavior:
    1) If my application is NOT the default program, then performing an "Open With --> APT" causes the file to open in Excel (?). Then APT opens, but doesn't load the file data. It acts as though it's been called without loading any file information.
    2) If my application IS the default program, then endless instances of APT begin appearing. This forces a restart.
    Has anyone had any sort of experience with combining these two features? Any ideas on how to make them play nicely together? If not, I think I may have to break it to the enduser that he can only have one or the other.
    Thanks.
    http://linkd.in/mikele

    You must be using an older version of LabVIEW. That event isn't exposed in LabVIEW 2011, as far as I know. In fact, Ton submitted an idea to provide a native way to handle this.
    Given that the event you are using isn't documented, it's anybody's guess as to what the problem is. At the very least we would need to see some code to have a chance at guessing what the problem might be. It could be something as simple as a race condition.

  • Add eventlistener to catch after save document event?

    How can I catch a after save document event?
    Best regards
    / Pontus

    http://127.0.0.1:63632/help/index.jsp?topic=%2Fcom.adobe.cside.docs%2Freferences%2Fcshalib %2Fcom%2Fadobe%2Fcshostadapter%2FIDScriptingEventAdapter.html
    Harbs

  • Validation: usage of "Complete Document" event

    Hi All.
    I'm trying to implement a Validation which checks several conditions in a Document to know if it is valid or not.
    Since these conditions are spread between the Document's lines, I choose the "Complete Document" event and expected to get a table of all lines, but it is not the case.
    I debugged the code and found that the SAP code that calls my code has a parameter called BOOL_DATA which is a table that holds the BKPF structure (of course) and also all the Document lines (stored as a table in its BSEG field).
    However, this BOOL_DATA is not used at all when my Validation is called.
    2 questions:
    1.
    How can I use this BOOL_DATA table so I can see all the Document's lines?
    2.
    If this param cannot be used, what the difference between the "Line Item" event and the "Complete Document" event in terms of what I can see and use?
    Regards.
    Ayal Telem.

    Hi Ayal Telem,
    Dear Md Faheem.
    I was not familiar with this subject.
    Thank you very much for the info.
    I started to read the documentation you referred me to and it looks interesting.
    I will update after implementation.
    Regards.
    Ayal Telem.
    That's good. Ask me anything if you struck up somewhere.
    Thanks & Regards,
    Faheem.

  • JTextField(Document, string, int)

    Dear friends,
    Could you just tell me how can I fix the size of the JTextField,
    such as just accept the maximum number of digits or characters in JTextField...
    I cant create the Document....
    Could anyone give me a tips?

    I found the best way to do this is to subclass PlainDocument as follows:
    public class MyTextDoc extends PlainDocument
        int maxCharacters;
        public MyTextDoc(int maxChars) {
            maxCharacters = maxChars;
        public void insertString( int offs, String str,  AttributeSet a )
                    throws BadLocationException {
            if( (getLength() + str.length()) <= maxCharacters)
                super.insertString(offs, str, a);
            else
                Toolkit.getDefaultToolkit().beep();
    }I then use this document in the constructor for all my JTextFields.
    I'm not sure what you mean by "I cant create the Document...."
    Cheers
    Gary

  • Capturing converting draft to real document event

    Hi all
    i wish to capture the event of turning a draft document of type warehouse transfer to a real document. in order to do so i want to capture the click event on the "Add" button in the document transfer draft form. the  problem is the draft and the real document forms have the same type. my question is how can i differntiate when i'm in a warehouse transfer draft form and not in warehouse transfer real document form?
    appreciate the help
    Yoav

    Hi, Yoav!
    The first thing i thought out is to check if there is such document in the draft-table(ODRF). When you get the Add-click event, do the query that selects from the ODRF table the document with the specific parameters - Docnum(from the 260 EditBox on the warehouse transfer form), DocDate and ObjType (67). If the record is found - it's an adding the document from the draft, if not found - it's from the real document...
    HTH!
    Aleksey Kuznetsov

  • Override event handler for document events in LiveCycle

    I would like to have an email notification when a user opens a policy-protected DRM pdf. Is there a way to override the event handler for Document Open events?
    Or perhaps there is a way to access the event database- where can I find this information?

    Thank you so much for your reply. I have created an external authorization and am following the steps outlined here: http://help.adobe.com/en_US/livecycle/9.0/programLC/help/index.htm?content=001479.html
    I have deployed my jar and restarted JBoss. However, now when I try to create a new policy using my external authorization, I do not see an option to add it on the create new policy page. I see only sections for Users and Groups, General Settings, Advanced Settings, and Unchangeable Advanced Settings. Could you please tell me how to add the external authorization?
    Also, in the component.xml file, I followed the sample and kept this line: <component-id>com.adobe.livecycle.samples.externalauthorization</component-id>
    Should that be changed? If so, to what?
    Thanks.

  • OnChange Document event ?

    Hi all,
    Is there any way to look at any document switch in the UI.
    I mean, I have 2 documents A & B.
    If I swith from A to B, can I add a event handler on that switch.
    It seems not to be possible in the DOM but is there any workaround ?
    TIA Loic

    Thanks to both of you,
    I have APID but never got time to play with, that's the moment :-)
    Loic

  • Photoshop save document event not firing

    I am creating a photoshop plugin using generator,'documentaftersave' event doesn't seem to working. is there anyway for me to catch save event on document.

    I am creating a photoshop plugin using generator,'documentaftersave' event doesn't seem to working. is there anyway for me to catch save event on document.

  • BeforeClose document event

    Hello,
    I'm seeing something very weird, or at least counter-intuitive with the 'beforeClose' event type.
    If I add a simple eventListener with the eventType of 'beforeClose', it seems to be dispatched twice: once before the close, and once after the close.
    #targetengine session
    app.documents[0].eventListeners.add("beforeClose", function()
         alert(app.documents[0].name);
    If there is only one document open, this will alert the document name twice.  If two or more documents are open, it will alert the document name, and then alert the second document name.
    Has anyone else experienced this?  Anyone know a workaround?  Am I being completely supid?
    /dan

    Bob,
    Thanks for your response.  Looking into this a bit more, there are, indead, two events that are fired when the document closes.  The first is an Event that targets the LayoutWindow, while the second is a DocumentEvent that targets the Document.  It was a bit counter-intuitive to me that diffrent events could trigger the same eventListener muliple times, but it seems clear now.
    Thanks,
    /dan

  • Sandbox + Document Event Handlers

    Hi,
    I am writing an sandbox Event receiver on sharepoint online. where when document will be uploaded to the document library the same document should get attached with the List item automatically.
    can anyone pin point me on how do i go about it..!?
    Thanks, Parth

    Hi,
    According to your description, my understanding is that you want to attach the document to list item when upload the document to document library.
    I suggest you use SOAP web service to achieve it.
    You need to add reference to the web service using the following URL:
    https://my.sharepoint.installation/personal/test/_vti_bin/lists.asmx
    In the web service, you can use AddAttachment funtion to add attachment to listItem.
    Here are some detailed article for your reference:
    http://msdn.microsoft.com/en-us/library/lists.lists.addattachment(v=office.12).aspx
    http://stackoverflow.com/questions/2969810/sharepoint-2010-client-object-model-add-attachment-to-listitem
    http://buyevich.blogspot.jp/2011/03/how-to-attach-files-to-list-item-using.html
    Best Regards
    Zhengyu Guo
    TechNet Community Support

  • Document Event Handlers

    How do I access the Page/Open and Doc/Open event handlers using the Javascript debugger ?
    Currently, I can see only a few related to the Closing and Saving of the document...Document Will Save, Document Will Close, etc.
    There is no "Add" button in the Document Actions dialog box that appears when one clicks on Other Tasks when editing a form-based document.
    Also, I noticed there is a Javascript function "SetPageAction" which can be used for the Open event handler, but apparently this must be established via script...
    no GUI counterpart appears to be available.

    There isn't an explicit document open event. Code that you place in a document-level JavaScript will execute when the document is opened.
    To get to the Page Open/Close events, open the Pages navigation pane, select the page you want, right-click > Page Properties > Actions

  • JTextField document model

    Hi,
    I have a JTextField field, which is supposed to be read only field to show time.
    My application gets from server a long value, which represents the time.
    This JTextField field shows the time (from server) in format mm:hh:ss (need to convert the long value to the format).
    My question is:
    Which document model should I use and how? I don't find a good example for that.
    Thanks

    I have a JTextField field, which is supposed to be read only field to show time.I would say that typically you would use a JLabel for this. Then you just use the setText() method.

  • JTextField Document validation

    What is the best way to use Document to validate a textfield that will only accepts numbers between 1 and 30.

    Lets say there is a situation where we really need to prevent users from typing numbers out of range (instead of showing an error message afterwards). I looked at the tutorial and there is an example on how to use DocumentFilter to restrict input to Integers. I tried to adapt it to do range checking. I was successful in enforcing max value but I can't get it to enforce min value. If the min value is 2 and if the user types 11 then DocumentFilter.insertString is called twice. First with just 1 and then with 11. Is there someway to stop insertString from being called until the user is done typing? I must be missing something obious.

Maybe you are looking for