Solved

JScrollPane w/JTextArea not visible

Posted on 2004-09-15
7
1,295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
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.
Suggested Courses

634 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