Hello Forum, Vaironl here.
I'm going to ask a question, that will most likely annoy you all, but first let me say this, I did some research but cannot use a Jscrollbar efficiently.
That being said, I want to give more details.
I'm trying to add a scrollbar to a panel which is going to contain JLabels and JTextFields.
It will contain 40 of each ones.
It should be set to the East.
I only need a vertical scrollbar since this will be a test only.
I actually am making a test program instead of my main project for testing purposes, since it has worked before this way when I had any problems.
Here is the test with the things I'm doing wrong.
Main class
import javax.swing.*;
public class Driver {
public static void main(String[] args)
{
Frame frame = new Frame();
}
}
Panel
import java.awt.Color;
import javax.swing.*;
public class Panel extends JPanel{
JTextField field[] = new JTextField[40];
public Panel()
{
setBackground(Color.red);
for(int i=0;i<40;i++)
{
field[i] = new JTextField(40);
field[i].setText("Field["+(i+1)+"]");
add(field[i]);
}
}
}
Frame
import java.awt.BorderLayout;
import javax.swing.*;
public class Frame extends JFrame
{
JScrollBar ver = new JScrollBar(JScrollBar.VERTICAL);
Panel panel = new Panel();
public Frame()
{
super("Testing Scroller");
setLayout(null);
ver.setLocation(0,0);
ver.setSize(400,500);
panel.setSize(500,500);
ver.add(panel);
add(ver);
setSize(800,600);
setLocation(10,30);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}