PDA

View Full Version : ScrollPane Doesn't Show




Alvinkiang
Apr 24, 2006, 10:07 PM
My Program read a XML file and Display the textArea according to the location it read.. which goes something like:


text=new JTextArea("",10,5);
text.setBounds(newPos[2*total1],newPos[2*total1+1],200,200);
panel.add(text);


I ADDED in the Scrollpane:

text=new JTextArea("",10,5);
text.setText("Item");
// text.setLineWrap(true);
text.setBounds(newPos[2*total1],newPos[2*total1+1],200,200);
// JScrollPane p= new JScrollPane(text);
text.setEditable(false);
// p.setPreferredSize(new Dimension(450, 110));
// panel.add(p, BorderLayout.SOUTH);
panel.add(text);


2 problem Faced... Firstly the lineWrap mess up all my location setting and Second is my Scrollpane code Wrong in any place?



mrichmon
Apr 24, 2006, 10:41 PM
I ADDED in the Scrollpane:

text=new JTextArea("",10,5);
text.setText("Item");
// text.setLineWrap(true);
text.setBounds(newPos[2*total1],newPos[2*total1+1],200,200);
// JScrollPane p= new JScrollPane(text);
text.setEditable(false);
// p.setPreferredSize(new Dimension(450, 110));
// panel.add(p, BorderLayout.SOUTH);
panel.add(text);

2 problem Faced... Firstly the lineWrap mess up all my location setting and Second is my Scrollpane code Wrong in any place?

The code you show is adding the TextArea to the panel when you should be adding the scrollpane.

A couple of months back another poster had similar problems. I threw together a quick piece of example code and posted it in this thread: http://forums.macrumors.com/showthread.php?p=2156406#post2156406

My comments (and those by others) there about getting into good habits with regard to variable names and spacing out of code would also apply to you based on the code snippet you posted. If the code is readable and structured it is far easier to follow what is going on. It makes it easy for others to help you and suprisingly enough makes it easier for you to understand your own code.