jscrollpane dosen't work....

hi,

i m using a jscrollpane with a jeditorpane.when i use only jeditorpane to see a html page everything is ok.but when i add jscrollpane to the jeditorpane i cannot see the html page and even the scrollpane.my code is as follows...

JEditorPane jEditorPane1 = new JEditorPane();

JScrollPane editorScrollPane = new JScrollPane(jEditorPane1,

JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,

JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

editorScrollPane.setPreferredSize(new Dimension(450,500));

editorScrollPane.setMinimumSize(new Dimension(200,200));

//panel3.add(jEditorPane1);

//panel3.add(editorScrollPane);

this.getContentPane().add(jEditorPane1, null);

this.getContentPane().add(editorScrollPane,null);

jEditorPane1.setEditable(false);

jEditorPane1.setEditorKit(new HTMLEditorKit());

jEditorPane1.setContentType("text/html");

try {

jEditorPane1.setText(inputLine);

} catch(Exception exp) {

exp.printStackTrace(System.out);

}

here inputline is an html string read from a cgiscript.

any help would be highly appreciated..

anurag.

[1191 byte] By [anurag_bansal] at [2007-9-26 1:29:18]
# 1

Try something like this:

// Create a component.

JEditorPane jep=new JEditorPane();

// Create a scrollpane.

JScrollPane jsp=new JScrollPane();

// Put the component into the scrollpane.

jsp.getViewport().add(jep,null);

// Put the scrollpane on the window.

this.getContentPane().add(jsp,null);

Works for me!

peeveen at 2007-6-29 1:25:36 > top of Java-index,Archived Forums,Swing...
# 2

Hi!

You only have to add the JScrollPane to the JFrame (or what ever),

NOT the JEditorPane too, because the editor pane is the client of your

scroll pane.

Remove the line

this.getContentPane().add(jEditorPane1, null);

Maybe you have to set a preferred size for the JEditorPane.

Oliver

oliverd1 at 2007-6-29 1:25:36 > top of Java-index,Archived Forums,Swing...
# 3
He's not adding anything to the JScrollPane. You need to set the Viewport of the scrollpane to the editorpane.
Hoju at 2007-6-29 1:25:36 > top of Java-index,Archived Forums,Swing...
# 4
It IS done in the constructor's call, line 2 to 4!
oliverd1 at 2007-6-29 1:25:36 > top of Java-index,Archived Forums,Swing...
# 5

You cant just add both components like you did here - they will overlay each other

this.getContentPane().add(jEditorPane1, null);

this.getContentPane().add(editorScrollPane,null);

You need to do it this way

editorScrollPane.setViewPortView(jEditorPane1);

this.getContentPane().add(editorScrollPane,null);

then it should work

shirish_wagh at 2007-6-29 1:25:36 > top of Java-index,Archived Forums,Swing...