Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4295763

CSS Attribute "text-indent" gives problems when highlighting text

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      006
    • CPU:
      sparc
    • OS:
      solaris_2.6
    • Verification:
      Verified

      Description


      The included test case makes use of a JEditorPane to display a HTML page that uses a Cascading Style Sheet. The Style sheet redefines the <Body> tag so that it uses a negative indent using the following syntax:

      body {
              background-color: #cccccc;
              text-indent: -36.000000pt;
              margin-left: 36.000000pt;
      }

      Text affected by this style will be indented by 36 points with the first line starting at the very left of the page. This displays fine in jdk1.2.2 (but not in jdk1.3, see Bug ID #4284162), but when you drag select the indented text, the text affected by "text-indent" disappears and reappears.

      If a positive indent is used then the text can be selected without seeing this problem.

      Here is the sample code and html file:

      import javax.swing.*;
      import javax.swing.event.*;
      import javax.swing.text.*;
      import javax.swing.text.html.*;
      import java.awt.*;
      import java.io.*;
      import java.awt.event.*;
      import java.net.*;
      public class TestSS extends JFrame {

          JEditorPane editorPane = null;
          URL pageURL = null;

          public TestSS() {
      // Assign a name to the frame and obtain a handle
      // on the frame's content pane
      super ("TestSS");
      Container container = this.getContentPane();

      // create an editor pane and add it to the content pane
      editorPane = new JEditorPane("text/html", "initial Text");
      JScrollPane scrollPane = new JScrollPane (editorPane);
      container.add(scrollPane);

      editorPane.setEditable (false);
      editorPane.addHyperlinkListener (new HyperlinkListener() {
      public void hyperlinkUpdate (HyperlinkEvent e) {
      try {
      editorPane.setPage (e.getURL());
      }
      catch (IOException ex) {
      ex.printStackTrace();
      }
      }
      });

      try {
      pageURL = new URL("file:test.html");
      }
      catch (MalformedURLException excep) {
      System.out.println ("MalformedURL");
      }

      // Assign the page to the editor pane so that the
      // page is displayed
      try {
      editorPane.setPage(pageURL);
      }
      catch (java.io.IOException excep) {
      System.out.println ("setPage" + excep.toString());

      }

      // display the editorpane with the specified size.

      setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
      setSize(600, 400);
      setBackground(Color.lightGray);
      setForeground(Color.black);
      show();

          }

          // The listener class to handle closing of the frame
          // Class to close the frame and exit the application
          class WindowEventHandler extends WindowAdapter {
      public void windowClosing (WindowEvent e) {
      System.exit(0);
      }
          }

          // The main method
          public static void main (String[] ergs) {
      SwingUtilities.invokeLater(new Runnable() {
      public void run() { new TestSS(); }
      });
          }

      }

      2. HTML source:
      <html>
      <head>
      <title>XXXXX</title>
      <STYLE TYPE="text/css">
      A:link {
      color: blue;
      text-decoration: underline;
      }
      A:visited {
      color: purple;
      text-decoration: underline;
      }
      A:active {
      color: red;
      text-decoration: underline;
      }
      html {
      background-color: #cccccc;
      }
      body {
      background-color: #cccccc;
      text-indent: -36.000000pt;
      margin-left: 36.000000pt;
      }
      blockquote {
      text-indent: 0.000000pt;
      margin-left: 0.000000pt;
      }
      table {
      text-indent: 0.000000pt;
      margin-left: -10.000000pt;
      }
      tr th {
      text-align: center;
      padding-left: 10.000000pt;
      padding-right: 10.000000pt;
      }
      tr td {
      padding-left: 10.000000pt;
      padding-right: 10.000000pt;
      margin-top: -3.000000pt;
      margin-bottom: -3.000000pt;
      }
      </style>
      </head>
      <body>
      <BASEFONT SIZE=2>
      <H2 ALIGN=center>xxxxxxx xxx xxxxx</H2>
      <B>xxxxxxxx: </B>xxxxxxx xxxx, xxxxxxxxx xx xxxxxx xx xxxxxxx xx xxxxxxx xx xxxxxxx xx xxxxxxxxxx xx xxxxxxx xx xxxxxxxxxxx xx xxxxxxxxxx xx xxxxxx xx xxxxxxxxxx xx xxxxxxxxxxx xx xxxxxxxxxx xx xxxxxxxxxxxx<DIV HEIGHT=18><B>xxxxxxxxxx xxxx:</B></DIV>
      <BLOCKQUOTE>
      xx xxxxxxxxxx xxxx xxxxx</BLOCKQUOTE>
      <DIV HEIGHT=18><B>xxxxxxxxxxx:</B></DIV><BLOCKQUOTE>
      xxxx</BLOCKQUOTE>
      <DIV><B>xxxxx xxxx:</B></DIV><TABLE BORDER=0><TR><TH>xxxxx xxxxxx</TH><TH>xx xxx</TH><TH>xx xxxx</TH><TH>xx xxxxx</TH><TH>xxxxxxxx xxxxxxxxxxxxxx</TH></TR><TR><TD ALIGN=center>A</TD><TD ALIGN=center>B</TD><TD ALIGN=center>C</TD><TD ALIGN=center>D</TD><TD ALIGN=center>E</TD></TR>
      </TABLE><DIV><B>xxx xxxxxxxxxxxxxx:</B></DIV>
      <TABLE BORDER=0><TR><TH>xxxxxxxxxxxxx</TH><TH>xxxxx</TH><TH>xxx</TH><TH>xxx</TH><TH>xxx</TH></TR><TR valign=baseline><TD>xxxxx</TD><TD ALIGN=right>Z</TD><TD ALIGN=right>xxxxxxxx</TD><TD ALIGN=right>xxxxxxxx</TD><TD ALIGN=right>yyyyyyyy</TD></TR>
      <TR valign=baseline><TD>xxxx</TD><TD ALIGN=right>Z</TD><TD ALIGN=right>xxxxxxxx</TD><TD ALIGN=right>xxxxxxxx</TD><TD ALIGN=right>yyyyyyyy</TD></TR>
      </TABLE><DIV><B>xxxxxxx xxxxxxxxxxx:</B></DIV><TABLE BORDER=0><TR><TH width=75>xxxx</TH><TH width=60>xxxx</TH><TH width=60>xxxxxx</TH><TH >xxxxxx</TH><TH >xxxxxxxxxxx</TH></TR>
      <TR VALIGN=BASELINE><TD ALIGN="left">xxxxxxxxxx</TD><TD ALIGN="left">xxxxxxxx</TD><TD ALIGN="right">xxxxxxxx</TD><TD ALIGN="left">xxxxx</TD><TD ALIGN="left">xxxxx</TD></TR>
      <TR VALIGN=BASELINE><TD ALIGN="left">xxxxxxxxxx</TD><TD ALIGN="left">xxxxxxxx</TD><TD ALIGN="right">xxxxxxxx</TD><TD ALIGN="left">xxxxx</TD><TD ALIGN="left">xxxxx<BR>xxxxx<BR>xxxxx</TD></TR>
      <TR VALIGN=BASELINE><TD ALIGN="left">xxxxxxxxxx</TD><TD ALIGN="left">xxxxxxxx</TD><TD ALIGN="right">xxxxxxxx</TD><TD ALIGN="left">xxxxx</TD><TD ALIGN="left">xxxxx</TD></TR>
      <TR VALIGN=BASELINE><TD ALIGN="left">xxxxxxxxxx</TD><TD ALIGN="left">xxxxxxxx</TD><TD ALIGN="right">xxxxxxxx</TD><TD ALIGN="left">xxxxx</TD><TD ALIGN="left">xxxxx</TD></TR>
      </TABLE>
      </body>
      </html>

      Also, a NullPointerException is thrown when running the code. This only goes away if all of the style sheet is removed.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              tprinzinsunw Timothy Prinzing (Inactive)
              Reporter:
              duke J. Duke (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: