PDA

Click to See Complete Forum and Search --> : JScroll


DaoK
Apr 21st, 2002, 04:21 PM
How can I add a Jscroll in a jTextArea if my layout is NULL?

Thx you

DaoK
Apr 21st, 2002, 07:10 PM
I just want to add a scroll bar to a jTextArea. Any suggestion if my layout is null?

Dillinger4
Apr 21st, 2002, 08:34 PM
This is how it is normally done....

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

class Example{
public static void main(String[] args){

JScrollPane jsp = new JScrollPane(new JTextArea());
JFrame jf = new JFrame();
jf.addWindowListener(new WindowAdapter(){
public void WindowClosing(WindowEvent we){
System.exit(0);
}
});


Container c = jf.getContentPane();
c.add(jsp);

jf.setSize(200,150);
jf.setVisible(true);

}
}


But in order to position a component without the help of a layout manager you would have to use absoulte positioning. Normally you would want to use the setBounds() method which takes either a rectangle or x,y,width and height. I guess this could be good if you want the scroll bar wider then it normally is. You could also use setLocation() which takes a Point or x,y coordinates. :)

DaoK
Apr 22nd, 2002, 05:36 PM
thx you, !!! I mixed up the jscroll pane and the jtextarea

that what I had:
JTextArea text1 = new JTextArea(new JScrollPane);
and like you have gaven to me :
JScrollPane jsp = new JScrollPane(new JTextArea());


You see my error now ;)

Thx you Dilenger4 :)

Dillinger4
Apr 23rd, 2002, 02:18 PM
Your welcome. ;)