Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bhargava

macrumors newbie
Original poster
Aug 1, 2007
1
0
Hi,
The code i mentioned below is not working for me.
Code:
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

macrumors regular
Feb 27, 2006
243
0
Kent, United Kingdom
You need to replace:

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

with:

Code:
frame.getContentPane().add(panel);
        frame.pack();
        frame.setSize(255, 255);
        frame.show();
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.