How to set focus on the last row of JTextPane

how to set focus on the last row of JTextPane?
import javax.swing.*;
import javax.swing.text.html.*;
import java.awt.*;
import java.awt.event.*;
public class MyGUITest extends JPanel implements ActionListener
{   public static void main(String[] args)
    {   SwingUtilities.invokeLater(new Runnable()
         {   public void run()
          {    JFrame f = new JFrame("My GUI");
              MyGUITest GUI = new MyGUITest();
              GUI.setOpaque(true);
              f.setContentPane(GUI);
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              f.pack();
              f.setLocationRelativeTo(null);
              f.setVisible(true);
    JTextPane txtP;
    JButton add;
    HTMLEditorKit hek;
    HTMLDocument hd;
    String txt;
    MyGUITest()
    {     this.setLayout(new BorderLayout());
     this.setPreferredSize(new Dimension(400,200));
     txtP = new JTextPane();
     txtP.setEditable(false);
     txtP.setContentType("text/html");
     txtP.setText("");
     hek = new HTMLEditorKit();
     txtP.setEditorKit(hek);
     hd = new HTMLDocument();
     txtP.setDocument(hd);
     JScrollPane sTxtA = new JScrollPane(txtP);
     add = new JButton("add");
     add.addActionListener(this);
     sTxtA.setBorder(BorderFactory.createTitledBorder(""));
     this.add(sTxtA, BorderLayout.CENTER);
     add(add, BorderLayout.SOUTH);
     new Thread(new Runnable()
     {   public void run()
         {   while(true)
          {   try
              {     Thread.sleep(100);
              }catch(InterruptedException ex)
              {     ex.printStackTrace();
              appendText("This is <b>HTML</b> text");
              //add.doClick();
     }).start();
    public void actionPerformed(ActionEvent e)
    {     txt = "<b>asd</b>";
     try
     {   hek.insertHTML(hd, hd.getLength(), txt, 0, 0, null);
     }catch(Exception ex){   ex.printStackTrace();   }
    public void appendText(String txt)
    {     try
     {   hek.insertHTML(hd, hd.getLength(), txt, 0, 0, null);
     }catch(Exception ex){   ex.printStackTrace();   }
}thanks~

anIdiot wrote:
im not sure what is the caret location...So don't youthink you should have looked for it in the API?
anyway, i want the scroll bar to scrolled down automatically when the output is displayed.
normally, the scroll bar is scrolled down automatically when a new text is inserted, but it doesnt work on this timeGo through camockr's http://tips4java.wordpress.com/2008/10/22/text-area-scrolling/
db

Similar Messages

  • How to set focus on the title of JTabbedPane

    I have created a JTabbedPane and added three JPanels to it. They are titled, say "Panel 1", "Panel 2" and "Panel 3". And each of them contains buttons and text areas. Since this app is for physically disabled users, it must provide navigation through these three tabs with keyboard operations only (i.e. without mouse clicks).
    When the title "Panel 1" gets focused, users can go to "Panel 2" by the right arrow key. When Panel 2 is brought up, however, the title "Panel 2" does not get focused. Instead the first button inside panel 2 is focused. In order for users to navigate to 'Panel 3" by the arrow key, the title "Panel 2" has to be focused. How do I set focus on the tab title?
    I have tried 'requestFocus()' on Panel 2, but it does not work. Please help me with this issue. Thanks in advance.

    I'd be quite interested to know if this can be doen as well so I thought I'd post this message to move it to the top of the board.
    Thanks.

  • How to set focus in the parent window after a JOptionPane pop up ?

    I am not able to set the focus back to a JTextField in the parent window after poping up a JOptionpane.showMessageDialog(). I tried requestfocus(),requestFocusInWindow etc......but not working. The code is given below.
    if ((encryptor.encrypt(password)).equals(configuredPasswd)) {
                        validPassword = true;
                   } else {
                        JOptionPane.showMessageDialog(saveUI,"The password entered is not correct.");
                        saveUI.getPasswdField().setText("");
    saveUI.getPasswdField().requestFocus();
    Sometimes the focus is coming to the JTextField.Sometimes it appears for a moment and then dissappears.Please give a solution

    see if this makes a difference
    if((encryptor.encrypt(password)).equals(configuredPasswd))
      validPassword = true;
    else
      JOptionPane.showMessageDialog(saveUI,"The password entered is not correct.");
      ActionListener al = new ActionListener(){
        public void actionPerformed(ActionEvent ae){
          saveUI.getPasswdField().setText("");
          saveUI.getPasswdField().requestFocusInWindow();}};
      javax.swing.Timer timer = new javax.swing.Timer(100,al);
      timer.setRepeats(false);
      timer.start();
    }

  • RFC - XI - JDBC(mapping only the last row of a record)

    Hello all,
    in a mapping response from an oracle base after a RFC call with a select statement, i have the following response :
    <StatementSelect_response>(cardinality 0..1)
    <row1>(cardinality 0..unbounded)
    <field1>1</field1>
    <field2>2</field2>
    </row1>
    <row2>
    <field1>3</field1>
    <field2>4</field2>
    </row2>
    </statement>
    i have to map those fields in a RFC_response like :
    <RFC_response>(0..1)
    <field1>
    <field2>
    </rfc _response>
    Problem : I only need to send back to the rfc_response the last records of my StatementSelect_response in order to have the following message :
    <RFC_response>
    <field1>3
    <field2>4
    </rfc _response>
    How can i select only the last row of my records plz ?
    Thanks by advance

    VJ wrote:>
    > Hi,
    >
    > public void LastRow(String[] a,ResultList result,Container container){
    >
    > int len = a.length();
    > Result.addValue(a\[len-1\]);
    >
    > }
    VJ,
    Please don't confuse him. If you want to update the thread, let me leave it aside.Coz it shouldn't cause him trouble. Can u check a.length() is correct? it has to be a.length, isn't it?
    We all here to help others, not under any motivation of compete..
    Sorry, if I hurt you..
    raj.

  • How to set focus on a input field in a selected row of a table?

    In a previous discussion (http://scn.sap.com/thread/3564789) I asked how to access an input (sap.m.Input) field of a selected row in a table. In the answer that was supplied I was shown how to get the items of the table. Then using the selected index to get the selected item get the cells. Then I could set editable on the proper cell(s). This worked fine.
    Now I need to set the focus on one of the fields. I tried something like this:
                var oNewLink = table.getSelectedItem();
                var oNewLinkName = oNewLink.getCells()[1];
                oNewLinkName.focus();
    But this doesn't seem to work.
    I have searched through other discussions and have seen this technique for putting focus on a field if you have its ID:
    sap.ui.getCore().byId(id_of_the_input_field).$().focus();
    In my case though I do not have an ID since the row and its cells are generated. How can I set focus on the cell of a certain row in a table?

    Hello Venkatesh. Yes that code does work. First I tried it on a table cell that was already rendered and it did work. The next time I tried it on a table row that was being added and it did not work there. So I added an on after rendering function for the table and added that code there. That did not work until I added a delay (timeout) to do a context switch before calling the focus and that worked.
    Once last thing though sometimes when I call focus on an input field (actually in a table row cell) if the field has text in it already the flashing cursor is at the beginning of the text and other times it is at the end of the text (which is the desired way). It depends on where I click in the row. Is there anyway to make sure the flashing cursor is at the end of the text when the focus is applied to a field that contains text?

  • How  to set focus on next row inputfield in table

    Hello all,
    How  to set focus on next row input field in table
    Please help.
    Thanks in advance.
    CSP

    Hi,
    use the following code
    wdThis.wdGetAPI().requestFocus(nodeElement, attribute)
    Ex:
    Provide the attribute and replace the nodeElement with that of yours
    IWDAttributeInfo attributeInfo = wdContext.getNodeInfo().getAttribute("Your attribute");
           wdThis.wdGetAPI().requestFocus(wdContext.currentContextElement(), attributeInfo);
    Regards
    Ayyapparaj

  • How do I set focus to the Browser so I can CmdKey-A and select all?

    I've searched the shortcut list for about 10 minutes and cannot find a shortcut to shift focus to the browser (by default the right-side) preferably the lower film-strip/list pane where pressing Cmd-A selects all the photos.
    Note, that if you select an album and hit Cmd-A it doesn't select all the photos in the album - if that worked I wouldn't need to set focus to the film-strip/list pane.
    There's only 1 keyboard shortcut in the "Aperture 3 Keyboard Shortcuts" guide with the word "Focus", and it's not the one I need.

    Put it this way.
    1. Select an Album
    2. Now, you want to select all photos in that album, hit Cmd-A
    You can't do (2) until I manually click in the film-strip pane.
    I want to hit 1 key, to put me in a position to select all photos immediately.
    This would also allow me to navigate using the arrow keys.
    I'm not sure I really understand how anyone would not need this.
    You click an album, you want to navigate through them (without using the mouse) ... doesn't everyone need to do this somehow?
    ** I just realized while experimenting that hitting the arrow-key actually gives focus to the film-strip in a way that allows me to hit Cmd-A.
    So it looks like the answer is to
    1. Select the Album
    2. Hit any arrow key (sometimes it already has focus, depending on what you were doing in this album last time, by the look of it)
    3. Cmd-A now works.

  • How to get the last row in a resultset or query

    Hi All
    Say If I have a complex query which returns a resultset say 15 rows. Now I want to limit the output showing only the last row.
    How can we do this

    Keep in mind Oracle does not keep "row" order as such. Unlike a graphical type db like Access, Oracle will not always give you back the results in order.
    Even if you were to use a sequence, your query is never guaranteed to give back the results in the order you are expecting. You must then give an order by statement to all queries expecting the order.
    Your definition of last row too is vague - if it is in fact the greatest amount, use the inline view suggestion. If you simply want to see the last inserted row, consider adding a last_update_date column inserting the sysdate (by a trigger perhaps). This would then allow you to see the last inserted row.
    Enjoy!

  • How to get the last row of a database table.

    HI ,
    I want to get record exactly from the last row of a database table.
    How is that possible?

    Hi,
    To fetch last record from an internal table, just do find the number of records in it and read using index.
    DESCRIBE TABLE ITAB LINES L_LINES.
    READ TABLE ITAB INDEX L_LINES.
    You can also use LOOP .. ENDLOOP but the above method is better (performance wise).
    using LOOP .. ENDLOOP.
    LOOP AT ITAB.
    **do nothing
    ENDLOOP.
    **process ITAB (Header record of ITAB).
    **after ENLOOP, ITAB will have the last record of the internal table.
    [here ITAB is internal table as well as header record.]
    But what is the requirement?
    If you are looking for the current record of an employee then you can use ENDDA = HIGH_DATE.
    My advice is to review your requirement again and try to fetch only that record which you need.
    Mubeen

  • HELP! How te retrieve the last row in MYSQL database using Servlet!

    Hi ,
    I am new servlets. I am trying to retireve the last row id inserted using the servlet.
    Could someone show me a working sample code on how to retrieve the last record inserted?
    Thanks
    MY CODE
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    public class demo_gr extends HttpServlet {
    //***** Servlet access to data base
    public void doPost (HttpServletRequest req, HttpServletResponse resp)
         throws ServletException, IOException
         String url = "jdbc:mysql://sql2.njit.edu/ki3_proj";
              String param1 = req.getParameter("param1");
              PrintWriter out = resp.getWriter();
              resp.setContentType("text/html");
              String semail, sfname, slname, rfname, rlname, remail, message;
              int cardType;
              sfname = req.getParameter("sfname");
              slname = req.getParameter("slname");
              rfname = req.getParameter("rfname");
              rlname = req.getParameter("rlname");
              semail = req.getParameter("semail");
              remail = req.getParameter("remail");
              message = req.getParameter("message");
              //cardType = req.getParameter("cardType");
              cardType = Integer.parseInt(req.getParameter("cardType"));
              out.println(" param1 " + param1 + "\n");
         String query = "SELECT * FROM greeting_db "
    + "WHERE id =" + param1 + "";
              String query2 ="INSERT INTO greeting_db (sfname, slname ,semail , rfname , rlname , remail , message , cardType ,sentdate ,vieweddate) values('";
              query2 = query2 + sfname +"','"+ slname + "','"+ semail + "','"+ rfname + "','"+ rlname + "','"+ remail + "','"+ message + "','"+ cardType + "',NOW(),NOW())";
              //out.println(" query2 " + query2 + "\n");
              if (semail.equals("") || sfname.equals("") ||
              slname.equals("") || rfname.equals("") ||
              rlname.equals("") || remail.equals("") ||
              message.equals(""))
                        out.println("<h3> Please Click the back button and fill in <b>all</b> fields</h3>");
                        out.close();
                        return;
              String title = "Your Card Has Been Sent";
              out.println("<BODY>\n" +
    "<H1 ALIGN=CENTER>" + title + "</H1>\n" );
                   out.println("\n" +
    "\n" +
    " From  " + sfname + ", " + slname + "\n <br> To  "
                                            + rfname + ", " + rlname + "\n <br>Receiver Email  " + remail + "\n<br> Your Message "
                                            + message + "\n<br> <br> :");
                   if (cardType ==1)
                        out.println("<IMG SRC=/WEB-INF/images/bentley.jpg>");
                   else if(cardType ==2) {
                        out.println("<IMG SRC=/WEB-INF/images/Bugatti.jpg>");
                   else if(cardType ==3) {
                        out.println(" <IMG SRC=/WEB-INF/images/castle.jpg>");
    else if(cardType ==4) {
                        out.println(" <IMG SRC=/WEB-INF/images/motocross.jpg>");
    else if(cardType ==5) {
                        out.println(" <IMG SRC=/WEB-INF/images/Mustang.jpg>");
    else if(cardType ==6) {
                        out.println("<IMG SRC=/WEB-INF/images/Mustang.jpg>");
    out.println("</BODY></HTML>");
         try {
              Class.forName ("com.mysql.jdbc.Driver");
              Connection con = DriverManager.getConnection
              ( url, "*****", "******" );
    Statement stmt = con.createStatement ();
                   stmt.execute (query2);
                   //String query3 = "SELECT LAST_INSERT_ID()";
                   //ResultSet rs = stmt.executeQuery (query3);
                   //int questionID = rs.getInt(1);
                   System.out.println("Total rows:"+questionID);
    stmt.close();
    con.close();
    } // end try
    catch (SQLException ex) {
              //PrintWriter out = resp.getWriter();
         resp.setContentType("text/html");
              while (ex != null) { 
         out.println ("SQL Exception: " + ex.getMessage ());
         ex = ex.getNextException ();
    } // end while
    } // end catch SQLException
    catch (java.lang.Exception ex) {
         //PrintWriter out = resp.getWriter();
              resp.setContentType("text/html");     
              out.println ("Exception: " + ex.getMessage ());
    } // end doGet
    private void printResultSet ( HttpServletResponse resp, ResultSet rs )
    throws SQLException {
    try {
              PrintWriter out = resp.getWriter();
         out.println("<html>");
         out.println("<head><title>jbs jdbc/mysql servlet</title></head>");
         out.println("<body>");
         out.println("<center><font color=AA0000>");
         out.println("<table border='1'>");
         int numCols = rs.getMetaData().getColumnCount ();
    while ( rs.next() ) {
              out.println("<tr>");
         for (int i=1; i<=numCols; i++) {
    out.print("<td>" + rs.getString(i) + "</td>" );
    } // end for
    out.println("</tr>");
    } // end while
         out.println("</table>");
         out.println("</font></center>");
         out.println("</body>");
         out.println("</html>");
         out.close();
         } // end try
    catch ( IOException except) {
    } // end catch
    } // end returnHTML
    } // end jbsJDBCServlet

    I dont know what table names and fields you have but
    say you have a table called XYZ which has a primary
    key field called keyID.
    So in order to get the last row inserted, you could
    do something like
    Select *
    from XYZ
    where keyID = (Select MAX(keyID) from XYZ);
    Good Luckwhat gubloo said is correct ...But this is all in MS SQL Server I don't know the syntax and key words in MYSQL
    This works fine if the emp_id is incremental and of type integer
    Query:
    select      *
    from      employee e,  (select max(emp_id) as emp_id from employee) z
    where      e.emp_id = z.emp_id
    or
    select top 1 * from employee order by emp_id descUday

  • How to display the last row in a table

    I have a table that is constantly updating, and I always want to see the last row. How can I get my table to auto scroll?

    Hi žabić,
    there is a property called "top left visible row". You can use it to scroll your table.
    edit:
    Maybe this is not the exact name, but you can see an example here
    Mike
    Message Edited by MikeS81 on 05-27-2010 03:57 PM

  • How do I remove the last row in a csv data file

    I would like to remove the last row of data from a csv file that I have saved.  I can identify the start byte of the last row; however, I'm not sure what tool is the best one to remove it.  Should I move the EOF?  Should I open the file up to that point then save over the old one?  Is there another way I don't know about?  I am using labview 7.1.
    Thanks

    I would use the Read Text File.  You can right-click on it and tell it to read lines.  Then Delete From Array.  Leave the index and length unwired and it will delete the last item (I noticed your code is removing the second line).  Then open the file again set to replace or create and write your data.  This method allows you to propagate your errors instead of the Write/Read Spreadsheet File handling the errors for you.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Remove last row of csv_BD.png ‏14 KB

  • How can I delete the last row of a Matrix

    Hi All,
    Does anyone know whether deleting the last row of a matrix controlled by a UDO child table gives problems? I have the strange effect that I cannot delete the very last existing row in the matrix, i.e. after updating the delete the last to-be deleted row comes back into my matrix !!
    I give you a snippet of my code (function getSelectedRow gives the selected row in the matrix):
    ==
    if (evnt.ItemUID.Equals(ViewConstants.Items.DELETEBUTTON))
      if (evnt.EventType == BoEventTypes.et_ITEM_PRESSED)
        if (evnt.BeforeAction)
          form = BusinessOne.Application.Forms.Item(formUID);
          mtx = (Matrix)form.Items.Item(ViewConstants.Items.MATRIX).Specific;
         int numRow = getSelectedRow(mtx);
         if (numRow != -1)
                                            mtx.DeleteRow(numRow);
                                            form.Mode = BoFormMode.fm_UPDATE_MODE;
                                       Item btn = (Item)form.Items.Item(ViewConstants.Items.ADDBUTTON);
                                       btn.Enabled = true;
    ==
    Cheers,
    Marcel Peek
    Alpha One
    Message was edited by: Marcel Peek
    Message was edited by: Marcel Peek

    Yes, there is a problem to delete the last row.
    It is fixed in version 2005.

  • VBS:How can i determine the last row of an excel-sheet

    I want to replace the chn-comments of an datafile. I pick up the chn-names and want to compare them with an excel-file and so get from the excel-file the right chn-comment and store int back in the datafile. my problem is how can i determine where the excelfile-row is on the end to load the loopounter with corr values.
    i know one solution via scan on ascii 13 and 9.but bether is to know immediately the length of the column.
    answers also in german possible.

    Peter,
    Are you using DIAdem's Excel Import Wizard? By "Excel file" do you mean a tab- or comma-delimited ASCII file that Excel can read in easily, or do you mean a file with the extension "*.xls"? You certainly could not search through an *.xls file to find CR/LF characters.
    If you use the ASCII or Excel Import Wizard to create an *.STP file for the "Excel" file in question, then after the *.STP file is loaded you have access to a whole range of variables, starting with Ascii... or Excel... which completely outline the structure of the ASCII or Excel file, including things like the row in which the channel comments are, etc.
    Why don't you send over your Excel file and I'll be able to help you a lot better.
    Regards,
    Brad Turpin
    NI

  • How to get the last row

    I have 10 rows in my table and I have to retrive last row using rownum.
    For this I use
    SELECT * from <table_name>
    where rownum<=10
    minus
    SELECT * from <table_name>
    where rownum<=9
    The result is no rows selected
    In the same case if I use
    SELECT rownum from <table_name>
    Where rownum <= 10
    minus
    SELECT rownum from <table_name>
    where rownum <=9
    The result is 10
    Why this happend.
    If the result is 10, then why the row whose rowid is 10 is not retrived

    All
    Please bear in mind that ROWNUM is an attribute of the query NOT the table. The last row returned by an unORDERed SELECT statement may be the most recently inserted row but is not guaranteed to be so.
    The only way of assuring yourself of returning the most recent row is either to timestamp all your tables with a date_created column or to use a primary key with an ascending value.
    rgds, APC

Maybe you are looking for