Solved

JScrollPane w/JTextArea not visible

Posted on 2004-09-15
7
1,253 Views
Last Modified: 2012-05-05
I am using the following to establish a JTextArea with scroll bars.  Problem is, it doesn't show up on execution.

JTextArea taCase = new JTextArea();
  JScrollPane jsp = new JScrollPane( taCase,
                    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                    JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
.
.
.
 contentPane.add( jsp );
 //contentPane.add(taCase );

What am I missing?
thanks,
je
0
Comment
Question by:jesterepsilon
7 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 100 total points
Comment Utility
Can you post all the method in which you add the scroll pane?
0
 
LVL 92

Accepted Solution

by:
objects earned 400 total points
Comment Utility
make sure you don't add the text area to your frame elsewhere in your code.
0
 
LVL 92

Assisted Solution

by:objects
objects earned 400 total points
Comment Utility
heres an example:

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

public class ScrollText
{
    public static void main(String[] args)
    {
        JFrame frame = new JFrame();
        Container contentPane = frame.getContentPane();
        JTextArea taCase = new JTextArea();
        JScrollPane jsp = new JScrollPane( taCase,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        contentPane.add( jsp );
        frame.setSize(100, 100);
        frame.show();
    }
}


0
 

Expert Comment

by:Emilda
Comment Utility
You didn't set the size. As objects suggested you need to set the size of frame if you are adding JScrollPane to
frame.getContentpane.

JScrollPane jsp = new JScrollPane( taCase, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JSrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

If you give JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JSrollPane.HORIZONTAL_SCROLLBAR_ALWAYS arguments when you create JScrollPane the scrollpane always appear.

You can also use as shown below as well, in this case scroll pane adds the scrollbars automatically (but only "as needed") when the cursor goes beyonds the size set to the content pane.

JScrollPane jsp = new JScrollPane( taCase)
0
 
LVL 5

Expert Comment

by:Naeemg
Comment Utility
hello use the following code, it will work.

jsp.getViewport().add(taCase, null);
contentPane.add( jsp );
 //contentPane.add(taCase );

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now