?
Solved

Can I hide the scrollbar in JTextArea ?

Posted on 2005-03-06
14
Medium Priority
?
1,620 Views
Last Modified: 2008-02-01
Dear all,

For some reasons, I could not use JTextField, and instead, I need to use JTextArea.
The problem is when I set the size of JTextArea to (1,10) (rows=1, columns=10), I will see a scrollbar, no matter how I tried, the scrollbar is still there even if I set rows and columns to 0,0.

Is it possible to hide the scrollbar away ? if so, how can I do ?

Thanks,
Cristy
0
Comment
Question by:cristy56
  • 7
  • 6
14 Comments
 
LVL 92

Expert Comment

by:objects
ID: 13473655
if you do not want scroll bars then don't add the field to a scroll pane, instead add the text field directly.
alternately set the scroll pane policy to never display scroll bars.
0
 
LVL 5

Author Comment

by:cristy56
ID: 13473661
I haven't add the text field to scroll pane, but still the scrollbars are there, though they are grey and not activate...

Cristy
0
 
LVL 92

Expert Comment

by:objects
ID: 13473673
please post your code that adds the text field.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Author Comment

by:cristy56
ID: 13473682
FYR, snippet from my code as following :

private TextArea txt_cname = new TextArea(1,10);
:
txt_cname.setBounds(new Rectangle(150, 115, 200, 25));
:
this.getContentPane().add(txt_cname, null);



Cristy
0
 
LVL 5

Author Comment

by:cristy56
ID: 13473683
and the outcome is that the small textarea is almost covered up by the unwanting scrollbars.

Cristy
0
 
LVL 92

Expert Comment

by:objects
ID: 13473687
Thats a TextArea, *not* a JTextArea.
Are you using Swing or just AWT?
0
 
LVL 92

Accepted Solution

by:
objects earned 1600 total points
ID: 13473695
use the following TextArea constructor if you don't want scrollbars

http://java.sun.com/j2se/1.4.2/docs/api/java/awt/TextArea.html#TextArea(java.lang.String, int, int, int)
0
 
LVL 5

Author Comment

by:cristy56
ID: 13473704
Oops, sorry, I am using Swing JTextArea, just change it :

private JTextArea txt_cname = new JTextArea(1,10);
:
txt_cname.setBounds(new Rectangle(150, 115, 200, 25));
:
this.getContentPane().add(txt_cname, null);
 

0
 
LVL 92

Expert Comment

by:objects
ID: 13473708
changing it to JTextArea will get rid of the scroll bars :)
0
 
LVL 5

Author Comment

by:cristy56
ID: 13473802
I have changed to JTextArea, but the scroll bars are still there, but if I use TextArea(String, int, int, int), then the problem is solved, is it possible to have JTextArea working in the same way too ?

Cristy
0
 
LVL 92

Expert Comment

by:objects
ID: 13473891
> I have changed to JTextArea, but the scroll bars are still there

I can't see how that is possible, JTextArea does not have any scroll bars.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 13473985
As said by Mick,

JTextArea does not have any scrollbars. I Just tested this code. TextArea shows scrollbasrs. You need to recheck the code

Regards
Sudhakar

import java.awt.*;
import javax.swing.*;
class ScrollBarTest extends JFrame
{
      private JTextArea txt_cname = new JTextArea(1,10);
      private TextArea txt_cname1 = new TextArea(1,10);

      
      public ScrollBarTest()
      {
        JPanel panel=new JPanel();
        panel.add(txt_cname,new FlowLayout());
                panel.add(txt_cname1,new FlowLayout());
            txt_cname.setBounds(new Rectangle(150, 115, 200, 25));
            this.getContentPane().add(panel, null);

      }
      public static void main(String[] args)
      {
            System.out.println("Hello World!");
            ScrollBarTest test=new ScrollBarTest();
            test.setSize(700,700);
            test.setVisible(true);

      }
}
0
 
LVL 5

Author Comment

by:cristy56
ID: 13474447
Thanks for all your effort :)

Cristy
0
 
LVL 92

Expert Comment

by:objects
ID: 13474479
no worries :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
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:
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.
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

621 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