Adding Scroll to Display

Hi ive been reading through the scoll tutorials but still cant add a working scroll bar to my display. This is what ive come up with so far:

private JTextArea display, display2, textArea;

private JScrollPane scroll;

//setting up scroll bar.

display =new JTextArea(5, 30);

JScrollPane scrollPane =new JScrollPane(display);

setPreferredSize(new Dimension(450, 110));

add(scrollPane, BorderLayout.CENTER);

JScrollPane ScrollPane =new JScrollPane(display,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

//display which needs scroll bar

display =new JTextArea();

display.setText("" );

display.setBorder(new LineBorder(Color.BLACK));

display.setFont(new Font("Candara", Font.BOLD, 13));

display.setLineWrap(true);

display.setBackground(Color.WHITE);

display.setOpaque(true);

display.setBounds(10, 5, 420, 340);

mainPanel.add( display );

display.setLayout(null);

display.setEditable (false);

That is not the full code listing but everything that ive done to try and add a scoll pane to the listed display JTextarea.

What am i doing wrong?

Thanks

[1764 byte] By [rossma] at [2007-11-26 22:26:52]
# 1
Try this: http://forum.java.sun.com/thread.jspa?threadID=5149738
prometheuzza at 2007-7-10 11:28:50 > top of Java-index,Java Essentials,New To Java...
# 2
just had a look, i still cant work out how i would add that to my display
rossma at 2007-7-10 11:28:50 > top of Java-index,Java Essentials,New To Java...
# 3
> just had a look, i still cant work out how i would> add that to my displayDid you study and run the example?
prometheuzza at 2007-7-10 11:28:50 > top of Java-index,Java Essentials,New To Java...
# 4
yes, ive tried to add the parts i think i need to my program but it brings up your program in the background. Do i need any of the Frame code?
rossma at 2007-7-10 11:28:50 > top of Java-index,Java Essentials,New To Java...
# 5
What you need to do is (like in the example I linked to):- add the JTextArea to a JScrollPane;- add the JScrollPane directly on a JFrame or- add the JScrollPane first on some sort of JPanel and- add that JPanel to a JFrame.
prometheuzza at 2007-7-10 11:28:50 > top of Java-index,Java Essentials,New To Java...
# 6

> yes, ive tried to add the parts

Better would be to compile and run the example first, so you see what (should) happen.

> i think i need to my

> program but it brings up your program in the

> background. Do i need any of the Frame code?

I don't know. I haven't seen your code. I assume you have some sort of a (J)Frame (or an (J)Applet) to put all your GUI components on?

prometheuzza at 2007-7-10 11:28:50 > top of Java-index,Java Essentials,New To Java...
# 7

i have added a display JTextArea onto a panel. I need the display to have a scrollbar on it.

Not sure how else i can explain it. this is what ive done so far with the sample you posted.

JTextArea textArea = new JTextArea("ADDDING SCROLL BAR", 100, 200);

JScrollPane scrollPane = new JScrollPane(display);

scrollPane.add(textArea);

scrollPane.setSize(200, 200);

scrollPane.setVisible(true);

textArea.setBounds(1,1,100,100);

scrollPane.add(textArea);

this.add(textArea);

I have tried to just get the scroll bar working with a new textArea for the time being.

rossma at 2007-7-10 11:28:50 > top of Java-index,Java Essentials,New To Java...
# 8
Like I said before:- add the JTextArea to a JScrollPane, - add the JScrollPane to the JPanel (do not add the JTextArea to the JPanel!),- add the JPanel to a JFrame or JApplet.
prometheuzza at 2007-7-10 11:28:50 > top of Java-index,Java Essentials,New To Java...