Click a row in jTextArea and get the content of the row.

I have an array of strings display in a textarea, once a user click on a row, i will like to display the content of the clicked row. I am new in java swing. how should i achieve it? thank you all!!

Working example with CaretListener:
package org.apex.sunforums;
import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
* TextAreaLineSelectionTest.java
* @author mrityunjoy_saha
* @version 1.0
* @since Apex 1.2
public class TextAreaLineSelectionTest {
    public void createUI() {
        final JFrame frame = new JFrame("TextAreaLineSelectionTest");
        frame.setSize(400, 400);
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(2, 1));
        final JTextArea textField = new JTextArea(
                "Hello\nThis is a test class.\nTo show line selection\nType some text and see the magic.",
                10, 20);
        JScrollPane scroll = new JScrollPane(textField,
                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        final JLabel display = new JLabel();
        textField.addCaretListener(new CaretListener() {
            public void caretUpdate(CaretEvent e) {
                String lineText = "";
                try {
                    int dot = e.getDot();
                    int rowStart = Utilities.getRowStart(textField, dot);
                    int rowEnd = Utilities.getRowEnd(textField, dot);
                    lineText = textField.getDocument().getText(rowStart,
                            (rowEnd - rowStart));
                } catch (BadLocationException ex) {
                    ex.printStackTrace();
                display.setText(lineText);
        panel.add(scroll);
        panel.add(display);
        frame.getContentPane().add(panel);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    public static void main(String[] args) {
        final TextAreaLineSelectionTest test = new TextAreaLineSelectionTest();
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                test.createUI();
}Thanks,
Mrityunjoy

Similar Messages

  • How do I get iTunes 11 to work as the old iTunes did in this respect: after playing a song in one playlist, I click on another playlist, highlight a song, press play, and get the result of that song playing & that playlist continuing?

       How do I get iTunes 11 to work as the old iTunes did in this respect: after playing a song in one playlist, I click on another playlist, highlight a song, press play, and get the result of that song playing & that playlist continuing?  As it goes now, one clicks on the song in the new playlist where the arrow is and then chooses 'Play Song Next.'  So, it plays next, but then the song after that is back in the old playlist.  I want to use iTunes smoothly without the extra clicks I've had to do in order to get the playlist to continue.  This is music for background while I play the violin at restaurants, and extra clicks and hassle is quite unappreciated, especailly since it worked fine in the previous iTunes.
       Thanks.

    At the top of the playlist where it shows the playlist title and the number of songs, there are two icons. Click the "play" triangle to add the entire playlist to "Up Next", or the "shuffle" symbol to do the same thing but in random order. But the currently playing track will stop playing, and all the songs in "Up Next" will be removed (replaced by the ones from this playlist).
    If you hold down the "option" key while clicking those icons, the currently playing song will continue playing, and the new playlist will be added to "Up Next" (above the songs that were already there).

  • App Store says update available for iPhone app. Try to install and get the message "the item you are trying to buy is no longer available" for three apps in a row.

    App Store says update available for iPhone app. Try to install and get the message "the item you are trying to buy is no longer available" for three apps in a row. Even when I go to the specific app and press Update, the update begins to install then aborts with this error message.iPhone 3GS running iOS 5.1.1. Also very long delay typing each keystroke in this message.

    That error message is usually indicative of a problem with the App Store. If you look through the forums, you'll see that a number of people are experiencing the problem. Try again tomorrow.

  • No matter where I click a black box appears and on the left side a black box telling me where my cursor is at the moment. How do I get rid of those black boxes?

    No matter where I click a black box appears and on the left side a black box is telling me where the cursor is at the moment. How do I get rid of it?

     ▹ System Preferences ▹ Universal Access ▹ Seeing ▹ VoiceOver: Off

  • Hi, i'm trying to download the Lightroom 6 stand alone version and get the following message right after a click the checkout box: "The account was registered for a different country. Please sign out and sign in using an existing account for this country.

    Hi, i'm trying to download the Lightroom 6 stand alone version and get the following message right after a click the checkout box: "The account was registered for a different country. Please sign out and sign in using an existing account for this country." I'm in Namibia and tried to change my country from Africa to USA but still the same problem. TIA

    Hi Annen,
    Please refer the following forum thread.
    Trying to purchase trial period in different email address - error message "Error in Your Order The account was registered for a different country. Please sign out and sign in using an existing account for this country. Ok"
    Regards,
    Sumit Singh

  • Bind Variable in SELECT statement and get the value  in PL/SQL block

    Hi All,
    I would like  pass bind variable in SELECT statement and get the value of the column in Dynamic SQL
    Please seee below
    I want to get the below value
    Expected result:
    select  distinct empno ,pr.dept   from emp pr, dept ps where   ps.dept like '%IT'  and pr.empno =100
    100, HR
    select  distinct ename ,pr.dept   from emp pr, dept ps where   ps.dept like '%IT'  and pr.empno =100
    TEST, HR
    select  distinct loc ,pr.dept   from emp pr, dept ps where   ps.dept like '%IT'  and pr.empno =100
    NYC, HR
    Using the below block I am getting column names only not the value of the column. I need to pass that value(TEST,NYC..) into l_col_val variable
    Please suggest
    ----- TABLE LIST
    CREATE TABLE EMP(
    EMPNO NUMBER,
    ENAME VARCHAR2(255),
    DEPT VARCHAR2(255),
    LOC    VARCHAR2(255)
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (100,'TEST','HR','NYC');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (200,'TEST1','IT','NYC');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (300,'TEST2','MR','NYC');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (400,'TEST3','HR','DTR');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (500,'TEST4','HR','DAL');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (600,'TEST5','IT','ATL');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (700,'TEST6','IT','BOS');
    INSERT INTO EMP (EMPNO,ENAME,DEPT,LOC) VALUES (800,'TEST7','HR','NYC');
    COMMIT;
    CREATE TABLE COLUMNAMES(
    COLUMNAME VARCHAR2(255)
    INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('EMPNO');
    INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('ENAME');
    INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('DEPT');
    INSERT INTO COLUMNAMES(COLUMNAME) VALUES ('LOC');
    COMMIT;
    CREATE TABLE DEPT(
    DEPT VARCHAR2(255),
    DNAME VARCHAR2(255)
    INSERT INTO DEPT(DEPT,DNAME) VALUES ('IT','INFORMATION TECH');
    INSERT INTO DEPT(DEPT,DNAME) VALUES ('HR','HUMAN RESOURCE');
    INSERT INTO DEPT(DEPT,DNAME) VALUES ('MR','MARKETING');
    INSERT INTO DEPT(DEPT,DNAME) VALUES ('IT','INFORMATION TECH');
    COMMIT;
    PL/SQL BLOCK
    DECLARE
      TYPE EMPCurTyp  IS REF CURSOR;
      v_EMP_cursor    EMPCurTyp;
      l_col_val           EMP.ENAME%type;
      l_ENAME_val       EMP.ENAME%type;
    l_col_ddl varchar2(4000);
    l_col_name varchar2(60);
    l_tab_name varchar2(60);
    l_empno number ;
    b_l_col_name VARCHAR2(255);
    b_l_empno NUMBER;
    begin
    for rec00 in (
    select EMPNO aa from  EMP
    loop
    l_empno := rec00.aa;
    for rec in (select COLUMNAME as column_name  from  columnames
    loop
    l_col_name := rec.column_name;
    begin
      l_col_val :=null;
       l_col_ddl := 'select  distinct :b_l_col_name ,pr.dept ' ||'  from emp pr, dept ps where   ps.dept like ''%IT'' '||' and pr.empno =:b_l_empno';
       dbms_output.put_line('DDL ...'||l_col_ddl);
       OPEN v_EMP_cursor FOR l_col_ddl USING l_col_name, l_empno;
    LOOP
        l_col_val :=null;
        FETCH v_EMP_cursor INTO l_col_val,l_ename_val;
        EXIT WHEN v_EMP_cursor%NOTFOUND;
          dbms_output.put_line('l_col_name='||l_col_name ||'  empno ='||l_empno);
       END LOOP;
    CLOSE v_EMP_cursor;
    END;
    END LOOP;
    END LOOP;
    END;

    user1758353 wrote:
    Thanks Billy, Would you be able to suggest any other faster method to load the data into table. Thanks,
    As Mark responded - it all depends on the actual data to load, structure and source/origin. On my busiest database, I am loading on average 30,000 rows every second from data in external files.
    However, the data structures are just that - structured. Logical.
    Having a data structure with 100's of fields (columns in a SQL table), raise all kinds of questions about how sane that structure is, and what impact it will have on a physical data model implementation.
    There is a gross misunderstanding by many when it comes to performance and scalability. The prime factor that determines performance is not how well you code, what tools/language you use, the h/w your c ode runs on, or anything like that. The prime factor that determines perform is the design of the data model - as it determines the complexity/ease to use the data model, and the amount of I/O (the slowest of all db operations) needed to effectively use the data model.

  • HT201272 Hello there,I delete my scruff application on the 8/05/13. Receipt N: 184052577343. And I was charged ammount of £ 16.99on the 15/05/13. I t's a Subscription Renewal. How can I stop it and get the refund of this ammount back on my account? Thank

    Hello there,I delete my scruff application on the 8/05/13. Receipt N: 184052577343. And I was charged ammount of £ 16.99on the 15/05/13. I t's a Subscription Renewal. How can I stop it and get the refund of this ammount back on my account? Thank you!!

    There are instructions on this page for managing and stopping auto-renewing subscriptions (deleting an app won't stop it) : http://support.apple.com/kb/HT4098
    In terms of a refund, what does it say on the app's description page in the store (a lot say that refunds aren't given) ? But you can try contacting iTunes Support and see if they will refund or credit you : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • I bought a gift card, but it hasn't shown up in my e-mail after 1 hour.  How can I find it and get the credit on my account?

    I bought an iTune gift card for myself and sent it to my e-mail address.  I have waited over an hour and the e-mail showing the gift card has not arrived.  How do I find it and get the credit put into my iTunes account so that I can buy some music?

    Oh hold on - sudden development!
    I panicked and force-shut down my computer because it froze after I clicked on the 'Reset Cache' option, then I logged back on and noticed the Cloud symbol next to the missing song. I clicked it, and it's finally downloaded properly! <3
    Mate, thank you so much for helping me out! xxx

  • I'm trying to download the latest version of iTunes and get the message "There is a problem with this Windows Installer package. A program required for this install to complete could not be run." I have no clue what to do with this.

    I'm trying to download the latest version of iTunes and get the message "There is a problem with this Windows Installer package. A program required for this install to complete could not be run." I have no clue what to do with this to resolve the issue. Thanks for any help!

    Repair your Apple software update.
    Go to START > ALL PROGRAMS > Apple Software Update. If it offers you a newer version of Apple Software Update, do it but Deselect any other software offered at the same time. Once done, try another iTunes install
    If you don't find ASU, go to Control Panel:
    START > CONTROL PANEL/ > Add n Remove Programs, highlight ASU and click CHANGE then REPAIR

  • R/3 job and get the details of variants like (from and to)

    Hi,
    How to find R/3 job and get the details of variants like (from and to) for that job.
    the job is extraction job and running for 4 hours in R/3 once atfer this job completes BW job will start executing. Now i have to analyse R/3 job that how many years of data it is extracting (from, to) and other useful information why it is taking time for 4 hours.
    Please let me know what transaction i have to use and how to check this information in R/3 side.
    Thanks,

    Hi........
    Go to SM37 >> select the job >> Click on Job log.........Check there whether u r getting any Clue or not...........Is this load is through PSA..........? if so check the records of the First data packet...........then the Last data packet............from there u can get some idea..................
    Also u can check the data in the Extractor.......is it a full load?.............Go to RSA3 >> Execute..........there check the data........
    Is it a LO datasource ? if so................Go to LBWE >> Click on maintenance link for your datasource........>> Here in the Right pane u can see the Structute associated with that Datasource ...........If u remove MC from those structure name............u will get the table name..............In those tables also u can check the data...............there should be some data field.............from where u can get some idea.........
    If ur Extractor is extracting data using some Function Module.............then open the datasource using RSA2.............there double click on the Exrtractor..............u will get the function module.................u can try to analyze the function module............
    For Variants..................select the job >> click on Step in the top >> then Go to in the top >> Variant..............but I don't think this will help u............this will tell u that this Extraction job is part of which chain or IP......
    Regards,
    Debjani..........

  • Lost all photos on my iPhoto and get the ERROR WRITING TO DISK when trying to reload from Time Machine. iPhoto cannot import your photos because there was a problem writing to the volume containing your iPHOTO LIBRARY  . Looking for solution.

    Lost all photos on my iPhoto and get the ERROR WRITING TO DISK when trying to reload from Time Machine. iPhoto cannot import your photos because there was a problem writing to the volume containing your iPHOTO LIBRARY  . Looking for solution.

    Problems such as yours are sometimes caused by files that should belong to you but are locked or have wrong permissions. This procedure will check for such files. It makes no changes and therefore will not, in itself, solve your problem.
    First, empty the Trash, if possible.
    Triple-click anywhere in the line below on this page to select it, then copy the selected text to the Clipboard by pressing the key combination command-C:
    find ~ $TMPDIR.. \( -flags +sappnd,schg,uappnd,uchg -o ! -user $UID -o ! -perm -600 \) 2>&- | wc -l | pbcopy
    Launch the built-in Terminal application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Terminal in the icon grid.
    Paste into the Terminal window (command-V). The command may take a noticeable amount of time to run. Wait for a new line ending in a dollar sign ($) to appear.
    The output of the command will be a number. It's automatically copied to the Clipboard. Please paste it into a reply.
    The Terminal window doesn't show the output. Please don't copy anything from there.

  • I want to de-install mac-excel test version and get the error message: you have not the privileges to de-install. Please login with the Mac-OS account you have installed mac-excel originally'. I don't know this account anymore. I am sysadm

    I want to de-install mac-excel test version and get the error message: 'You have not the privileges to de-install. Please login with the Mac-OS account you have installed mac-excel originally'. I don't know this account anymore. Possibly it does not exist anymore. anybody out there who can help ?

    Hi, I may suggest to activate the root account and try the uninstall process from that account. To do so, you have to:
    Go to System Preferences a open up the Users pane;
    On the left side of the pane, you shuold see Login Options;
    Enabled editing option clicking on the lock (it will ask your password);
    Once the pane is enabled, you should see something like Server Account Network (sorry my OS is in italian, so I don't exactly know the right translation), and right next to it a button;
    Click on that button, and a new pane shows up. Click on Open Directory Utility, and on the upper bar of OS X click on Edit;
    Select Enable Root Account (you can set a password, or not);
    Done that, you should log out and when the login window show up, type on the user field "root" and the password you choose;
    Theorically, from this account you will be able to unistall the application.
    After completing your task, I reccomend you to disable the root account, just by loggin in your personal account and repeating the steps I described before. Hope it helps

  • I cannot install adobe reader. I get so far and get the message "Error 1324. The oath All folders or the volume is invalid. Please enter it again" can you help?

    i cannot install adobe reader. I get so far and get the message "Error 1324. All folders or the volume is invalid. Please enter it again" can you help?

    We need to know if any registry settings are causing this error.  Please follow these instructions:
    from Windows Start | Search: type regedit and hit Enter; you will see a window like this
    now click on the little arrow ▹ left from HKEY_CURRENT_USER
    Next click the arrow ▹ beside Software, then Microsoft, then Windows, then CurrentVersion, then Explorer, then click on User Shell Folders
    all entries on the right side should start with %USERPROFILE%
    If you have anything different, this may be the cause for the install failure.
    Now you need to repeat the same thing for another key:
    ▹ HKEY_LOCAL_MACHINE ▹ Software ▹ Microsoft ▹ Windows ▹ CurrentVersion ▹ Explorer ▹ User Shell Folders
    Here all entries should start with %PUBLIC% or %ProgramData%.  If you have anything different, this may also be the cause for the install failure.

  • I have Photoshop cc on creative cloud but would like to add lightroom. Can I cancel my current membership and get the photography plan which would be cheaper? thanks

    I have Photoshop cc on creative cloud but would like to add lightroom. Can I cancel my current membership and get the photography plan which would be cheaper? thanks

    yes.
    contact adobe support by clicking here and, when available, click 'still need help', https://helpx.adobe.com/contact.html

  • Attempted to create a slideshow (version 9.3) and get the dreaded twiling ball that will not go away; iphoto locked up when open.  how do I get rid of the ball.  Have forced quit seveal times and opens with the ball p

    Attempted to create a slideshow (version 9.3) and get the dreaded spinning ball that will not go away; iphoto locked up when open.  how do I get rid of the ball.  Have forced quit seveal times and opens with the spinning ball.

    Make a temporary, backup copy if you don't have a backup copy of the library (select the library and type Command+D) and  apply the two fixes below in order as needed:
    Fix #1
    Launch iPhoto with the Command+Option keys held down and rebuild the library.
    Since only one option can be run at a time start with Option #1, followed by #3 and then #4
    Launch iPhoto and try again.
    Fix #2
    Using iPhoto Library Manager  to Rebuild Your iPhoto Library
    Download iPhoto Library Manager and launch.
    Click on the Add Library button, navigate to your Home/Pictures folder and select your iPhoto Library folder.
    Now that the library is listed in the left hand pane of iPLM, click on your library and go to the File ➙ Rebuild Library menu option
    In the next  window name the new library and select the location you want it to be placed.
    Click on the Create button.
    Note: This creates a new library based on the LIbraryData.xml file in the library and will recover Events, Albums, keywords, titles and comments but not books, calendars or slideshows. The original library will be left untouched for further attempts at fixing the problem or in case the rebuilt library is not satisfactory.
    OT

Maybe you are looking for