Select part of jtextarea content over a button click

Hi,
i would like to do something quite simple, but i don't manage to do it and don't understand why my code doesn't work :s
Actually, i would like to select a part of the text contained in a jtextarea when the user clicks over a jbutton ; here is my code:
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class BasicFrame extends JFrame implements ActionListener {
     private static final long serialVersionUID = 1L;
     private JTextArea jta;
     private JButton b;
     public BasicFrame() {
          this.setSize(400,400);
          this.getContentPane().setLayout(new GridLayout(2,1));
          this.getContentPane().add(this.jta = new JTextArea());
          this.getContentPane().add(this.b = new JButton("foo"));
          this.b.addActionListener(this);
          this.setVisible(true);
          this.setDefaultCloseOperation(EXIT_ON_CLOSE);
          this.setLocationRelativeTo(null);
     @Override
     public void actionPerformed(ActionEvent arg0) {
     //     this.jta.select(2, 5);
          this.jta.setCaretPosition(2);
          this.jta.moveCaretPosition(5);
     public static void main(String [] args) {
          BasicFrame bs = new BasicFrame();
          bs.jta.setText("this crap won t work");
}notice that this solution doesn't work, but if the "select" (or setcaret+movecaret) instruction is put directly in the main, it will work
Suggestions? Advices? Answers?
Thanks in advance!

the code does work, problem is the textArea needs the focus to show the highlighted (selected) text,
but when you click the button, focus goes to the button.
run the code then tab (not click) to the textArea, you will see the text selected
simple fix is to add this line at the end of the constructor
b.setFocusable(false);

Similar Messages

  • Embedding a text file to display its contents on a button click

    I am quite a beginner in this platform. I have text file with me and I want to display its contents to the user(Read Only) on a button click event in my app.(using C#)
    I wish to know how to link/ embed this text file to my app and once it is embedded, how to deploy the file reading.
    P.S. i would really appreciate it if you can provide some sample code.

    thx Rob..plz check this piece of code..
    namespace Syllabus
        public partial class MainPage : PhoneApplicationPage
            public MainPage()
                InitializeComponent();
            private async Task Button_Click(object sender, RoutedEventArgs e)
                try
                      System.IO.Stream src = Application.GetResourceStream(new Uri("Syllabus;vbu.txt", UriKind.Relative)).Stream;
                      string text;
                      using (StreamReader sr = new StreamReader(src))
                          text = sr.ReadToEnd();
                      TextBlock t = new TextBlock();
                      t.Text = text;
                  catch
                      MessageBox.Show("File Not Found");
    On running the code always chokes within the constructor itself ...what's wrong?

  • Selecting all rows in ALV on a button click

    Hi Experts
    Hi,
    I have a dynamic ALV table. I also have a button 'Select All Rows'. On clicking the button I want all the rows in the ALV table selected which is done by using set_selected method at the context node.
    All the rows in the alv is selected after clicking select_all except for the first row.
    Need your inpts to solve the same.
    Regards
    Karthick

    Use the folowing code
    *... get model
      data:
        lr_model type ref to cl_salv_wd_config_table.
      lr_model ?= me->r_model.
    *... get columns
      data:
        ls_column type salv_wd_s_column_ref,
        lt_column type salv_wd_t_column_ref.
      lt_column = lr_model->if_salv_wd_column_settings~get_columns( ).
      data:
        l_selected type abap_bool.
      loop at lt_column into ls_column.
        l_selected = abap_false.
        read table value transporting no fields with key column = ls_column-id.
        if sy-subrc eq 0.
          l_selected = abap_true.
        endif.
        try.
            me->if_salv_bs_model_column~set_selected(
              column = ls_column-id
              value = l_selected ).
          catch cx_salv_bs_sc_object_not_found.             "#EC NO_HANDLER
        endtry.
      endloop.

  • Smooth Content Transition on Button Click?

    Hello,
    I am creating a website with a content box and 4 buttons which activate 4 different pages of content. I would like the content box to resize smaller on one page when activated by a button and resize back to normal when clicked on any other button. I figure I will use a shape tween to resize the box to avoid distortion. So, how do I program each button to transition properly if the page with the smaller box is displayed?
    Thanks

    All Tweens are coded pretty much the same, where you specify the starting value of the property of the object and the final value it should reach for that property at the end of the Tween.
    example = Tween(instanceName, propertyToChange, easingMethod, startingValue, finalValue, changeDuration, durationBasis (secs or frames))
    Since you're not really scaling the area, just reducing the width (I think), you don't have to Tween the scale property, but can tween the width property instead.
    So if your clicking a button that's related to a display that's gonna be 960 wide, then that's the final value that you assign.  If it's gonna be the 760 display, then that's the value you assign.
    If you did want to go with tweening the scale, and you end up picking the 960 to represent the 100% scale, you want to specify the percent scale for the finalValue (100x760/960 = 79.2%)... so the finalValue would be either 1.0 or 0.792

  • Select System's Local Directory Path on Button Click

    Hi All,
    I Have a case where a use needs to give a directory path in
    TextInput.
    I want to replace this with a Browse Button, which when
    clicked need to open a Browe popup to select a Systems Directory
    and the selected Directory Name is written into the TextInput.
    This is the same way that we do in HTML to select a File from
    System.
    How can i achieve this with Flex ?
    Regards,
    Madan N

    Because of security restrictions, the only access you have to
    the local file system is via the FileReference class, which is used
    to upload/download files. Note, you cannot use it to get the file
    path, security again.
    An AIR app does not have this restriction.
    Tracy

  • Change Button content when Radio button clicked...

    Within my BSP code I have an OnClientClick event against the Radio button tag.
    What I need to do is to have some kind of Javascript that changes the context (text) or colour of a button if the Radio button is clicked.
    I know very little of how to achieve this and would relish any guidance about how I can get this to work.
    I understand that I need to use a reference/handle to the button and change it's values via javascript, but how can I embed this code into my BSP code, what code do I use, and more importantly how can I obtain this reference/handle on the buttion?.
    Jon

    Hi Jon,
    below an Example to do this
    (due to security forum restriction replace scrip t with script and o nclick with onclick)
    <html>
    <head>
    <scrip t>
    function change_button_text(v_object){
    var button = document.getElementById("id_button");
    var new_text = v_object.value + ' Clicked!';
    if (button.childNodes[0])
            button.childNodes[0].nodeValue=new_text;
        else if (button.value)
            button.value=new_text;
    </scrip t>
    </head>
    <body>
    <form>
    <input type="radio" name="***" value="male" o nclick="change_button_text(this)"/> Male<br />
    <input type="radio" name="***" value="female" o nclick="change_button_text(this)"/> Female
    </form>
    <button id="id_button">Button Text</button>
    </body>
    </html>
    Edited by: alessandro spadoni on Apr 28, 2011 9:56 AM

  • How to hide bounding box over selected parts in 3d annotation?

    Please let me know if it is possible to hide bounding box over selected parts in 3d annotation?

    Have you unchecked the Display Bounding Box in the Options menu on the left side of the Model Tree toolbar? Select the down arrow next to the menu icon under Model Tree to see the Options menu.

  • Is there a way to place markers in a multicam clip, and then have those same markers carry over when you select part of the clip for a project (or various projects)?

    Is there a way to place markers in a multicam clip, and then have those same markers carry over when you select part of the clip for a project (or various projects)?

    Thanks. Beforehand, I was double clicking on the multicam clip and forced to make a marker on either the Cam A or B. I realize now that I can do it in the Event Browser. THANK YOU.
    Considering I may create >20 markers per clips for around 10 different interviews, I wish there was a way to bring the Event Brower to the bottom half of the FCPX windows, to resemble the screen orientation when I'm working in an actual project (one could do this in iMovie), and this way the markers could be listed to the left without having all the other event clips around it. Is that clear? Is that possible?

  • Zooming in/out while selecting parts of the audio file?

    The company I am with use Cool Edit 2000 for our audio editing, in Cool Edit it allows you to click and drag to select parts of files while you are doing this you can use the mouse wheel to zoom in and out. This helps for when you need to zoom in at the beginning of the sound and drag to the beginning of the file to delete any unwanted sound or lack of sound, zooming out while doing this allows you to do it very quickly.
    I have tried the trial version of Adobe Audition 3 and I was not able to do this.
    My questions are:
    1. Was this feature removed?
    2. If not how do I enable this feature.
    This feature will determine weather or not my company will purchase this software. Thanks for the time to answer my questions.

    zooming isn't a problem its zooming out while dragging over the file to select it, basically what I am doing is zooming into the beginning or end of a file selecting the precise beginning or ending holding the left mouse button and dragging left or right while I am doing this I am zooming out to make it select what I need faster and deleting those areas away.
    I just read about the top/tails view, I am going to check it out see if this helps.

  • Active Content W/ Rollover Buttons Help

    I'm pretty new to web design, and I've been using dreamweaver
    to create webpages. My problem is I have some rollover buttons I
    made in fireworks and imported to dreamweaver as fireworks html,
    and in IE7 I get the "activate active content" error. I installed
    the dreamweaver 8.2 update, thinking that would fix it, but
    although I can see that the extension to automatically change the
    code so it'll work in IE in my preferences, the option to do so
    never comes up. I read somewhere that it doesn't support image
    tags, which I think mine are. So my question is: is there an easy
    fix for this other than the update, or at least a fix for a
    beginner who doesn't know javascript? I've googled to my heart's
    content, and everything I've come across has been over my head.
    Please someone help me with this. I can also post the code if
    that'll help, just let me know. Thanks in advance!
    Hiram

    I'm not quite sure what the actual issue is here but several
    things seem to
    be confused.
    My problem is I have some rollover buttons I made in
    fireworks and
    > imported to dreamweaver as fireworks html, and in IE7 I
    get the "activate
    > active content" error.
    Buttons made in Fireworks and activated with Javascript are
    not related to
    the "activate active content" issue.
    Do you have some Flash or other active content on your page
    which is
    triggering the "click to activate" which you're confusing
    with your
    Fireworks buttons?
    I installed the dreamweaver 8.2 update, thinking that
    > would fix it, but although I can see that the extension
    to automatically
    > change
    > the code so it'll work in IE in my preferences, the
    option to do so never
    > comes
    > up. I read somewhere that it doesn't support image tags,
    which I think
    > mine
    > are.
    I don't quite follow this part.
    So my question is: is there an easy fix for this other than
    the update, or
    > at least a fix for a beginner who doesn't know
    javascript?
    Web content driven by Javascript is not active content so I'm
    not sure what
    the issue is or what needs fixing.
    Can you post a link to your page?
    Regards
    John Waller

  • I can not print only a selected part of a page

    I have reset the print.print_printer and still can't print only the selected part of a page. I highlight what I want to print and use control P to get to the printer setup. Then I click the selection button and then OK. The preview screen shows what would print but the page has blank space above what was selected. This has only started to happen since the upgrade to FF 11.0. I have tried the same operation using IE and it works fine. please, is there a fix for this??

    Hi jweigh,
    This is a known bug. You should take a look at this thread:
    https://support.mozilla.org/en-US/questions/923294
    See the last post by Cww.
    Hopefully this helps!

  • How to select parts of a clip in a project in iMovie 10.0.1

    In the previous version of iMovie partial clip selection was possible just by dragging a left click over a clip within the movie clip project. Now in iMovie 10.0.1 the same left click dragging over the clip it's just for moving the entire clip to another position.
    The only place where I was able to select a portion of any given clip is in the Event window, on the imported clips section.
    Is it possible to select portions of a clip that it's already embeded into a movie clip project?
    Thanks to all for your answers.

    Further to Karsten's advice, position the skimmer (or the playhead) within the clip where you want to start your selection. Now click and hold down the mouse button (or trackpad). As you do this you will firstly see that the whole clip is highlighted with a thin yellow border. While still holding down on the click, you will then see a wider yellow vertical line on the clip, being the start point - drag this to mark your selection. Release the mouse button (or trackpad) once you've reached the end point of your selection.
    If you wish to delete the segment that you've highlighted, just press the Delete key on the keyboard. Otherwise perform whatever other actions are available from the Modify menu item.
    The key is to not release the mouse button after clicking on the clip. The selection border will appear within a millisecond after clicking and holding.
    John
    Message was edited by: John Cogdell

  • Problem w Plug-in Check page: the "Update" button for my outdated version of the WMP plugin does not do anything, and no link is indicated in the status bar when I mouse over the button.

    In Firefox, I select Tools > Add-ons > Find Updates. The Plugin Check page comes up in the browser. The entry for the WMP Plugin indicates it is out of date. I click on the "Update" button and nothing happens. When I mouse over the button, no link is indicated in the status bar (it continues to read "Done").
    The entries for the other plugins indicate they are current. When I mouse over the "Up to date" button for each of those entries, a link is indicated in the status bar.
    I am running Windows XP SP2 on a 2005 Dell Inspiron 6000 (1.6 GHz Pentium M processor, 590 MHz bus, 504 MB RAM). I have Norton Internet Security 2010 installed and running.

    See:
    * http://kb.mozillazine.org/Windows_Media_Player#Missing_plugin
    * http://windows.microsoft.com/en-US/windows/downloads/windows-media-player (see Firefox)
    * http://port25.technet.com/pages/windows-media-player-firefox-plugin-download.aspx

  • Content Player navigation buttons not working for everyone

    Hi,
    Some of the participants are experiencing the issue with Content Player navigation buttons 'Continue' , 'End Test' etc..
    We suspect it is because of the version of Java runtime environment on thier PC after eliminating the browser cache, or IE version issues.
    Could anyone please tell me what are the supported Java versions for proper functioning of LSO600 Content player?
    We are on ECC 6.0, LSO600 and SAP portal version EP7.
    Any help is highly appreciated.
    Thanks,
    Jaya

    Hello Jaya,
    java supported version is more than JRE 1.4.2._07
    and IE is IE6 and IE7
    LSO supports Java 1.4.02_07 to java 1.6
    Browsers:
    Micorsoft IE6 and IE7.
    Firefox from 2.2
    If there is more than one Java version on the pc, try forcing the browser to use a certain version of Java by going to the control panel -> Java -> in java control panel go to -> java tab -> Click view in Java Applet run time settings -> Select one of the JRE to enable it and force the browser to use this version of Java.
    Regards,
    Manny

  • Selection part of Logical Database

    I read about logical database somewhere on the net but it was not so clear. Can anyone explain to me about the selection part of the logical database???

    Logical databases are special ABAP programs that retrieve data and make it available to application programs. The most common use of logical databases is still to read data from database tables and linking them to executable ABAP programs while setting the program contents. You edit logical databases using the Logical Database Builder in the ABAP Workbench.
    However, since Release 4.5A, it has also been possible to call logical databases independently of this tool using the function module LDB_PROCESS. This allows you to call several logical databases from any ABAP program, nested in any way. It is also possible to call a logical database more than once in a program, if it has been programmed to allow this. This is particularly useful for executable programs, allowing them to use more than one logical database and process a database more than once.
    Logical databases contain Open SQL statements that read data from the database. You do not therefore need to use SQL in your own programs. The logical database reads the program, stores them in the program if necessary, and then passes them line by line to the application program or the function module LDB_PROCESS using an interface work area.
    http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db9b5e35c111d1829f0000e829fbfe/content.htm
    A logical database is a special ABAP/4 program which combines the contents of certain database tables. You can link a logical database to an ABAP/4 report program as an attribute. The logical database then supplies the report program with a set of hierarchically structured table lines which can be taken from different database tables.
    GO THROUGH LINKS -
    http://www.sap-basis-abap.com/saptab.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9bfa35c111d1829f0000e829fbfe/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9b5e35c111d1829f0000e829fbfe/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/c6/8a15381b80436ce10000009b38f8cf/frameset.htm
    /people/srivijaya.gutala/blog/2007/03/05/why-not-logical-databases
    Re: **LDB**
    www.sapbrain.com/FAQs/TECHNICAL/SAP_ABAP_Logical_Database_FAQ.html
    www.sap-img.com/abap/abap-interview-question.htm
    www.sap-img.com/abap/quick-note-on-design-of-secondary-database-indexes-and-logical-databases.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9b5e35c111d1829f0000e829fbfe/content.htm
    http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db9bb935c111d1829f0000e829fbfe/content.htm
    Logical databases are SAP standard programs that are desinged with selections screens that helps easy retrival and access of data from various tables in and efficient manner.
    You can get to know more about the logical databases from the SAP documentation or the following links.
    A logical database is a special ABAP/4 program which combines the contents of certain database tables. You can link a logical database to an ABAP/4 report program as an attribute. The logical database then supplies the report program with a set of hierarchically structured table lines which can be taken from different database tables.
    Advantages of Logical database -
    1) No need of programming for retrieval , meaning for data selection
    2) Easy to use standard user interface, have check completeness of user input.
    Disadvantages
    1) Fast in case of lesser no. of tables But if the table is in the lowest level of hierarchy, all upper level tables should be read so performance is slower.
    GO THROUGH LINKS -
    http://www.sap-basis-abap.com/saptab.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9bfa35c111d1829f0000e829fbfe/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9b5e35c111d1829f0000e829fbfe/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/c6/8a15381b80436ce10000009b38f8cf/frameset.htm
    1. A logical database is in fact
    a program only.
    2. This LDB provides two main things :
    a) a pre-defined selection screen
    which handles all user inputs and validations
    b) pre defined set of data
    based upon the user selection.
    3. So we dont have to worry about from
    which tables to fetch data.
    4. Moreover, this LDB Program,
    handles all user-authorisations
    and is efficient in all respects.
    5. tcode is SLDB
    good info about Logical Database. you can check the link.
    http://www.geekinterview.com/question_details/1506
    http://help.sap.com/saphelp_46c/helpdata/EN/35/2cd77bd7705394e10000009b387c12/frameset.htm
    Re: How to Create and Use ldb in reports?
    Re: Logical databases
    http://help.sap.com/saphelp_46c/helpdata/en/9f/db9bed35c111d1829f0000e829fbfe/frameset.htm
    Functions for displaying and changing logical databases:
    Call Transaction SE36 or
    Choose ABAP Workbench -> Development -> Programming environ. -> Logical databases
    Interaction between database program and report:
    During program processing, subroutines are performed in the database program and events are executed in the report.
    To read data from a database tables we use logical database.
    A logical database provides read-only access to a group of related tables to an ABAP/4 program.
    advantages:-
    The programmer need not worry about the primary key for each table.Because Logical database knows how the different tables relate to each other,and can issue the SELECT command with proper where clause to retrieve the data.
    i)An easy-to-use standard user interface.
    ii)check functions which check that user input is complete,correct,and plausible.
    iii)meaningful data selection.
    iv)central authorization checks for database accesses.
    v)good read access performance while retaining the hierarchical data view determined by the application logic.
    disadvantages:-
    i)If you donot specify a logical database in the program attributes,the GET events never occur.
    ii)There is no ENDGET command,so the code block associated with an event ends with the next event
    statement (such as another GET or an END-OF-SELECTION).
    1. transaction code SLDB.
    2.enter name z<ldb-name>
    3.create
    4.short text
    5.create
    6. name of root node (here Ekko)
    7. enter short text (f6)
    8.node type -> data base table.
    9.create
    10 change logical DB
    riht click on ekko and insert node
    here node name ekpo
    11.create
    12. click on selections
    13. press no Should the changed structure of Z<ldb name> be saved first.
    14.select tables which you want to join.
    15.transfer
    16 now you have to o to coding part.
    17. save
    activate.
    19.click to src code
    double click on first include and activate
    Regards
    Vasu

Maybe you are looking for