Can I nest a JEditorPane inside a JScrollPane inside a JPanel?

Discussion in 'Java' started by Mike, Dec 2, 2003.

  1. Mike

    Mike Guest

    The title pretty much says it all. I've created a class that extends
    JPanel and have attempted to place a JScrollPane inside of it with a
    JEditorPane inside the scroll pane with no luck. When I run the
    applet the scroll pane shows up but the JEditorPane doesn't render. I
    am able to nest a JTextArea inside the scroll pane just fine.

    Thanks for you help,

    Mike
    A Java Noob
     
    Mike, Dec 2, 2003
    #1
    1. Advertising

  2. Mike

    Woebegone Guest

    "Mike" <> wrote in message
    news:...
    > The title pretty much says it all. I've created a class that extends
    > JPanel and have attempted to place a JScrollPane inside of it with a
    > JEditorPane inside the scroll pane with no luck. When I run the
    > applet the scroll pane shows up but the JEditorPane doesn't render. I
    > am able to nest a JTextArea inside the scroll pane just fine.
    >
    > Thanks for you help,
    >
    > Mike
    > A Java Noob


    Well, the short answer is "yes," but I think it requires some tinkering. See
    http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/index.html#TextSamplerDemo
    or if you're not at 1.4 yet
    http://java.sun.com/docs/books/tutorial/uiswing/components/example-swing/TextSamplerDemo.java

    Here is a short example: not an applet, but that at least shows it's
    possible...

    //==========
    package news.exp;
    import javax.swing.JEditorPane;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    public class Main {
    private static String DOC =
    "<html><head>Testing some scrolling</head>" +
    "<body><h1>Hello World!</h1>" +
    "<p>An editor pane inside a scroll pane.</p></body></html>";
    public static void main(String[] args) {
    JFrame frame = new JFrame("Test the scrollers");
    JPanel panel = new JPanel();
    JEditorPane editor = new JEditorPane("text/html", DOC) {
    // See justification in javax.swing.Scrollable
    public boolean getScrollableTracksViewportWidth() {
    return false;
    }};
    JScrollPane scroller =
    new JScrollPane(
    editor,
    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
    JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    panel.add(scroller);
    frame.getContentPane().add(panel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.show();
    }
    }

    //========

    HTH!
    Sean.
     
    Woebegone, Dec 2, 2003
    #2
    1. Advertising

  3. "Mike" <> wrote in message
    news:...
    > The title pretty much says it all.


    It is always a good idea to repeat the Subject:
    line in the body - I think I heard because certain
    newsreaders do not show the headers (shrugs)

    Also, and this is far more important.

    Please do not multi-post Mike. If you
    did not like the answer Harald gave you
    over on c.l.j.g, it is best to follow it up there,
    rather than bring the discussion over here.

    --
    Andrew Thompson
    * http://www.PhySci.org/ PhySci software suite
    * http://www.1point1C.org/ 1.1C - Superluminal!
    * http://www.AThompson.info/andrew/ personal site
     
    Andrew Thompson, Dec 2, 2003
    #3
  4. Mike

    Mike Guest

    Thanks for the tip. I actually posted over here first, and then saw another
    message saying that gui questions should be posted over there, so that's
    what I did.

    "Andrew Thompson" <> wrote in message
    news:maXyb.36070$...
    > "Mike" <> wrote in message
    > news:...
    > > The title pretty much says it all.

    >
    > It is always a good idea to repeat the Subject:
    > line in the body - I think I heard because certain
    > newsreaders do not show the headers (shrugs)
    >
    > Also, and this is far more important.
    >
    > Please do not multi-post Mike. If you
    > did not like the answer Harald gave you
    > over on c.l.j.g, it is best to follow it up there,
    > rather than bring the discussion over here.
    >
    > --
    > Andrew Thompson
    > * http://www.PhySci.org/ PhySci software suite
    > * http://www.1point1C.org/ 1.1C - Superluminal!
    > * http://www.AThompson.info/andrew/ personal site
    >
    >
     
    Mike, Dec 2, 2003
    #4
  5. "Mike" <> wrote in message
    news:bqi2jp$8a5$...
    > Thanks for the tip. I actually posted over here first, and then saw

    another
    > message saying that gui questions should be posted over there, so that's
    > what I did.


    As reasonable an answer as I've ever heard, but you
    might have saved some bother by acknowledging
    you had multi-posted and explaining why.

    It's good that you are reading the posts of the
    group though.

    You might also Google for the recently established
    FAQ through the c.l.j.g group. I will leave further
    discussion for that group.

    (Hope you get a solution BTW!)

    --
    Andrew Thompson
    * http://www.PhySci.org/ PhySci software suite
    * http://www.1point1C.org/ 1.1C - Superluminal!
    * http://www.AThompson.info/andrew/ personal site
     
    Andrew Thompson, Dec 2, 2003
    #5
  6. Mike

    Mike Guest

    Okey dokey smokey.

    "Andrew Thompson" <> wrote in message
    news:7o0zb.36529$...
    > "Mike" <> wrote in message
    > news:bqi2jp$8a5$...
    > > Thanks for the tip. I actually posted over here first, and then saw

    > another
    > > message saying that gui questions should be posted over there, so that's
    > > what I did.

    >
    > As reasonable an answer as I've ever heard, but you
    > might have saved some bother by acknowledging
    > you had multi-posted and explaining why.
    >
    > It's good that you are reading the posts of the
    > group though.
    >
    > You might also Google for the recently established
    > FAQ through the c.l.j.g group. I will leave further
    > discussion for that group.
    >
    > (Hope you get a solution BTW!)
    >
    > --
    > Andrew Thompson
    > * http://www.PhySci.org/ PhySci software suite
    > * http://www.1point1C.org/ 1.1C - Superluminal!
    > * http://www.AThompson.info/andrew/ personal site
    >
    >
     
    Mike, Dec 2, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ludaekipa
    Replies:
    2
    Views:
    2,181
    ludaekipa
    May 4, 2004
  2. Andreas Beresko

    Add a JPanel to a JPanel...

    Andreas Beresko, Jul 14, 2004, in forum: Java
    Replies:
    6
    Views:
    27,025
  3. McMatt
    Replies:
    2
    Views:
    828
    McMatt
    Feb 23, 2007
  4. Raphael Jolivet

    [JPanel] Drop Down JPanel

    Raphael Jolivet, Jul 18, 2008, in forum: Java
    Replies:
    1
    Views:
    1,541
    John B. Matthews
    Jul 18, 2008
  5. t1m1976
    Replies:
    1
    Views:
    2,440
    t1m1976
    Nov 7, 2010
Loading...

Share This Page