JScrollPane help needed


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: JScrollPane help needed

  1. #1
    Join Date
    Mar 2003
    Posts
    1

    JScrollPane help needed

    hei,

    I have a little problem with scrolling...i am trying to develop a chat applet...when i receive a new message...i append it to the bottom of already existing messages( just like msn or other chat clients)...

    But when i append new message...scroll pane should be at the bottom...but it remains at the top...so i have to scroll down to see the new message...

    I want it to work same as in TextArea for example... please help...my brain is going to explode soon..part of my source code is given below:

    //****************************************
    Panel upperPanel = new Panel();

    upperPanel.setLayout(
    new FlowLayout(FlowLayout.LEFT));

    JEditorPane jt = new JEditorPane();
    jt.setEditable(false);
    jt.setContentType("text/html");
    jt.setText("<H2> Welcome </H2>");

    JScrollPane editorScrollPane = new JScrollPane(jt);
    editorScrollPane.setVerticalScrollBarPolicy(
    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    editorScrollPane.setPreferredSize(
    new Dimension(250, 300));
    upperPanel.add(editorScrollPane);

    //*****************************************

  2. #2
    Join Date
    Nov 2002
    Posts
    138
    i am not familiar with the JEditorPane class but most components of this type extends the JTextComponent class. so i'll bet you can use the getText() and setCaretPosition() methods.

    i.e.:
    component.setCaretPostion( component.getText().length() );

    where component is your JEditorPane. i am not too sure if this should work since there might be an effect to the getText() method regarding the HTML content type that a JEditorPane handles. just give it a try...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center