Scrolling a JEditorPane

I have a JEditorPane inside a JScrollPane.
In this JEditorPane I show a Html file which is bigger than the JEditorPane, so the ScrollBars appears.
In my application, the keys (up,down,left, right) should be used for Scrolling, so we've used this code:
  peditor.addKeyListener( new KeyAdapter() {
         public void keyPressed( KeyEvent e ) {
            int icode = e.getKeyCode();
            if ( icode == KeyEvent.VK_UP ) {
               int igo = pscroll.getVerticalScrollBar().getUnitIncrement( 1 );
               int ival = pscroll.getVerticalScrollBar().getValue();
               int idest = ival - igo;
               if ( idest < pscroll.getVerticalScrollBar().getMinimum() ) {
                  idest = pscroll.getVerticalScrollBar().getMinimum();
               pscroll.getVerticalScrollBar().setValue( idest );
            else if ( icode == KeyEvent.VK_DOWN ) {
               int igo = pscroll.getVerticalScrollBar().getUnitIncrement( 1 );
               int ival = pscroll.getVerticalScrollBar().getValue();
               int idest = ival + igo;
               if ( idest > pscroll.getVerticalScrollBar().getMaximum() ) {
                  idest = pscroll.getVerticalScrollBar().getMaximum();
               pscroll.getVerticalScrollBar().setValue( idest );
      });in fact it worked, but I have 2 bugs:
1)When the keys are used after the mouse, the position changes to where the mouse had started.
2)When you keep the key pressed, the ScrollBars doesn't move in a standard way, they are fast in some points, and slow in some other.
What should I do ?
Can someone help me to solve these bugs ?
Thanks.
Wmiro.

Hello,
bbrittas solution works for me (jdk1.42), but the
problem is that it only looks where the cursor is and
not where the user scrolled to.
You have to check whether the vertical ScrollBar is at
maximum + model-extent else dont scroll to bottom.
regards,
TimHeres an ugly(flickering) but working start:public void actionPerformed(ActionEvent ae)
     final JScrollBar bar = scroll.getVerticalScrollBar();
     final int barPos = bar.getValue();
     boolean end = bar.getValue() == bar.getMaximum() - bar.getModel().getExtent() - 3;
     try
          doc.insertString(doc.getLength(), "Something", null);
          if (end)
               jep.setCaretPosition(doc.getLength());
          else
               SwingUtilities.invokeLater(new Runnable()
                    public void run(){
                         bar.setValue(barPos);
     catch (BadLocationException ble){}
}regards,
Tim

Similar Messages

  • Map html tags to text display in jeditorpane

    hi,
    i am looking for some way to map the position of a tag in a html i/p to the actual display in the JEditorPane... below are the details of why i need this feature...
    i have a JEditorPane whose text is set from a html file i/p... and i have a JTree which is like a table of contents for the content in the JEditorPane... when i click on any of the jTree nodes, i want to scroll the JEditorPane to the position corresponding to that element in the text...
    currently i am doing a string search (for ex, "1. My_First_Heading: ") and getting the position from the editorPane.getDocument().getText() method and then using a modelToView() to determine the scrollBar position...
    but i would like to have a more correct searching method, since the string could appear at many places... i would like to have some anchor or some tags defined at the place of each table of content element in the JEditorPane's html i/p... then search for those tags and somehow map the position in the html to the position in the display...
    is there a way i can do this...
    thanks,
    prasuna

    Hi Tarabyte,
    Actually wanted to know how to map the postion of any tags in the html to the display in the jeditorpane...
    Hi StanislavL,
    Thank you very much for your answer... it solved my problem... awarded the 5 duke dollars to you for that...
    Cheers,
    Prasuna

  • JEditorPane acting incorrectly

    OK, I posted this previously but no answers. My code used to work with the 1.3 JDK but now it doesn't.
    I set a Jframe with a JEditor Pane inside it. Then I load a html page. If you select output page from the file menu the JEditorPane dumps the html code it has displayed to stdout.
    However the page I load is completely different when outputted from the JEditor Pane. All the html between the form tags is moved outside them. I'm wondereing why this happens.
    Please help...
    Here's the code I'm running, it's very simple (viewer is my JEditorPane):
    import java.io.*;
    import java.util.*;
    import java.awt.event.*;
    import java.awt.Toolkit;
    import java.net.URL;
    import javax.swing.*;
    import javax.swing.text.html.HTMLDocument;
    public class Main extends JFrame implements ActionListener
       public Main() throws Exception
       {  super();
          setSize(Toolkit.getDefaultToolkit().getScreenSize());
          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          // menu bar
          JMenuBar menubar = new JMenuBar();
          JMenu fileMenu = new JMenu("File");
          JMenuItem nItem = (JMenuItem)fileMenu.add("Output Page");
          nItem.addActionListener(this);
          JMenuItem eItem = (JMenuItem)fileMenu.add("Exit");
          eItem.addActionListener(this);
          menubar.add(fileMenu);
          setJMenuBar(menubar);
          // main component
          viewer = new JEditorPane();
          viewer.setContentType("text/html");
          viewer.setEditable(false);
          scroll = new JScrollPane(viewer);
          getContentPane().add(scroll);
          setVisible(true);
          URL url = new URL( "file:///C:/Documents%20and%20Settings/ross/Desktop/Phd%20Backup/test/test.html");
          viewer.setPage(url);
       public void actionPerformed(ActionEvent ae)
       {  if (ae.getActionCommand().equals("Exit"))
          {   System.exit(0);
          else if (ae.getActionCommand().equals("Output Page"))
             System.out.println(viewer.getText());
       private JScrollPane scroll;
       private JEditorPane viewer;
       public static void main(String[] args)
       {  Main madness = null;
          try
          {  madness = new Main();
          catch (Exception e)
          {  System.err.println(e);
             System.exit(1);
    Here's the content of "test.html":
    <html>
    <head>
    <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Holiday Search</title>
    <style type="text/css">
          .header { background-color: #9bbadd; font-weight: bold; color: #000040;}
          .odd { background-color: #ffffc0; height:10mm}
          .even { background-color: #ffaf88; height:10mm }
       </style>
    </head>
    <body bgcolor="white" text="darkblue">
    <table bgcolor="#9bbadd">
    <tr>
    <td><font face="helvetica,verdana,geneva,arial" color="#ee0000" size="+2">
    <center>Holiday Search</center>
    </font></td>
    </tr>
    </table>
    <br>
    <table cellspacing="0" cellpadding="3" border="0" width="100%" class="odd">
    <tr class="header">
       <td width="5%">Id</td>
       <td width="15%">Destination</td>
       <td width="15%">Month</td>
       <td width="5%">Persons</td>
       <td width="5%">Nights</td>
       <td width="20%">Hotel</td>
       <td width="10%">Rating</td>
       <td width="10%">Type</td>
       <td width="5%">Price</td>
       <td width="10%"> </td>
    </tr>
    <tr>
    <form action="/obr-holidays/Refine" name="627" method="get">
       <td width="5%">627</td>
       <td width="15%">Fuerteventura<input name="attr" type="hidden" value="Region"><input name="op" type="hidden" value="like"><input name="val" type="hidden" value="Fuerteventura"></td>
       <td width="15%">June<input name="attr" type="hidden" value="Month"><input name="op" type="hidden" value="like"><input name="val" type="hidden" value="June"></td>
       <td width="5%">3<input name="attr" type="hidden" value="NumberOfPersons"><input name="op" type="hidden" value="like"><input name="val" type="hidden" value="3"></td>
       <td width="5%">21<input name="attr" type="hidden" value="Duration"><input name="op" type="hidden" value="like"><input name="val" type="hidden" value="21"></td>
       <td width="20%">Hotel Rio Ventura, Fuerteventura</td>
       <td width="10%">FourStars<input name="attr" type="hidden" value="Accommodation"><input name="op" type="hidden" value="like"><input name="val" type="hidden" value="FourStars"></td>
       <td width="10%">Bathing<input name="attr" type="hidden" value="HolidayType"><input name="op" type="hidden" value="like"><input name="val" type="hidden" value="Bathing"></td>
       <td width="5%">7161<input name="attr" type="hidden" value="Price"><input name="op" type="hidden" value="like"><input name="val" type="hidden" value="7161"></td>
       <td width="10%"> <input type="Submit" value="refine..."></td>
    </form>
    </tr>
    </table>
    <table cellspacing="0" cellpadding="3" border="0" width="100%" class="even">
    <tr>
    <form action="/obr-holidays/Refine" name="1149" method="get">
       <td width="5%">1149</td>
       <td width="15%">Salzkammergut<input name="attr" type="hidden" value="Region"><input name="op" type="hidden" value="like"><input name="val" type="hidden" value="Salzkammergut"></td>
       <td width="15%">February<input name="attr" type="hidden" value="Month"><input name="op" type="hidden" value="like"><input name="val" type="hidden" value="February"></td>
       <td width="5%">3<input name="attr" type="hidden" value="NumberOfPersons"><input name="op" type="hidden" value="like"><input name="val" type="hidden" value="3"></td>
       <td width="5%">14<input name="attr" type="hidden" value="Duration"><input name="op" type="hidden" value="like"><input name="val" type="hidden" value="14"></td>
       <td width="20%">Dorfhotel Heiligenblut, Salzkammergut</td>
       <td width="10%">FourStars<input name="attr" type="hidden" value="Accommodation"><input name="op" type="hidden" value="like"><input name="val" type="hidden" value="FourStars"></td>
       <td width="10%">Recreation<input name="attr" type="hidden" value="HolidayType"><input name="op" type="hidden" value="like"><input name="val" type="hidden" value="Recreation"></td>
       <td width="5%">8007<input name="attr" type="hidden" value="Price"><input name="op" type="hidden" value="like"><input name="val" type="hidden" value="8007"></td>
       <td width="10%"> <input type="Submit" value="refine..."></td>
    </form>
    </tr>
    </table>
    </body>
    </html>
    What getText() returns from JEditorPane:
    <html>
      <head>
        <style type="text/css">
          <!--
            .odd { height: 10mm; background-color: #ffffc0 }
            .even { height: 10mm; background-color: #ffaf88 }
            .header { background-color: #9bbadd; color: #000040; font-weight: bold }
          -->
        </style>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Holiday Search    </title>
      </head>
      <body text="darkblue" bgcolor="white">
        <table bgcolor="#9bbadd">
          <tr>
            <td>
              <center>
                <font face="helvetica,verdana,geneva,arial" color="#ee0000" size="+2">Holiday
                Search X
    </font>          </center>
            </td>
          </tr>
        </table>
        <br>
        <table cellpadding="3" cellspacing="0" class="odd" border="0" width="100%">
          <tr class="header">
            <td width="5%">
              Id
            </td>
            <td width="15%">
              Destination
            </td>
            <td width="15%">
              Month
            </td>
            <td width="5%">
              Persons
            </td>
            <td width="5%">
              Nights
            </td>
            <td width="20%">
              Hotel
            </td>
            <td width="10%">
              Rating
            </td>
            <td width="10%">
              Type
            </td>
            <td width="5%">
              Price
            </td>
            <td width="10%">
            </td>
          </tr>
          <tr>
            <td>
              <form method="get" name="627" action="/obr-holidays/Refine">
              </form>
            </td>
            <td width="5%">
              627
            </td>
            <td width="15%">
              Fuerteventura<input type="hidden" value="Region" name="attr"><input type="hidden" value="like" name="op"><input type="hidden" value="Fuerteventura" name="val">
            </td>
            <td width="15%">
              June<input type="hidden" value="Month" name="attr"><input type="hidden" value="like" name="op"><input type="hidden" value="June" name="val">
            </td>
            <td width="5%">
              3<input type="hidden" value="NumberOfPersons" name="attr"><input type="hidden" value="like" name="op"><input type="hidden" value="3" name="val">
            </td>
            <td width="5%">
              21<input type="hidden" value="Duration" name="attr"><input type="hidden" value="like" name="op"><input type="hidden" value="21" name="val">
            </td>
            <td width="20%">
              Hotel Rio Ventura, Fuerteventura
            </td>
            <td width="10%">
              FourStars<input type="hidden" value="Accommodation" name="attr"><input type="hidden" value="like" name="op"><input type="hidden" value="FourStars" name="val">
            </td>
            <td width="10%">
              Bathing<input type="hidden" value="HolidayType" name="attr"><input type="hidden" value="like" name="op"><input type="hidden" value="Bathing" name="val">
            </td>
            <td width="5%">
              7161<input type="hidden" value="Price" name="attr"><input type="hidden" value="like" name="op"><input type="hidden" value="7161" name="val">
            </td>
            <td width="10%">
               <input type="submit" value="refine...">
            </td>
          </tr>
        </table>
        <table cellpadding="3" class="even" cellspacing="0" border="0" width="100%">
          <tr>
            <td>
              <form method="get" name="1149" action="/obr-holidays/Refine">
              </form>
            </td>
            <td width="5%">
              1149
            </td>
            <td width="15%">
              Salzkammergut<input type="hidden" value="Region" name="attr"><input type="hidden" value="like" name="op"><input type="hidden" value="Salzkammergut" name="val">
            </td>
            <td width="15%">
              February<input type="hidden" value="Month" name="attr"><input type="hidden" value="like" name="op"><input type="hidden" value="February" name="val">
            </td>
            <td width="5%">
              3<input type="hidden" value="NumberOfPersons" name="attr"><input type="hidden" value="like" name="op"><input type="hidden" value="3" name="val">
            </td>
            <td width="5%">
              14<input type="hidden" value="Duration" name="attr"><input type="hidden" value="like" name="op"><input type="hidden" value="14" name="val">
            </td>
            <td width="20%">
              Dorfhotel Heiligenblut, Salzkammergut
            </td>
            <td width="10%">
              FourStars<input type="hidden" value="Accommodation" name="attr"><input type="hidden" value="like" name="op"><input type="hidden" value="FourStars" name="val">
            </td>
            <td width="10%">
              Recreation<input type="hidden" value="HolidayType" name="attr"><inputtype="hidden" value="like" name="op"><input type="hidden" value="Recreation" name="val">
            </td>
            <td width="5%">
              8007<input type="hidden" value="Price" name="attr"><input type="hidden" value="like" name="op"><input type="hidden" value="8007" name="val">
            </td>
            <td width="10%">
               <input type="submit" value="refine...">
            </td>
          </tr>
        </table>
      </body>
    </html>Why does this happen, please, please help...

    JEditorPane's HTMLEditorKit primarily supports HTML 3.2. Beyond these basic tags, it handles few tags from later versions of HTML.
    Add "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">" at the beginning of your html file and try to validate it at http://validator.w3.org/ .
    The inconsistent behavior you're experiencing might be solved if you modify your file to make it strictly html 3.2 valid. This is of course just a wild guess.

  • How can I create JEditorPane which scrolls to the bottom on every resize?

    JRE 1.3.0
    Included a simple frame with the only control - JEditorPane (contained within JScrollPane). Every time scroll pane size changes, attempt to scroll down to the end of JEditorPane is made.
    The problem is: although everything works 9 times of 10, sometimes editor is scrolled almost to the end, sometimes - to the very top. On the next resize editor is scrolled correctly.
    I think, there are some delayed layout recalculations inside SWING which prevent JEditorPane and/or JScrollPane from knowing actual size.
    Is it possible to force JEditorPane+JScrollPane pair to update dimensions? ( explicit call to doLayout() does not fix anything )
    Thanks
    public class TestFrame extends JFrame
    BorderLayout borderLayout1 = new BorderLayout();
    JScrollPane jScrollPane1 = new JScrollPane();
    JEditorPane jEditorPane1 = new JEditorPane();
    public TestFrame()
    try
    jbInit();
    catch(Exception e)
    e.printStackTrace();
    private void jbInit() throws Exception
    this.getContentPane().setLayout(borderLayout1);
    jEditorPane1.setContentType("text/html");
    jEditorPane1.setText("test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test ");
    jScrollPane1.addComponentListener(new java.awt.event.ComponentAdapter()
    public void componentResized(ComponentEvent e)
    jScrollPane1_componentResized(e);
    this.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
    jScrollPane1.getViewport().add(jEditorPane1, null);
    void jScrollPane1_componentResized(ComponentEvent e)
    Dimension size = jEditorPane1.getPreferredSize();
    jEditorPane1.scrollRectToVisible( new Rectangle(0, size.height, 0, 0) );
    System.out.println("preferred height=" + size.height);
    }

    Seen this thread?
    Return to previously viewed page

  • JEditorPane with automated linewrapping and no horizontal scroll bar.

    Hello.
    I am working with a JEditorPane which is added insisde a JScrollPane, the thing is that i want to have
    [1]Automatic line wrapping, although this works good with the method .setText(String str) i am not using that method, instead of that i prefer to have an HTMLDocument object inside the JEditorPane and use the method insertBeforeEnd(...) . When i do that, i do not have automatic line wrapping.
    [2]Not having that line wrapping means that i see an ugly scroll bar in the horizontal position, which i want to avoid, since this is for an IM application.
    Before i used a JTextArea with the method .setLineWrap(true) and everyghing was ok, so is there any way to do the same in a JEditorPane with an HTMLDocument? Any help will be apreciated.
    Thanks

    But what i want to do is ....Well instead of telling us what you want to do, why don't you post a 20 line executable demo program that shows us exactly what you are doing and what the problem is. A picture is worth a thousand words.
    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

  • Scrolling with images in a jeditorpane

    Hi,
    I'm really struggling with a jeditor pane. I'm using it to show formatted system messages in the interface i'm writing. In some cases these messages may include an image (usually a reference to an online image using html <img> tags.)
    What I want to do is automatically scroll to the bottom of the pane when new text is added. If i use only html formatted text this works fine, but as soon as there is an image in there it doesn't scroll far enough. I believe what's happening is that the image has not finished loading so it scrolls only the length of the placeholder.
    This is the code i'm using to scroll:
    JEditorPane IMPane;
    JScrollPane IMScroller;
    //...snip...
    private void scrollPaneToBottom(){
            SwingUtilities.invokeLater(new Runnable(){
                public void run(){
                    if (isAdjusting()){
                        return;
                    int height = IMPane.getHeight();
                    IMPane.scrollRectToVisible(new Rectangle(0, height - 1,1, height));
        private boolean isAdjusting(){
            JScrollBar scrollBar = IMScroller.getVerticalScrollBar();
            if (scrollBar != null && scrollBar.getValueIsAdjusting()){
                return true;
            return false;
        }I have tried various options including moving the caret but to no avail. Perhaps there is some way i can wait till the page is fully loaded or something like that?
    I hope somebody can help me with this - it's driving me bananas.
    Thanks in advance,
    Crystal

    In the future, Swing related questions should be posted in the Swing forum.
    I would guess your isAdjusting() method is returning true, so the code never executes.
    An easier way to scroll to the bottom is to use:
    textComponent.setCaretPosition( textComponent.getDocument().getLength() );

  • Getting jeditorpane to scroll to a piece of text

    I am highlighting text in a JEditorPane and can't figure out how to get the pane to scroll so the hightlighted text is visible.
    Any ideas?
    Thanks

    search -> no answer
    browse main page -> easy answer
    I feel silly. I just modified this a little:
    text.setCaretPosition( text.getDocument().getLength() );
    http://forums.java.sun.com/thread.jsp?forum=57&thread=422783&tstart=0&trange=15

  • JEditorPane not scrolling in JScrollPane no matter what

    Hello,
    I thoroughly researched this problem and I tried all suggestions, but nothing seems to work. I have a JEditorPane inside the JScrollPane, but JEditorPane does not scroll horizontally no matter what. It simply cuts off the text to the right.
    Here is my code:
    reportArea = new JEditorPane() {
    public boolean getScrollableTracksViewportWidth() {                   
    if (getSize().width < getParent().getSize().width)
         return true;
    else
         return false;
    public void setSize(Dimension d) {                   
    if (d.width < getParent().getSize().width)
         d.width = getParent().getSize().width;
    super.setSize(d);
    reportArea.setEditorKit(new HTMLEditorKit());
    reportArea.setEditable(false);
    JScrollPane reportJ = new JScrollPane(reportArea);
    reportJ.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    reportJ.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    Any suggestions will be greatly and truly appreciated!
    Elana

    I need to display HTML page, that's why I need JEditorPane. Also, In the html table that I'm displaying I have the nowrap attribute, so nothing gets wrapped at all. It's just being cut off...
    ;-(

  • How do i put a scroll bar on a  JEditorPane ?

    How do i put a scroll bar on a JEditorPane ?
    Can somebody point me to some sample
    code that works?
    thanks in advance
    Owen

    You should use a JScrollPane and add the JEditorPane to it...

  • JEditorPane always scrolls down to the bottom, how can I prevent this?

    Hello, I have the following code that contains a JTable and JEditorPane in a panel. When I click on a headline on the table, I have some text showing up in the lower pane. My problem is that the lower pane (that is inside a JScrollPane) always scrolls down to the end of the text, but I want to to always point to the beginning.
    Does anyone know how to do this?
    Your help will be appreciated.
    Thanks!
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.Point;
    import javax.swing.JEditorPane;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JSplitPane;
    import javax.swing.JTable;
    import javax.swing.JViewport;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import javax.swing.table.DefaultTableModel;
    public class MyHTMLPaneTest {
         JFrame frame;
         JPanel panel;
         JSplitPane splitPane;
         JTable table;
         JEditorPane htmlPane;
         JPanel tablePanel;
         DefaultTableModel model;
         JViewport viewPort;
         public MyHTMLPaneTest()
              frame = new JFrame("MyCalHTMLPane Test");
              panel = new JPanel(new BorderLayout());
              splitPane = new JSplitPane();
              tablePanel = new JPanel(new BorderLayout());
              setTable();
              tablePanel.add(table.getTableHeader(), BorderLayout.NORTH);
              tablePanel.add(table, BorderLayout.CENTER);
              htmlPane = new HTMLPane();
              JScrollPane pane = new JScrollPane(htmlPane, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
              viewPort = pane.getViewport();
              viewPort.setViewPosition(new Point(0, 0));
              splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tablePanel, pane);
            panel.add(splitPane, BorderLayout.CENTER);
              frame.getContentPane().add(panel);
              frame.setSize(new Dimension(400, 300));
              frame.setVisible(true);
         public void setTable()
              String[] columnNames = {"Date","Time","Subject"};
             Object[][] data =
                  {"03/31/05", "8:20 AM EDT", "Headline 1"},
                  {"08/24/05", "8:19 AM EDT", "Headline 2"},
                  {"08/18/05", "8:18 AM EDT", "Headline 3"},
                 {"08/12/05", "8:17 AM EDT", "Headline 4"},
                 {"06/20/05", "8:16 AM EDT", "Headline 5"},
                 {"06/20/05", "8:15 AM EDT", "Headline 6"}
             model = new DefaultTableModel(data, columnNames);
             table = new JTable(model);
             table.getSelectionModel().addListSelectionListener(new ListSelectionListener()
                 public void valueChanged(ListSelectionEvent e)
                      String text = "LOOOOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOOOOOOOOOOONG" +
                                "\nLOOOOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOONG"+
                                "\nLOOOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG"+
                                "\nSTRIIIIIIIIIIIIIIIII" +
                                "\nIIIIIIIIIIIIIIIIIIII" +
                                "\nIIIIIIIIIIIIIIIIIIIII" +
                                "\nIIIIIIIIIIIIIIIIIIIII" +
                                "\nIIIIIIIIIIIIIIIIIIIIING"+
                                "LOOOOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOOOOOOOOOOONG" +
                                "\nLOOOOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOONG"+
                                "\nLOOOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOOOOO" +
                                "\nOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOONG"+
                                "\nSTRIIIIIIIIIIIIIIIII" +
                                "\nIIIIIIIIIIIIIIIIIIII" +
                                "\nIIIIIIIIIIIIIIIIIIIII" +
                                "\nIIIIIIIIIIIIIIIIIIIII" +
                                "\nIIIIIIIIIIIIIIIIIIIIING";
                      htmlPane.setText(text);
         public static void main(String[] args) {
              MyHTMLPaneTest test = new MyHTMLPaneTest();
    }

    try setCaretPosition:
            table.getSelectionModel().addListSelectionListener(
                    new ListSelectionListener()
                        public void valueChanged(ListSelectionEvent e)
                            String text = "LOOOOOOOOOOOOOOOOOOO"
                                    + "\nOOOOOOOOOOOO"
                                    + "\nOOOOOOOOOOOOOOOO"
                                    + "\nOOOOOOOOOOOOOOOO"
                                    + "\nIIIIIIIIIIIIIIIIIIIII"
                                    + "\nIIIIIIIIIIIIIIIIIIIIING";
                            htmlPane.setText(text);
                            htmlPane.setCaretPosition(0);  // ******* here **********
                    });

  • Scrolling issue in JEditorPane

    Have searched through the forums and found one way that doesn't seem to work...
    Anyways, here is the problem...
    I have a JEditorPane in a JScrollPane (inside a JTabbedPane, but I beleive that to be irrelevant, as is the fact that that is in a JSplitPane)
    The JEP will wrap to the letter, not to words.. Thats problem one.
    The JEP will resize with the Splitter appropriately, but when the Splitter shrinks the size of the ScrollPane, the JEP insists that it should still be as wide as it was, and gives me a horizontal scroll bar (Which I dont want)
    Any suggestions?

    Nevermind, I've swapped to JTextPane, which has completely and totally fixxed these problems.
    I have no idea why, nor do I care at this point

  • Vertical Scrolling and Horizontal Wrapping in a JEditorPane

    Hey guys,
    Some of you may recall my [post |http://forums.sun.com/thread.jspa?threadID=5418688] from a couple weeks back. In it, I learned how to force (or appear to force) the text of a JEditorPane to grow from the bottom-up instead of top-down (picture the difference between how a chat window grows to how a word document grows). The solution (which solves my original problem perfectly) involves simply placing the JEditorPane into the South region of a JPanel.
    That was all fine and dandy, until I tried putting long lines of text into the JEditorPane. It scrolled vertically when it should have, but the text simply ran off the right side of the JEditorPane instead of wrapping (or showing a horizontal scrollbar).
    After a gross amount of googling, I finally came across this old [post |http://forums.sun.com/thread.jspa?threadID=5318664] that seems to be related to my problem here. It hinted that I should set the width of the JPanel to match the width of the JScrollPane's Viewport. While that does indeed fix the problem with horizontal wrapping, it now creates a problem with the vertical scrolling (which works fine without the fix for horizontal wrapping)!
    I've tried setting the preferred height of the JPanel to just about everything I can think of: the height of the viewport, extremely large numbers, negative numbers, zero, itself, the height of the JEditorPane. But they all do the same thing: no vertical scrollbar ever pops up, even when the text is obviously too long to fit in the window.
    Here's an SSCCE demonstrating what I'm talking about:
    import javax.swing.*;
    import java.awt.*;
    public class EditorPaneTest {
        public EditorPaneTest() {
             JFrame frame = new JFrame("EditorPane Test");
             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             JEditorPane textComponent = new JEditorPane();
             textComponent.setContentType("text/html");
             String text =
                  "This sentence should wrap and not cause the horiztonal scroll bar to display.<br/>"
                  + "<br/>This<br/>sentence<br/>should<br/>cause<br/>"
                  + "the<br/>vertical<br/>scroll<br/>bar<br/>to<br/>display.<br/>";
             textComponent.setText(text);
             JPanel panel = new JPanel(new BorderLayout());
             //the purpose of putting the JEditorPane in a JPanel
             //is to force it to the bottom with BorderLayout
             panel.add(textComponent, BorderLayout.SOUTH);
             JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
             //this line enables wrapping
             //but disables vertical scrolling
             //(comment it out to switch)
             panel.setPreferredSize(new Dimension(scrollPane.getViewport().getWidth(), scrollPane.getViewport().getHeight()));
             frame.add(scrollPane);
             frame.setSize(100, 200);
             frame.setVisible(true);
        public static void main(String[] args) {
            new EditorPaneTest();
    }As always, any pointers / suggestions / criticisms you can give me are greatly appreciated.
    Thanks again,
    Kevin

    camickr wrote:
    You need create a custom panel that implements the Scrollable interface. The key method to override to give you the behaviour you desire is the getScrollTracksViewportWidth() to return "true". This effectively fixes the width of the JEditorPane to the width of the viewport to wrapping is done as expected.That does handle the wrapping and scrolling, but it breaks the original problem: keeping a JEditorPane at the bottom of a JPanel. Using the ScrollablePanel you posted, the JEditorPane now stays at the top of the Panel instead of growing from the bottom.
    To see what I'm talking about, check out this code (the only difference between this and the previous code is the addition of your suggestion):
    import javax.swing.*;
    import java.awt.*;
    public class EditorPaneTest {
        public EditorPaneTest() {
             JFrame frame = new JFrame("EditorPane Test");
             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             JEditorPane textComponent = new JEditorPane();
             textComponent.setContentType("text/html");
             String text =
                  "This sentence should wrap and not cause the horiztonal scroll bar to display.<br/>"
                  + "<br/>This<br/>sentence<br/>should<br/>cause<br/>"
                  + "the<br/>vertical<br/>scroll<br/>bar<br/>to<br/>display.<br/>";
             textComponent.setText(text);
             ScrollablePanel panel = new ScrollablePanel();
             panel.setLayout(new BorderLayout());
             //the purpose of putting the JEditorPane in a JPanel
             //is to force it to the bottom with BorderLayout
             panel.add(textComponent, BorderLayout.SOUTH);
             JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
             //this line enables wrapping
             //but disables vertical scrolling
             //(comment it out to switch)
            //panel.setPreferredSize(new Dimension(scrollPane.getViewport().getWidth(), scrollPane.getViewport().getHeight()));
             frame.add(scrollPane);
             frame.setSize(100, 200);
             frame.setVisible(true);
        public static void main(String[] args) {
            new EditorPaneTest();
         public class ScrollablePanel extends JPanel
              implements Scrollable
              public Dimension getPreferredScrollableViewportSize()
                   return getPreferredSize();
              public int getScrollableUnitIncrement(
                   Rectangle visibleRect, int orientation, int direction)
                   return 20;
              public int getScrollableBlockIncrement(
                   Rectangle visibleRect, int orientation, int direction)
                   return 60;
              public boolean getScrollableTracksViewportWidth()
                   return true;
              public boolean getScrollableTracksViewportHeight()
                   return false;
    }Resize the window to make it taller. The text should stay at the bottom of the window, but now it stays at the top. I tried using a BoxLayout on the ScrollablePanel instead, and adding a Box.createGlue( ) before adding the JEditorPane. But that didn't change anything.

  • Jeditorpane auto scrolling

    When I use a JEditorPane to display a web page, it automatically scrolls to the bottom of the page rather than initially displaying the top of the page. Why does it do this, and how do I get it to show the top instead? I'm using version 1.3.1_01.

    See my work-around near the end of this page: http://developer.java.sun.com/developer/bugParade/bugs/4227520.html

  • Jeditorpane/html - images disappear when scrolling

    The title says it-
    I've had this issue with JEditorPanes in my own code and also with the Java Help viewer. I'm using 1.4.1_01.
    I don't have a lot of images or any very large ones. My pages are quite standard, and very simple- just text and greatly reduced screenshots.
    When I scroll up and down in the component, however, images either completely disappear or part of them disappears. Reloading the page fixes it. Definately a repaint issue of some sort. But, in the case of Java Help, I don't have access to the JEditorPane to hack in any kind of fix.
    Whats the deal here? I can't find any bug postings about this one but it certainly seems to be a major bug.
    Thanks

    I'm glad to hear someone else is having the problem. Any ideas on a work around?
    There has to be some work around. For example, I'm using IDEA for my IDE and it is running under 1.4.1_01- clearly they have used Java Help but their help view isn't having the same problem mine is. I hope I find a solution soon. This is an absolute show stopper. I can't deploy something that is clearly broken.
    It is next to impossible that this is a user error- I haven't even written any code! It is all Java Help's code. I've even tried to turn off all the fancy drawing that is part of Swing, and turned off all hardware acceleration in Windows.

  • JEditorPane - Don't scroll on setText()

    Hi,
    Can someone help me with my problem?
    I have a JEditorPane, and i update it 2 times pro second with setText(), but i don't want that it scroll's to the top of de JEditorPane. It must stay were it is.
    Sorry for my bad English

    camickr wrote:
    and the new text is "abcdefghijk", so only hijk are added. Use a JTextArea, then you can use:
    textArea.append( "hijk" );instead of using setText(...);Thanks, it works :)

Maybe you are looking for

  • Implications of change of Exchange Rate Type from P to M in Version in CO

    Hi SAP Experts, We have a requirement to change the exchange rate type in Versions. In fact, exchange rate type P has been configured in Version 0. This version is being used in Costing Variant PPC1. Price updations are being made with this costing v

  • How to use advanced tab in user reports?

    Hi, How to use "advanced" tab in user reports? I have two reports. I fill "Report ID" in both and then I can push "Add Report" and fill fields property. Then I'm can "drill" from one report to another on right click, but how to pass parameters? Is it

  • Upload Excel to a form in Oracle Applications: 11.5.10.2

    Hi I want to upload excel into a form in Oracle 11i application - order management. There are two columns in Excel Delivery number and Delivery Date. Search each delivery number in Shipping>Transaction>Query Manager . Go to Date field and copy respec

  • Restrict date field in vf01 to system date .

    hi gurus, my requirement is to restrict date field in vf01 to system date . i have changed the 011 routine in vtfa . do I need any extra effort debajyoti

  • Output Type Print Issue

    Hi Experts , I have a output type ZDDC that is triggered from Shipment document and printed automatically at the end user  . Now they dont want the print out automatically for only Belgium. Means ZZDC will be triggered but no auto print out for Belgi