Documents to text controls (TextField) style.

Is this possible?

I need textfield with different styles (font color).

Thank you.

Hi Antonio,.

Antonio Sánchez says:
This issue is starting to make me doubt that it is possible to implement, after at least one more o less natural approach.

No offense meant - but there is a completely natural approach (which Rob suggested), only you have not found a way to follow this path, because the too much doubt :-)

Couldn't resist to play around a bit (after all, all of the text is the more opaque for me) the stripped of what is needed:

-a field that uses a StyledDocument and a StyledEditorKit with other ways to expose these last to the fieldUI
-a representative of the custom user interface that uses the editorKit instead of the simple default value
-configuration of the document with the style to use for the only not-yet-typed (after the caret, i.f.)
-logic that observes the circumflex and moves the style accordingly

A very rough proof of concept code snippet:

// one method override of xxTextFieldUI
    public static class BasicStyledTextFieldUI extends BasicTextFieldUI {
        /**
         * @inherited 

*/ @Override public EditorKit getEditorKit(JTextComponent tc) { if (tc.getClientProperty("editorKit") instanceof EditorKit) { return (EditorKit) tc.getClientProperty("editorKit"); } return super.getEditorKit(tc); } public static ComponentUI createUI(JComponent c) { return new BasicStyledTextFieldUI(); } } // setup a styled field JTextField normal = new JTextField("just a normal field", 10); // quick config of a field with StyledEditorKit/-Document JTextField styledField = new JTextField(50); StyledEditorKit kit = new StyledEditorKit(); styledField.putClientProperty("editorKit", kit); StyledDocument document = new DefaultStyledDocument(); styledField.setDocument(document); // note: just a proof-of-concept, for real-world-support // must install with the UIManager for all supported LAFs // f.i. via SwingX XXComponentAddon styledField.setUI(new BasicStyledTextFieldUI()); //Initialize some styles. Style defaultStyle = StyleContext.getDefaultStyleContext(). getStyle(StyleContext.DEFAULT_STYLE); Style regular = document.addStyle("regular", defaultStyle); StyleConstants.setFontFamily(defaultStyle, normal.getFont().getFamily()); Style s = document.addStyle("proposal", regular); StyleConstants.setForeground(s, Color.GRAY); s = document.addStyle("typed", regular); StyleConstants.setForeground(s, Color.BLACK); // some static text insert just to see it working // updating on caret moves is left to the reader :-) try { document.insertString(0, "typed text", document.getStyle("typed")); document.insertString(document.getLength(), "proposed completion", document.getStyle("proposal")); } catch (BadLocationException e1) { e1.printStackTrace(); }

And my point for pets: Swing is one of the component frames most powerful in the world, fifteen years ago designed for living requirements never dreamed - and it does. It is not the easiest to learn, but then... the world is not simple to more :-)

See you soon
Jeanette

Tags: Java

