Split TextArea

Im wanting to create a TextArea that will show ASCII on the left, and the Hex values on the right.
Im not sure where to start. Ive looked into the JTextArea source and noticed it doesnt have a paintComponent method. So obviosly text components render differently?
I thought of modifying the JTable, but I wont be dealing with rows.
I was then thinking of just implementing my own paintComponent for the text area, but I think I should learn how text components are drawn first.
Or, to save time, has anyone seen an implementation of this already?
Any ideas on where to start?

import java.awt.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.*;
public class ShowText extends JFrame{
    public ShowText(){
        setTitle("Show Text");
        setDefaultCloseOperation( EXIT_ON_CLOSE );
        try{
            readText();
        }catch(IOException ex){
            ex.printStackTrace();
        textPane = new JTextPane();
        textPane.setFont( new Font("monospaced", 0, 14) );
        JScrollPane scrollPane = new JScrollPane( textPane );
        getContentPane().add( scrollPane );
        showText(40);
        setScreenState(false);   //true = full screen
    private void showText(int textWidth){
        StringBuffer sb = new StringBuffer(1000);
        for ( int j=0; j<text.length(); j=j+textWidth ){
            int end = text.length();
            int end_2 = j+textWidth;
            if( end_2 > end ){
                text.append( blanks.substring( 0, end_2 - end ) );
            String str = text.substring(j, end_2);
            sb.append(str);
            sb.append("\t");
            sb.append(asciiToHex(str));
            sb.append("\n");
        setTabs( textPane, textWidth+5 );
        textPane.setText( sb.toString() );
    public void setTabs( final JTextPane textPane, int textWidth){
        FontMetrics fm = textPane.getFontMetrics( textPane.getFont() );
        int charWidth = fm.charWidth( 'W' );
        TabStop[] tabs = new TabStop[1];
        tabs[0] = new TabStop( textWidth * charWidth );
        TabSet tabSet = new TabSet(tabs);
        SimpleAttributeSet attributes = new SimpleAttributeSet();
        StyleConstants.setTabSet(attributes, tabSet);
        int length = textPane.getDocument().getLength();
        textPane.getStyledDocument().setParagraphAttributes(0, length, attributes, false);
    private void readText()throws IOException{
        BufferedReader reader = new BufferedReader(new FileReader("MyText.txt"));
        text = new StringBuffer(1000);
        for( String str = reader.readLine(); str != null; str = reader.readLine() ){
            text.append(str);
    private String asciiToHex(String ascii){
        StringBuilder hex = new StringBuilder();
        for (int i=0; i < ascii.length(); i++) {
            hex.append(Integer.toHexString(ascii.charAt(i)));
        return hex.toString();
    private void setScreenState(boolean full){
        setExtendedState(JFrame.MAXIMIZED_BOTH);
        if(full){
            setResizable(false);
            setVisible(true);
        }else{
            setVisible(true);
            setResizable(false);
    public static void main(final String[] args){
        new ShowText();
    private JTextPane textPane;
    private StringBuffer text;
    private final String blanks = "                                                  ";
}

Similar Messages

  • Questions on the features of a textarea.

    Hi experts,
    I am working on Documaker 12.0.1. I have some doubt related to the feature of a textarea mentioned below. Could you please put a light on it ?
    _1. Sizing_
         a- Can grow and shrink
         b- Can span pages
         c- Must fit on page
         d- Suppress variable lines
         e- Adjust top line
    _2.Default (fonts)_
         a- Tab stops
    I am having some problem while creating a fap. I have 2 textareas in a fap and separated by some space, when I am seeing the output the whole fap is going to second page, although it is having enough space to print in the first page itself. For some case when I am unchecking the ADJUST TOP LINE and checking CAN GROW AND SHRINK, its coming in first page. fap is auto sized also. When I am minimizing the space between two textareas to print in first page, its overlapping. Please let me know if you need any more information..
    Thanks,
    Bikas Ranjan

    You mention multiple options that can affect the result in numerous ways. For instance, 'Must fit' means that the text area must fit on a page if it can. So even with the can span turned on, the text might move as an entirety to the next page if it can't stay as a whole on the first page.
    Also note that with multiple text areas on a page, only the one text area that is formatting is allowed to split during that format. That means if you put two text areas one above the other and then make the top one grow, the bottom text area is "pushed". And if it encounters the bottom of the page, that text area will go to the next page - even if you had the split option on that one too. This behavior is not normally a problem when you consider that sections are mapped from top to bottom, but if you are using a different order or unusal sized items, it can get in the way.

  • Losing carriage returns in textarea / using plpdf to generate report

    Hello,
    I'm using Apex 3.1.1 and Oracle 10g database. I would appreciate any suggestions on how I can preserve carriage returns in a textarea when sending the text to a package that generates a report. Please see example of current problem (below code). I'm using an onkeypress function to check for keycode = 13 when the Enter key is pressed -- that is working. I also created an alert to show the url value -- I can see the text on multiple lines, so that appears to be working as well. The textarea value parameter in the package is defined as varchar2. Per the support folks at plpdf.com, chr(13) indicates an explicit line break, and they told me to check my text. I don't know what I'm missing. Thank you for any suggestions you may have.
    Lisa
      function callPLPDFRep()
          var url;
          url = '#OWNER#.' + $x('P&APP_PAGE_ID._REPORT_PROCEDURE').value + '?' + build_params();
          w = open(url, "winPDFRep", "Scrollbars=1, resizable=1, width=800, height=600");
          if (w.opener == null)
            w.opener = self;
            w.focus();
       function build_params()
        var lparms;
        lparms = '';
        lparms = lparms + '&p_incorrect=' + $x('P212_INCORRECT').value;
        lparms = lparms + '&p_correct=' + $x('P212_CORRECT').value;
        return lparms;
      }Text in textarea:
    035 5768 06/15/2010
    035 5768 06/16/2010
    035 5768 06/17/2010
    Printout on report:
    035 5768 06/15/2010035 5768 06/16/2010035 5768 06/17/2010

    Hello Michael,
    Thank you for your response. After doing some researching and experimenting, here's what I have found so far.
    First, using an onkeypress function to alert the keycode, a chr(13) is being returned when I press the Enter key in the textarea.
      function check_Enter(e)
        var keynum;
        var textval = $x('P212_INCORRECT').value;
        if(document.all) 
          keynum = e.keyCode
        else
          keynum = e.which
        alert(keynum);     
      }Next, when I access the value of the textarea via javascript with $x('P212_INCORRECT').value, the chr(13) is automatically converted to the newline character (\n). In an attempt to replace the \n with a \r so plpdf will recognize the carriage return, I added a javascript replace function before sending the text to the package, and it does not work.
      function build_params()
        var lparms;
        lparms = '';
        lparms = lparms + '&p_incorrect=' + $x('P212_INCORRECT').value;
        lparms = lparms + '&p_correct=' + $x('P212_CORRECT').value;
        alert(lparms.split(/\n/g).length - 1);  // confirm that a newline character is found
        lparms = lparms.replace( new RegExp( "\n", "g" ), "\r");  // replace newline character with carriage return
        return lparms;
      }When I tried to replace the newline character (\n) with chr(13), the chr(13) is printed out like it is text instead of a special character. In order to test that I have the correct syntax for the replace function in javascript, I tried replacing \n with '...', and then in the package that generates the PDF, I replaced the '...' with chr(13). That works!
    In response to your comment about the PLPDF procedure for multi line section, I am using: plpdf.PrintMultiLineCell(180, 6, l_incorrect, '0', 0). As a newbie to javascript, I am not sure why replacing \n with \r is not working. Can you advise how to use a chr(13) in the javascript replace function and have it recognized as a special character and not text? I don't know how to view special characters in the textarea other than checking for them with javascript.
    Thanks, Lisa

  • Design problem(split pane scrollpane Insets)

    hi,
    doing a exam simulator prgm
    design is like,
    Question (text area with scrollpane)
    Answers (checkbox inside panel with scrollpane)
    used split pane between qst and ans but big thick bar comes how to reduce size and it is not
    moving.
    used GridLayout for container and panel.
    PROBLEM is how to leave space qst textarea appears from very left edge of screen how to leave some space
    same prblm for checkbox they to appear extreme left on screen.

    Put those components in a JPanel overwriting the getInsets() method like this:
    JPanel cPane=new JPanel(){
        private final Insets _insets=new Insets(10,10,10,10);
        public Insets getInsets(){
            return _insets;
    };...should do the trick, take a look at the Insets class if you need information on how defining it...

  • Loop through contents of textarea / arrays in PL/SQL?

    Hi all,
    I have the need to allow a user to update a large number of rows at once. His data source is a spreadsheet. Basically, he receives a file weekly that contains dozens of vehicle numbers and dates that they are to be delivered.
    My thinking is that he can simply copy and paste these columns into a textarea, which would look like this (separated by tabs):
    Vehicle Date
    12345 12/31/07
    23456 1/12/08
    48484 1/15/08
    I'm a PHP programmer, so I could easily do this by splitting taking the text area, splitting it by line returns into an array, and then further splitting it by the tab between the vehicle and the date, and using a loop, do:
    UPDATE VEHICLE_TABLE SET delivery_date = TheDate WHERE VEHICLE_ID = vehicle.
    I'm very new to PL/SQL and I'm not sure that this is possible. Can someone point me in the right direction or suggest a better way of doing this?
    Thanks in advance!

    Hi,
    it's quite easy to do the same in PL/SQL. You can use the supplied Apex_Util.string_to_table function to slice a string and put the parts into an array. See the following code as an example.
    DECLARE
        vLines  Apex_Application_Global.vc_arr2;
        vFields Apex_Application_Global.vc_arr2;
    BEGIN
        vLines := Apex_Util.string_to_table
                    ( p_string    => :P4_TEST
                    , p_separator => CHR(13) -- line break delimiter
        FOR vLineIdx IN 1 .. vLines.COUNT
        LOOP
            vFields := Apex_Util.string_to_table
                         ( p_string    => vLines(vLineIdx)
                         , p_separator => CHR(9) -- tab delimiter
            -- some basic checks
            IF vFields.COUNT <> 2
            THEN
                RAISE_APPLICATION_ERROR(-20999, 'No enough fields in line '||vLineIdx);
            END IF;
            IF vFields(1) IS NULL
            THEN
                RAISE_APPLICATION_ERROR(-20999, 'No Vehicle entered in line '||vLineIdx);
            END IF;
            IF vFields(2) IS NULL
            THEN
                RAISE_APPLICATION_ERROR(-20999, 'No delivery date entered in line '||vLineIdx);
            END IF;
            -- let's do the update
            UPDATE VEHICLE_TABLE
               SET delivery_date = vFields(2)
             WHERE VEHICLE_ID    = vFields(1)
        END LOOP;
    END;Patrick
    My APEX Blog: http://inside-apex.blogspot.com
    The ApexLib Framework: http://apexlib.sourceforge.net
    The APEX Builder Plugin: http://sourceforge.net/projects/apexplugin/

  • Restrict "Enter, delete and backspace" in TextArea

    Hi,
         I want to restrict Delete key, Backspace key,  and Enter Key in TextArea. Please tell me how to restrict these 3 keys. Thanks in advance.
    Regards,
    Kameshwaran A

    var origS:String = "Cuveiro: resteba o restreba 'la segunda cosecha que se coge en un mismo terreno'."
    my_txt.text = origS;
    listenerObject = new Object();
    // If i press delete key, first  this listener is invoking
    listenerObject.keyDown = function(eventObject) { 
        ci = Selection.getCaretIndex(); 
    listenerObject.keyUp = function(eventObject) { 
        if(Key.getAscii()==13){
            my_txt.text=my_txt.text.split("\r").join("");
        } else if(Key.getAscii()==8 || Key.getAscii()==127){
            if(prevS){
                my_txt.text=prevS;
            } else {
                my_txt.text=origS
        prevS = my_txt.text;
        Selection.setFocus(my_txt);
        Selection.setSelection(ci,ci)
    my_txt.addEventListener("keyDown",listenerObject);
    my_txt.addEventListener("keyUp",listenerObject);

  • Make CLOB field as an textarea item and also provide update option

    Hello,
    Can anyone please help me out with this issue. I have clob field column in my table and I wanted to make this column as an Textarea item in my form so that the users can update this column item. Can anyone please provide a possible approach for this issue.
    thanks,
    orton

    Hi Orton,
    As far as I know it is a limitation of mod_plsql - variable size can't be more then 32K.
    I think that you have to split the value of text area in javascript in chunks less then 32K in length and submit them
    with AJAX one by one.
    Regards,
    Lev

  • Split Panes, Frame and Resizing

    Hi,
    my user interface is made up of a message panel using the created class SplitPanes2 through the method createSplitPanes called from a class that extends Frame. (will post code if required: lengthy). When the frame is resized/maximized, the splitPanes remain at their preferred size. How can I work on it such that the SplitPanes will resize proportionally too? Please inform me if I have overlooked certain details.
    -cyndi
    public class AppLayout {
         Frame parent;
         public AppLayout() {
         public void createSplitPanes( Panel messagePanel, TextArea messageAreaOut, TextArea messageAreaIn, TextArea messageArea ) {
              Panel splitPane2 = new SplitPane2( messageAreaOut, messageAreaIn, messageArea );
              messagePanel.setLayout( new GridLayout(1, 1));
              messagePanel.add(splitPane2);
         public class SplitPane2 extends Panel {
              public SplitPane2( TextArea messageAreaIn, TextArea messageAreaOut, TextArea messageArea ) {
                   //Create an instance of splitPane
                   splitPane sPane2  = new splitPane( messageAreaOut, messageAreaIn );
                   JSplitPane left    = sPane2.getSplitPane();
                   //XXXX: Bug #4131528, borders on nested split panes accumulate.
                   //Workaround: Set the border on any split pane within
                   //another split pane to null. Components within nested split
                   //panes need to have their own border for this to work well.
                   left.setBorder( null );
                   //Create a split pane and put "left" (a split pane)
                   //and TextArea instance in it.
                   JSplitPane sPane   = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT,
                        left, messageArea );
                   //splitPane.setOneTouchExpandable(true);
                   sPane.setDividerLocation( 150 );
                   sPane.setResizeWeight( 0.5 );
                   //Add the split pane to this frame
                   sPane.setPreferredSize( new Dimension( 400, 430 ) );
                   add( sPane );
              class splitPane {
                   JSplitPane sPane;
                   public splitPane( TextArea messageAreaOut, TextArea messageAreaIn ) {
                        //Read image names from a properties file
                        sPane = new JSplitPane( JSplitPane.VERTICAL_SPLIT,
                             messageAreaIn, messageAreaOut );
                        //splitPane.setOneTouchExpandable(true);
                        sPane.setDividerLocation( 0.5 );
                        sPane.setResizeWeight( 0.5 );
                        //Provide a preferred size for the split pane
                        sPane.setPreferredSize( new Dimension( 150, 350 ) );
                   public JSplitPane getSplitPane() {
                        return sPane;

    Hi, I'm not sure, but I think I had a similar problem. I tried to place a JSplitPane inside a JPanel and then I got the same behaviour as you describe. Unfortunately I didn't find out why that happened. I simply didn't use the JPanel and then it worked as I wanted it to. (Almost) :)

  • Show the carat in a TextArea without focus

    Anyone know how to show the carat in an Air TextArea without it having focus (in other words, ALWAYS show where the insertion point is no matter what). I've tried everything and even resorted to calculating the text metrics and drawing my own carat, but that doesn't work too well since I think getLineMetrics() was just a joke put in to piss off developers.

    That might be one of my problems. My main problem with it is that I'm using a TextArea that has wordwrap enabled. I've found that, even if there's (visibly) 20 lines in a textarea, it is still just considered one line for getLineMetrics() until it finds a line break. Since wordwrap pushes words to the next line as to not cut off or split up any words, it seems nearly impossible to find exactly where the carat is supposed to be.
    I also have to make minor adjustments to a couple letter sizes (it calculates i 1 pixel less, m is 2 pixels less, etc). This may be related to what you mentioned. If so, how should I get around that?

  • Form split across two columns

    I am trying to layout a form split across two columns. Is
    this possible, tables or divs?
    Test
    Page Here
    My test form only submits the fields on the right:
    Phone:
    Email:
    How did you here about us?
    Rich

    Joey,
    Gonna sound dim here...what where?
    <div class="form1">
    <table width="640" height="239" border="0"
    cellpadding="0" cellspacing="0">
    <tr>
    <td width="320" valign="top"> Name:
    <input type="text" name="t1" size="36" />
    <br />
    Company:
    <input type="text" name="t4" size="36" />
    <br />
    Address:
    <p><span class="Roman9px">
    <textarea rows="4" name="st"
    cols="35"></textarea>
    </span> </p>
    Your message or enquiry details:
    <p><span class="Roman9px">
    <textarea rows="4" name="t5"
    cols="35"></textarea>
    </span></p>
    </td>
    <td width="320" valign="top"><form method="post"
    action="SubmitForm.asp">
    <p></p>
    Phone:
    <p>
    <input type="text" name="t2" size="36" />
    <br />
    Email: </p>
    <p class="bold">
    <input type="text" name="t3" size="36" />
    </p>
    <p>
    <label>How did you here about us?<br />
    <select name="t6" id="t6">
    <option value="None Selected"
    selected="selected">Please Select</option>
    <option value="Internet Search">Internet
    Search</option>
    <option value="Advertising">Advertising</option>
    <option
    value="Recommendation">Recommendation</option>
    </select>
    </label>
    </p>
    <p class="Roman9px"> </p>
    <p class="Roman9px">
    <input type="submit" class="Roman10px" value="Submit"
    />
    </p>
    </form>
    </td>
    </tr>
    </table>
    </div>
    Rich

  • Inserting a text in textarea at specific row n column.

    hi,
    how to insert a string in a textarea at a particular row and column.
    plz reply
    thanks
    suresh.

    Then go ahead and do that :-)
    I'm not sure what the problem is. There are a number of ways to find the correct line, including (a) String.split() (b) Calling String.indexOf() in a loop and counting your way to the line in question, and (c) Tokenizer. I'd probably go with (b) because it saves you from taking out other lines of the text than the one you need to modify. Use String.substring() to take out (1) all the lines before the line to be inserted in (if any) (2) the line to be inserted in, and (3) the lines after that line (if any), and again use substring to take out the parts of the line before and after the inserted text.
    Am I helping you? If there's still something you don't get, exactly what is is?
    Yours, Ole

  • Loading text to textArea control

    I'm planing to load huge text document to textArea for
    editing so I need to find a way to page the document.For example if
    my textArea in 700px high how to split document to pages and than
    to be able to change pages of the document in that textArea?

    You'll need to determine the text metrics for some sample
    text to know approximately how much room (in pixels) a single line
    of text will hold. Then you can determine how many lines 700 pixels
    can hold. But since the TextArea does word-wrapping, it may be hard
    to determine exactly where the break should come, but you ought to
    get close.
    Check the Flex 2 doc for these topics:
    flash.text.TextLineMetrics
    flash.text.TextField
    mx.core.UITextField

  • Counting Lines in TextArea

    I need a way to count the lines the result from a text area's
    word wrap.
    In otherwords if I have a TextArea that's 150px wide and I
    put a string like:
    Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus
    neque, id pulvinar odio lorem non turpis.
    If the wrapping causes it to give me:
    Morbi commodo, ipsum sed pharetra
    gravida, orci magna rhoncus neque, id
    pulvinar odio lorem non turpis.
    I want to know that the result is 3 lines and they are ....
    Is this possible??... Is it something in TextLineMetrics??...
    Any help or possible work arounds would be great. Thanks in
    advance.

    Unfortunately I've not gotten very far with it... The closest
    I've found to a solution at this point would be to use the
    textWidth property to do calculations on when it should wrap...
    You would basically split into an array of words and add word
    by word calculating if it should wrap. The problem would be using
    the same rules as the TextArea (or at least making it look like you
    were )..
    I guess you could also split it as they're typing (change
    event) and split and manually add line breaks and then split by
    line breaks at the end.... make sense ?..
    Not sure .. but that's about as far as I've thought through
    it, not actually tried it though.

  • Is there any maxLine or maxRow in TextArea?

    Hi All,
    I need to restrict the number of lines entered in a TextArea
    control. The TextArea control doesnot have any property that can
    control the number of lines keyed in. Also the TextArea I need to
    use has the wrodWrap property set to true so I can not split the
    text by '\n' to calculate number of lines.
    Is there any hidden property or easy method etc. using which
    I may set the maximum number of lines for a TextArea control in a
    given context.
    Regards,
    Paromita

    ***Correction***
    The other way to do this is to choose About this Mac under the Apple menu.  When the window appears, click on More Info, and then choose Storage from the selection of tabs at the top.

  • PTax ded Twice incase of WPBP SPLIT (Mid month Transfer)

    Hi Friends:
    In SAP, whenever an Employee transfers from one state to another then system deducts P Tax Twice in that Payroll Period and this is a standard behaviour. (Due to two Splits and two regions)
    Ex: 1- 15 in MH and 16 to 30 in AP then P tax of MH is deducted for 1-15 days GROSS and P Tax of AP deducted for GROSS on 16 to 30.
    Now, i want to deduct only the P Tax for the Last split record in that Payroll Period. That is P tax for Extire GROSS to be deducted based on AP Region slab.
    Has anyone faced this scenario/ issue. Any Exits/ BADI's available to achieve this?
    regards,
    Srikanth

    Hi
    If you want to differ from the standard calculation then you can use the BADI
    HR_IN_CALC_PTX_BASIS
    Regards
    Sumit Pradhan

Maybe you are looking for

  • PC has Adobe 8 Pro, Adobe 9 Reader, cannot edit PDF tab in Properties

    Hey all, I have a user with the above configuration.  Even though I told windows to open pdfs with the adobe 8 pro, the PDF tab in properties after right clicking the file is grayed out and cannot be edited, just like a pc with only reader on it. Any

  • Importing SCA Via CMS

    Hi, Quick question regarding importing SCA's into a runtime enviornment via CMS. Lets assume that ACTIVITY-A was checked in, activited, deployed into development, QA, assebled and now waiting for import into production. Before i import ACTIVITY-A int

  • Mac Book Pro 17" 2006 version won't pick wireless signal with Airport update 7.5.2 and later.

    My 2006 old 17" Mac Book pro is won't connect to Airport Extreme older version with update 7.5.2 and also with 7.6.2.  In fact if I implement that update airport extreme will transmit over channel 100 which my Mac pro is unable to pick.  Any advise ?

  • Installing Reader & Flash

    I've spent the past couple weeks trying to install Adobe CS3--running the Adobe cleaner, ccleaner, uninstalling ALL my Adobe software, deleting my Adobe directories from my program files folder, changing virus & firewall settings and nothing seems to

  • Error while GR

    Dear All , I just faced a problem in Testing client while doing GR for a production order .ie while doing MB31 101 movement type . Error Msg : "  For object RF_BELEG Company code (XYZ),  number range interval 21 does not exist FBN1    " Regards W>A E