PDA

View Full Version : problem adding panes to JPanel




bhargava
Aug 1, 2007, 05:55 AM
Hi,
The code i mentioned below is not working for me.

import java.awt.*;
import javax.swing.*;

public class Test {
public static void main(String[] args) throws Exception{
JFrame frame = new JFrame();
JPanel panel = new JPanel(new BorderLayout());

JScrollPane sp = new JScrollPane(new JEditorPane("text/html", "Hello Worlddddddddddddd"), ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

panel.add(sp, BorderLayout.CENTER);
panel.add(new JEditorPane("text/html", "Hello Wrold"), BorderLayout.SOUTH);

frame.setSize(255, 255);
frame.getContentPane().add(panel);
frame.show();
}
}


Problem is, I can only see JScrollPane component of the panel, where I want to see both the scroll pane and editor pane. Is there something wrong in my code?



stadidas
Aug 3, 2007, 07:09 AM
You need to replace:


frame.setSize(255, 255);
frame.getContentPane().add(panel);
frame.show();


with:


frame.getContentPane().add(panel);
frame.pack();
frame.setSize(255, 255);
frame.show();