Similar Questions

  • Generate list of a document text paragraph/character styles?

    Hello. Does anyone know how to generate a list from a text paragraph/character styles?

    Nothing at all? Use a script! This JavaScript does the trick:

    myFile = File.saveDialog("Store this data, where?", "Plain text:*.txt");
    if (myFile == null)
     exit(0);
    myFile = File(myFile.fsName);
    myFile.open("w");
    myFile.writeln ("Character styles");
    myFile.writeln ("================");
    for (a=1; a
    

    Copy, paste it into a text editor (the editor ESTK which accompanies your InDesign is good). Save it as "storeStyles.jsx" in your Script file. When recording in the right place, it appear automatically in the actions panel. Double-click it to run it.

    Both character and paragraph style tables start the counter to 0, but the first character style is always "[None]", and the first paragraph of the styles are always "[None]" and "[standard paragraph].

  • Pick up writing text in a style to specify

    Hello!

    I would take a text wrtie specify style (such as font, size...) and put this text in my ExportPDF script to apply the text for the name of the exported document.

    As: On my document page, I write a text like this: HELLO ; We call it safe style "page_name". When I export this page in PDF format, I care about this HELLO became the name of the PDF file. In the end, in my computer so I want to have a PDF document, which is called HELLO.

    This is my script ExportPDF:

    main();  
      
    function main(){  
        mySnippet();  
    }  
       
    function mySnippet(){  
        
         var myPageName, myFilePath, myFile;  
         var myDocument = app.activeDocument;  
         var myBaseName = myDocument.name.replace(/\.indd/, "");  
         var myPDFExportPreset = app.pdfExportPresets.item("[Qualité supérieure]"); 
         for(var myCounter = 0; myCounter < myDocument.pages.length; myCounter++){  
              myPageName = myDocument.pages.item(myCounter).name;  
              app.pdfExportPreferences.pageRange = myPageName;  
               
              var myRegExp = /:/gi;  
              myPageName = myPageName.replace(myRegExp, "_");  
              myFilePath = Folder.desktop + "/" + myBaseName + "_" + myPageName + ".pdf";  
              myFile = new File(myFilePath);  
              myDocument.exportFile(ExportFormat.pdfType, myFile, false, myPDFExportPreset);  
         }  
    }  
    

    This code assumes that:

    -InDesign document with the paragraph style "page_name".

    -unique appearance of the text with "page_name" ParagraphStyle

    var myDocument = app.activeDocument;
    
    main();  
    
    function main(){
        var myPDFname = extractPAFname()
        exportPDF(myPDFname);
    }  
    
    function exportPDF(pdfname){
         //
         var myPageName, myFilePath, myFile;
         //var myBaseName = myDocument.name.replace(/\.indd/, "");
         var myPDFExportPreset = app.pdfExportPresets.item("[Qualité supérieure]");
         for(var myCounter = 0; myCounter < myDocument.pages.length; myCounter++){
              myPageName = myDocument.pages.item(myCounter).name;
              app.pdfExportPreferences.pageRange = myPageName;
              //The name of the exported files will be the base name + the
              //page name + ".pdf". If the page name contains a colon (as it will
              //if the document contains sections), then remove the colon.
              var myRegExp = /:/gi;
              myPageName = myPageName.replace(myRegExp, "_");
              myFilePath = Folder.desktop + "/" + pdfname + "_" + myPageName + ".pdf";
              myFile = new File(myFilePath);
              myDocument.exportFile(ExportFormat.pdfType, myFile, false, myPDFExportPreset);
         }
    }  
    
    function extractPAFname(){
        var myStyle = myDocument.paragraphStyles.itemByName('page_name');
        if (myStyle.isValid){
            app.findGrepPreferences = app.changeGrepPreferences = null;
            app.findGrepPreferences.appliedParagraphStyle = myStyle;
            var mySearch = myDocument.findGrep();
            if (mySearch.length >0){
                // take the firts item
                return mySearch[0].contents
            }else{
                alert('error message - no text');
                exit();
            }
        }else{
                alert('error message - no style');
                exit();
            }
    }
    
  • Questions to copy text, including GREP styles

    Hello.

    I have a block of text, which contains text formatted with styles, and a particular style by contains a GREP style, making a certain word "BOLD" and colored.

    When I copy this document to a new document that does not contain the styles, paragraph styles are made, but the character GREP style is not fired.

    If the character style in the receiving document, then all is good.

    Is this normal? I was expecting the character style that is attached to the paragraph style to be included automatically in the target document.

    Is there a way to get around this? I want to make it as perfect as possible, but for now I need to make sure that I have loaded before as I have paste the character style.

    See you soon


    Roy

    It should not. Try trashing the prefs - see replace your preferences

  • Removal of text box character style

    I have a CS3 document that has about 10 styles of characters - whose is Fig_ref. whenever I have to draw a text box, it automatically to the text with this style of character styles. I have to go to the menu drop down and select None. Is there a way to force the default value to "None"? Thank you.

    With no text selected, go to the character styles and select None.

  • Compensation a text control

    Hello, first let me say that I am new to Labview, but worked with it for a little while now and starting to get the hang of it.  The project that I am working on is one GOES for a test system for a bunch of cables, each serialized.  The idea is that the user selects a directory, and then for each test between a serial number while the VI enters data (from a network Analyzer) and written in a text file in the directory selected with the name being the serial number with the .txt extension.

    I have this works pretty well, but we would like to integrate a code scanner barcode.  We have a bunch of scanners that emulate USB keyboards, so it is easy to create a user click in the text for the serial number control and scan cable.  However, we would also be able to have so that the user does not need to do anything other that connect the cable and the scanner.  Have the scanners are set up to add a newline at the end of the number it just scanned, basically simulating hitting the Enter key.  I put the button that I use to trigger the test to fail over to the entrance, so just scan bar code will begin to try and save the data.  However, it will not erase the text control; on the contrary, the previous serial number is in there while the new one is appended to the end.  How can I clear this field programmatically?

    Write an empty string to the local variable of the control.

  • I can do my custom cascading text control?

    Hello

    I need a control of custom text in my application and I am wondering if it is possible to do in the Cascades:
    1. There must be a custom cursor appearance - a rectangular area of colours reversed on a character (like the slider on the old VT100 terminals).
    2. must have neither borders nor 'X' sign to clear the text.
    The text control uses the monospaced font.

    I realized there is AbstractTextControl, but you're not supposed to subclass it, you must use CustomControl for all custom controls. So I would say that I have to build my control from the basic text and Rectangle elements in Qt Quick, but they are absent in the Cascades. I just found QRect but the documentation says only: "the QRect class defines a rectangle...". ». Is it really to draw something on the screen? Can I use QRect in my custom control, I have write in C++ and register in QML?

    Can I make a custom control that contains the label and captures the events of virtual keyboard to add characters of the label?

    Thanks for help.

    (1) no custom cursor is currently possible, reverse color could possibly be done by a custom font or using HTML in the text control (or WebView so you need not display just to input from the user)

    (2) not possible to remove the borders at the present time, the X can be enabled or disabled programmatically.

    Yes you are right, I would say WebView to watch if it's screen only, otherwise you're looking at your own writing.

  • Blocks of text in Object Styles

    A text frame can be selected in the list of object Styles? When I select a text block, the gray out object styles. I do not understand why this is happening as I believe I created blocks of text before object styles...

    I use InDesign CC.

    You select it with the text tool, or with one of the selection arrow tools? It will not work if you select it with the text tool.

  • CS6 ePub "document Split: from paragraph tags Style Export.

    I tried to find how to set the Option Export ePub "document Split: from paragraph tags Style Export" using javascript. It doesn't seem to be part of the epubExportPreferences, as

    myDocument.epubExportPreferences.breakDocument = true;

    Sets the stop on [standard paragraph] document. I can change it for another single paragraph quite easily, but not what I need.

    I'm probably looking in the wrong place, but if someone could point me in the right direction, I would be very grateful.

    My code is here (that works, but does not define this option): https://github.com/makeBetterEBooks/eprdctn/BLOB/master/DBW_ePubExport.jsx

    Thank you!

    I found the answer earlier, but thought I'd post here for those seeking on the other.

    You must set the name of style paragraph to an empty string:

    myDocument.epubExportPreferences.breakDocument = true;

    myDocument.epubExportPreferences.paragraphStyleName = "";

    Then it will break on the plates for export.

  • can anyone tell how to compare two documents with two controlled with the same mouse pointers

    can anyone tell how to compare two documents with two controlled with the same mouse pointers?

    Windows and OS X can only display a mouse pointer - it is created by the operating system, not the application.

  • With the help of FindChangeList.jsx - can't find text AND character style?

    I have been using the "FindChangeList.jsx" script in CS5 and it works well for what I need, except for one thing: ideally I want to pick up a piece of text with a certain style of applied character. Is it possible to do something like

    Text {findWhat: 'some text', appliedCharacterStyle: 'character style name'}

    I tried the above, but it is basically ignored the character style and found all of the text corresponding to the sentence (unknown what character style has been applied). Any ideas?

    Thank you very much. HJ

    Problem solved-, I made two mistakes. First of all, the style is a paragraph not one style style character, and secondly, it has been grouped into a folder. So I moved out of the folder and changed the code to ' appliedParagraphStyle: ' (and everything worked fine.:).

    Thank you. HJ

  • XML can be used in text controls?

    I would like to use an external XML file to populate the text in a bunch of TextAreas (and other text controls).  I noticed that there is no 'dataProvider' for texf controls property.  What could be a good approach?

    Thank you.

    Repeaters if you use flex 3 or DataGroups if flex 4.

  • Reverse the text in the text control.

    Hey,.

    I need reverse my text control text so that I can read the text on a mirror. In this case I have to go the tank all tanks, change the order of characters in a word (first tank will be the last tank) and change the beginning of paragraphs, first word of the paragraph will be the last word in the paragraph.

    A very kind soul help me in this problem? I don't know how I can start doing.

    Thank you

    Hello

    When you rotate or scale-1 it must be remembered that the left position is now the old x - width of the control, so if you want a wide control 200 at position x = 10, you you x 210.

    David.

  • How to display only specified characters in the text control

    Hello

    I use the text control in the swf file. In this file, I want to display text up to 15 charaters and if more, then present them with [...]

    Please provide a solution for this.

    Here ya go to 15 characters maximum.

    This example uses textInputA as a box of textInput that someone can type in.  As a result, in the text/label component, it checks the length of the value of textInputA and if it is longer than 15 characters, it removes all characters beyond 15 and adds [...] at the end.

    You can substitute other things instead of a textInput control, but I used it here as it's the easiest way to explain.

    Let me know if this helps you

  • Property of the text control alpha...

    Hello world

    Can someone tell me why the alpha of Flex 2 text control attribute does not work? I hard coded the alpha value of 0, the text control, and it still shows the control as if the alpha attribute has not been defined. Is this a bug? Here is an example:

    ----------

    < mx:Text text = 'test' color = "#ffffff" fontSize = "24" width = "250" textAlign = "center" id = "bottomPart" height = "100%" alpha = "0" / >

    ----------

    Thanks for your time,

    -Tony

    You should always use an embedded font. No embedded fonts are used for performance reasons. Flash Player is not convert characters in these fonts to display the text. It is much faster. When you use an embedded font, the player uses the vector outlines to form characters. So they can be washed out, rotation, etc., but at the expense of speed.

Maybe you are looking for

  • Satellite A50 - after Exchange of disc HARD, I have the same ability

    Hello, I just changed the old 40 GB HDD in A50 a new 60 GB HARD drive. Until I changed it, I used True Image to do a backup of the old HARD drive file so that I can get everything to the new HARD drive. However, when I did the HARD drive has everythi

  • access the properties of digital format

    I create digital controls/indicators on the fly.  Most of them should be displayed in hexadecimal.  However, I can't access the format properties that allow me to define that when I create the indicator/control using the new object VI VI.  I think th

  • Optical digital work on the DVD and cable, but NOT on Youtube, Amazon Prime or applications.

    Just bought XBR65x850C. hung out on TV to stereo receiver digital optical cable. Works very well for cable and DVD player, but NO sound when I try to watch any application like Youtube, Amazon Prime, etc.. If I change to 'Speakers TV', I hear. I have

  • Find the MSI to install virtual pc

    Where can I find and install the virtual PC MSI.  I have windows vista, this is what it contains.  Thank you

  • WiFi says limited access

    having problems trying to connect to any wifi says limited access said that there is a problem with the connection of local card and 2 connection wireless network card It's a windows 7 Toshiba satellite c655 64-bit operating system computer intel pen