Solved

JScrollPane w/JTextArea not visible

Posted on 2004-09-15
7
1,259 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
json example 39 132
where is session ID cache stored 1 46
Core Java. What output will be and why ? 6 66
PDFBox - convert image to PDF, PDF resolution 3 117
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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

912 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

17 Experts available now in Live!

Get 1:1 Help Now