Solved

JScrollPane w/JTextArea not visible

Posted on 2004-09-15
7
1,266 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
ID: 12067875
Can you post all the method in which you add the scroll pane?
0
 
LVL 92

Accepted Solution

by:
objects earned 400 total points
ID: 12071333
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
ID: 12071358
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
ID: 12071497
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
ID: 12109949
hello use the following code, it will work.

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

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

770 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