Having trouble with scrollpanes

Hi all,

Been trying to get a scroll pane to work on a text area, problem is i don't fully understand how the frames are set up, and although i'm copying demos best i can all i get is the normal text area without the scroll bars on it.

This is my main piece of code for the frame, can someone tell me where i'm going wrong? Thanks

publicclass Chatextends JFrame

{

privatestatic JTextArea output =new JTextArea();

private JTextField toSend =new JTextField();

private ActionMap actionMap1 =new ActionMap();

private JLabel shortDisplay =new JLabel();

public BackgroundPanel bp =new BackgroundPanel();

public showAd showAd;

Image img;

public Chat()

{

try

{

jbInit();

}

catch(Exception e)

{

e.printStackTrace();

}

new getChatter().start();

new showAd().start();

}

class BackgroundPanelextends JPanel

{

Image img;

Image[] images =new Image[3];

String[] links =new String[3];

int imageCounter;

String link =new String("");

public BackgroundPanel()

{

}

publicvoid paintComponent(Graphics g)

{

super.paintComponent(g);

if(img !=null) g.drawImage(img, 0,0,this.getWidth(),this.getHeight(),this);

}

publicsynchronizedvoid addActionListener(ActionListener l)

{

listenerList.add(ActionListener.class, l);

}

publicvoid changeAd (String l, String ad)

{

//int temp = ++imageCounter % images.length;

try{

img = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource(ad), ad));

link = l;

repaint();

}

catch (Exception e){}

}

}

publicvoid jbInit()throws Exception

{

bp.setLayout(new GridBagLayout());

if(img !=null) bp.add(new JLabel(new ImageIcon(img)),new GridBagConstraints());

output.setEditable(false);

getContentPane().add(bp);

this.getContentPane().setLayout(null);

this.setSize(new Dimension(400, 379));

this.setTitle("Chat Window");

this.setResizable(false);

bp.setBounds(new Rectangle(5, 35, 380, 70));

bp.addMouseListener(new MouseAdapter(){

publicvoid mousePressed(MouseEvent me){

doSomethingForClick();}});

output.setBounds(new Rectangle(5, 110, 380, 185));

output.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));

output.setBackground(new Color(182, 197, 255));

JScrollPane outputPane =new JScrollPane(output,

JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,

JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

toSend.setBounds(new Rectangle(5, 310, 375, 25));

toSend.addActionListener(new ActionAdapter()

{

publicvoid actionPerformed(ActionEvent e){

String s = toSend.getText();

if (!s.equals("")){

toSend.setText("");

// Send the string

sendString(s);

Client.chat.append(s +"\n");

}

}

});

shortDisplay.setText(Client.name);

shortDisplay.setBounds(new Rectangle(10, 10, 125, 25));

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

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

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

this.getContentPane().add(outputPane);

}

[6695 byte] By [Kaligulaa] at [2007-10-2 18:26:07]
# 1
> this.getContentPane().add(output, null);Wrong. Just add your JScrollPane onto the contentpane.
hiwaa at 2007-7-13 19:47:12 > top of Java-index,Java Essentials,New To Java...
# 2
Thanks, but when i take out that line there just isn't a text area at all, so there must be a problem elsewhere too. Any ideas?
Kaligulaa at 2007-7-13 19:47:12 > top of Java-index,Java Essentials,New To Java...
# 3
Don't set layout to null.
hiwaa at 2007-7-13 19:47:12 > top of Java-index,Java Essentials,New To Java...