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

JScrollPane with JTextArea starts at bottom of text by default

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • client-libs
    • beta
    • x86
    • windows_nt



      Name: sl110371 Date: 07/20/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      1. Creating a JTextArea object and putting it inside a JScrollPane
      2. Showing the JScrollPane as the Object passed to JOptionPane.showMessageDialog
      3. Initially the text is scrolled to the bottom not the top

      Only happens with JRE 1.3 not JRE 1.2.2, and only when used by an applet using
      the plugin. Works when used by an application run using JRE 1.3.

      CODE:
      Test.java =====================================================================
      import javax.swing.*;
      import java.awt.*;

      public class Test extends JApplet {

        private HyperHelp hh;

        private static String DECLARATION = "When in the Course of human events it bec
      omes necessary for one people to dissolve the political bands which have connect
      ed them with another, and to assume among the powers of the earth, the separate
      and equal station to which the Laws of Nature and of Nature's God entitle them,
      a decent respect to the opinions of mankind requires that they should declare th
      e causes which impel them to the separation.\n\nWe hold these truths to be self-
      evident, that all men are created equal, that they are endowed by their Creator
      with certain unalienable Rights, that among these are Life, Liberty and the purs
      uit of Happiness. That to secure these rights, Governments are instituted among
      Men, deriving their just powers from the consent of the governed. That whenever
      any Form of Government becomes destructive of these ends, it is the Right of the
       People to alter or to abolish it, and to institute new Government, laying its f
      oundation on such principles and organizing its powers in such form, as to them
      shall seem most likely to effect their Safety and Happiness. Prudence, indeed, w
      ill dictate that Governments long established should not be changed for light an
      d transient causes; and accordingly all experience hath shewn that mankind are m
      ore disposed to suffer, while evils are sufferable, than to right themselves by
      abolishing the forms to which they are accustomed. But when a long train of abus
      es and usurpations, pursuing invariably the same Object evinces a design to redu
      ce them under absolute Despotism, it is their right, it is their duty, to throw
      off such Government, and to provide new Guards for their future security. Such h
      as been the patient sufferance of these Colonies; and such is now the necessity
      which constrains them to alter their former Systems of Government. The history o
      f the present King of Great Britain is a history of repeated injuries and usurpa
      tions, all having in direct object the establishment of an absolute Tyranny over
       these States. To prove this, let Facts be submitted to a candid world.";

        public void init () {
          hh = new HyperHelp(this, "HyperText", DECLARATION, JLabel.CENTER);
        }

        public void start () {
          getContentPane().add(hh);
        }
      }
      END Test.java =================================================================

      HyperHelp.java ================================================================
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;

      /****************************************************************************
       This easy to use class extends JLabel to allow a user to create a hypertext
       link to some text message which will be shown in a scroll pane in a dialog
       window
      ****************************************************************************/
      public class HyperHelp extends JLabel implements MouseListener {

        String help; // the help text
        JApplet parent;

        /****************************************************************************
         Constructor requires the parent applet, the string to display as the
         clickable label, and the help text to be shown in the popup dialog
        ****************************************************************************/
        public HyperHelp (JApplet parent, String lbl, String helpText, int align) {
          super(lbl, align);
          setFont(getFont().deriveFont(9.0f));
          setForeground(Color.blue);
          setToolTipText("Click here");
          addMouseListener(this);
          this.help = helpText;
          this.parent = parent;
        }

        /****************************************************************************
         Popup help text
        ****************************************************************************/
        private void showPopupHelp() {
          JTextArea ta = new JTextArea(help, 8, 35);
          ta.setLineWrap(true);
          ta.setWrapStyleWord(true);
          ta.setEditable(false);
          JScrollPane sp = new JScrollPane(ta);
          JOptionPane.showMessageDialog(parent, sp, "Help", JOptionPane.INFORMATION_ME
      SSAGE);
        }

        /****************************************************************************
         Mouse Listener methods
        ****************************************************************************/
        public void mouseEntered(MouseEvent e) {
          setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        }
        public void mouseExited(MouseEvent e) {
          setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
        public void mouseClicked(MouseEvent e) {
          showPopupHelp();
        }
        public void mousePressed(MouseEvent e) { }
        public void mouseReleased(MouseEvent e) { }

      }
      END HyperHelp.java ============================================================
      (Review ID: 107424)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: