Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SCROLLBAR ADDED BUT NOT WORKING IN TEXTAREA

 
Indu Anand
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HELLO! I WANT TO ADD A SCROLLBAR IN TEXTAREA USING JAVA SWING ,IT IS SHOWN BUT NOT ENABLED.......PLEASE TELL ME THE WHOLE CODE TO ENABLE MY SCROLLBAR..
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java is case-sensative.

you need a keyboard that is able to type
lower-case characters.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Indu,
Welcome to the Ranch!

You can checkout the tutorial that provides lot of information and examples for text components.

Also, please do not type in all caps. It is considered as 'shouting' on the internet and will put away people who are willing to help you.
 
Indu Anand
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have searched a lot on internet..but after creating a scrollbar..i am unable to enable this....can anybody give me a proper process & coding to do this.



my code is:-
JTextArea t1=new JTextArea();
t1.setEditable(false);

JScrollPane spn=new JScrollPane(t1);
spn.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

t1.setLineWrap(true);
f.add(t1);
f.add(spn);



now what more i need to do....if i need any kind of listener??? scrollbar is shown, but it is shown disable.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If yo had looked at the link you were given, you would have seen a tutorial link about using scroll panes. That has examples of what you want in.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> now what more i need to do.... scrollbar is shown, but it is shown disable.

the basics are that what is in the scrollpane/viewport must have a preferredSize larger than that of the scrollPane/viewport,
otherwise the scrollbar/s have nothing to scroll.

a lot depends on the layoutManager/s used.

if you want a solution, post a demo program so we can see what you're doing
i.e. just a textArea in a scrollPane in a JFrame
 
Indu Anand
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
more suggestions or code???please post a simple code for that....which has a working scrollbar in textarea using java..
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your code, you are adding both textarea and scrollpane to the 'f' variable. Once you create a JScrollPane by passing the text component, it is enough to add the scrollpane instance. There is no need to add both.
 
Indu Anand
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please explain your answer with proper & simple code....
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> please explain your answer with proper
> & simple code....

you are the one with the problem code.
post your code, or, if you actually have none,
pay someone to write it for you.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indu Anand wrote:please explain your answer with proper & simple code....

You provided some code and I have pointed out where the issue is in that code. Have you tried out my suggestions?
 
Indu Anand
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i have tried your suggestion.....but by not adding scrollpane to frame the scrollpane is not shown,so i have to add this...
 
Darryl Burke
Bartender
Posts: 5132
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranganathan Kaliyur Mannar wrote:In your code, you are adding both textarea and scrollpane to the 'f' variable. Once you create a JScrollPane by passing the text component, it is enough to add the scrollpane instance. There is no need to add both.


Indu Anand wrote:yes i have tried your suggestion.....but by not adding scrollpane to frame the scrollpane is not shown,so i have to add this...


Read the responses more carefully. And have you gone through the recommended tutorial yet?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic