Solved

JScrollPane w/JTextArea not visible

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
web services creation SOAP vs REST 5 80
Eclipse Help Java EE 5,6,7 Documentation, why not Java EE 8 8 40
junit as external jar or library 7 36
Java array 21 76
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 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 theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

679 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