#how do i make a scrollbar here?

45 messages · Page 1 of 1 (latest)

glossy light
rustic lynxBOT
#

This post has been reserved for your question.

Hey @glossy light! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

valid birch
#

using a JScrollPane encapsulate the panel that displays your information.
JScrollPane scrollablePanel = new JScrollPane(panel);

glossy light
#

im a beginner with java , first time making a JFrame program

#

i tried _ALWAYS, instead of _AS_NEEDED, but still doesnt show up.

valid birch
#

you are adding the JScrollPane to the panel not the JTextArea correct ?

glossy light
#

i have this.add(scroll); if u mean that

valid birch
#

what is this

glossy light
#

its the frame

#

i mean where every object is

#

the frame right?

valid birch
#

depends on the context of this if your class extends JPanel this refers to the JPanel not the frame and I don't know your context

glossy light
#

i mean i have a textarea , and i read a file into it but its longer than the textarea

#

and i want it to make scrollable if that makes sense to u

valid birch
#

I know. I just would like to see some code to actually help you.

glossy light
#

public class Program extends JFrame implements ActionListener{

#

thats how my code starts

#

this refers to the JFrame i believe.

valid birch
# glossy light public class Program extends JFrame implements ActionListener{

yeah that refers to the frame. I would expect your code to look something like this:

public class Program extends JFrame implements ActionListener{
...
    //Inside some method
    JTextArea display = new JTextArea ();
    //Some further configuration of the JTextArea
    
    //Declaring the JScrollPane
    JScrollPane scroll = new JScrollPane ( display );
    scroll.setVerticalScrollBarPolicy ( ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS );

    //Add Textarea to the frame by adding the JScrollPane
    this.add (scroll);
    
    //At the very end, after you added every component to the frame
    this.setVisible(true)
...
glossy light
#

yes, basically looks like this

valid birch
#

show me how that part looks like in your code

glossy light
#

this is the textarea and the scroll

#

txtarea = new JTextArea();
txtarea.setBounds(30, 150, 600, 225);
txtarea.setEditable(false);
scroll = new JScrollPane(txtarea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scroll.setVisible(true);
scroll.setBounds(630, 150, 20, 250);
txtarea.setBorder(BorderFactory.createEmptyBorder(0, 2, 2, 2));

#

if i set the bound manually for the scrollpane it does show up now

#

but i cant scroll the textarea

valid birch
#

from the code you have given me it should work. However, since it doesn't this leads me to believe that you haven't given me the full relevant code.

glossy light
#

what part of the code u want?
its a long code
i have a button that reads a txt file and writes it into the textarea

valid birch
#

I just need the code where you add all your components to the frame. That should be a single method

glossy light
valid birch
#

remove this.add(txtarea)

#

JScrollPane already contains your txtArea you are overlaying it

glossy light
#

then the textarea doesnt show up

valid birch
#

then show me the entire method please

glossy light
valid birch
#

are you using null layout ?

glossy light
#

SOLVED

#

if i set the bounds for the scroll it shows up just as i wanted

#

thank you so much man

rustic lynxBOT
# glossy light thank you so much man

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.