?
Solved

Can I hide the scrollbar in JTextArea ?

Posted on 2005-03-06
14
Medium Priority
?
1,391 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
[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
  • 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
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!

 
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

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.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

764 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