Help Please = JTextArea + JScrollPane

R

Russell

Can someone please point out my error and tell me why this JTextArea will
not activate the JScrollPane !!

====================================================
CODE BELOW
====================================================
import java.awt.*;
import javax.swing.*;

public class testing extends JFrame{

JTabbedPane Tabbed = new JTabbedPane();
JScrollPane Scroller = new JScrollPane();
JTextArea textArea = new JTextArea();
JPanel tab1Pan = new JPanel();
JPanel tab2Pan = new JPanel();

public testing() {
jbInit();
}

private void jbInit() {
setSize(800, 600);
textArea.setPreferredSize(new Dimension(760, 520));
textArea.setWrapStyleWord(true);

Scroller.setHorizontalScrollBarPolicy(

JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

Scroller.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
Scroller.getViewport().add(textArea, null);
tab1Pan.add(Scroller);
Tabbed.addTab("TAB 2", tab1Pan);
Tabbed.addTab("TAB 2", tab2Pan);
getContentPane().add(Tabbed);
}

public static void main(String[] args) {
testing frame = new testing();
JFrame.setDefaultLookAndFeelDecorated(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
 
D

Dave Glasser

Can someone please point out my error and tell me why this JTextArea will
not activate the JScrollPane !!

I don't have time to figure out why your code isn't showing the
sliders on the scrollbars, even when the contents of the textarea is
bigger than the scrollpane, but I changed your code to the way I would
do it (sort of) and it worked:

private void jbInit() {
setSize(800, 600);
// textArea.setPreferredSize(new Dimension(760, 520)); // DELETE
textArea.setWrapStyleWord(true);

Scroller.setHorizontalScrollBarPolicy(

JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

Scroller.setVerticalScrollBarPolicy(

JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
Scroller.getViewport().add(textArea, null);
tab1Pan.setLayout(new BorderLayout()); // ADD
tab1Pan.add(Scroller, BorderLayout.CENTER); // CHANGE
// tab1Pan.add(Scroller);
Tabbed.addTab("TAB 2", tab1Pan);
Tabbed.addTab("TAB 2", tab2Pan);
getContentPane().add(Tabbed);
}


--
Check out QueryForm, a free, open source, Java/Swing-based
front end for relational databases.

http://qform.sourceforge.net

If you're a musician, check out RPitch Relative Pitch
Ear Training Software.

http://rpitch.sourceforge.net
 
R

Russell

I was dumb-founded why the bars would not scroll (or even appear as you
pointed out)

Problem solved.......

Thankyou!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top