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

M

Mike

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
 
W

Woebegone

Mike said:
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.
 
A

Andrew Thompson

Mike said:
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.
 
M

Mike

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.
 
A

Andrew Thompson

Mike said:
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!)
 
M

Mike

Okey dokey smokey.

Andrew Thompson said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top