import javax.swing.*;
import java.awt.*;
class PanelScroll extends JPanel {
public PanelScroll() {
super();
this.setLayout(new GridLayout(100,1));
//Le introducimos componentes al JPanel para que tenga algo que mostrar
for(int i = 1; i < 100; i++)
this.add(new JLabel("Antony " + String.valueOf(i)));
return;
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Ventana extends JFrame {
public Ventana() {
//Generamos una instancia del JScroll y le agregamos un panel que tenga
// componentes para mostrar y asi poder desplazarnos con las barras
JScrollPane js = new JScrollPane(new PanelScroll());
//js.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
js.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
this.getContentPane().add(js);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent ev) {
System.exit(0);
}
});
this.setSize(100,200);
this.setTitle("Un buen ejemplo");
this.setVisible(true);
}
public static void main(String[] args) {
new Ventana();
}
}