#how do i make a scrollbar here?
45 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @glossy light! Please use
/closeor theClose Postbutton 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.
using a JScrollPane encapsulate the panel that displays your information.
JScrollPane scrollablePanel = new JScrollPane(panel);
doesnt work
im a beginner with java , first time making a JFrame program
i tried _ALWAYS, instead of _AS_NEEDED, but still doesnt show up.
you are adding the JScrollPane to the panel not the JTextArea correct ?
i have this.add(scroll); if u mean that
what is this
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
i found a solution to it to show up, but its not relative to the text in the textarea
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
I know. I just would like to see some code to actually help you.
public class Program extends JFrame implements ActionListener{
thats how my code starts
this refers to the JFrame i believe.
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)
...
yes, basically looks like this
show me how that part looks like in your code
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
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.
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
I just need the code where you add all your components to the frame. That should be a single method
remove this.add(txtarea)
JScrollPane already contains your txtArea you are overlaying it
then the textarea doesnt show up
then show me the entire method please
are you using null layout ?
SOLVED
if i set the bounds for the scroll it shows up just as i wanted
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.