JScrollPane + JPanel

Olá, tenho um painel setado com PreferedSize(1000,1000); Sendo que o JFrame é bem menor, e uma JScrollPane add o JPanel. Logo, as barras laterais são mostradas, até pq escolhi isso no momento de construir o JScrollPane.
No entanto, gostaria de saber, se é possível fazer um auto scroll na horizontal, apos entender esse evento, iria fazer uma Thread Sleep dispará-lo a cada x segundos. Tem como? Procurei sobre isso mas, só encontro coisas sobre JTextArea.

Vlw.
Atenciosamente.

Bom, fiz um exemplo simples, tem que fazer alguns ajustes para por exemplo detectar quando chegar
ao final da barra de rolagem cancelar o timer, mas no geral seria algo assim:

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;

public class TesteJF {

	public static void main(String[] args) throws Exception {
		JFrame f = new JFrame();
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setBounds(new Rectangle(500,500));
		JPanel painel = new JPanel(){
			public void paintComponent (Graphics g) {
				super.paintComponent(g);
				for(int x = 0; x < 1000; x+=20) {
					g.drawRect(x + 10, 250, 15, 15);
				}
			}
		};
		painel.setPreferredSize(new Dimension(1000,1000));
		final JScrollPane pane = new JScrollPane(painel);
		f.getContentPane().add(pane);
		TimerTask task = new TimerTask() {
			@Override
			public void run() {
				SwingUtilities.invokeLater(new Runnable() {
					
					@Override
					public void run() {
						pane.getHorizontalScrollBar().setValue(pane.getHorizontalScrollBar().getValue() + 1);
					}
				});
			}
		};
		f.setVisible(true);
		new Timer().schedule(task, 0, 10); 
	}

}

Até mais!

Use assim que fica mais prático.

setContentPane(new JScrollPane(getContentPane()));

[quote=WendersonLP]Use assim que fica mais prático.

setContentPane(new JScrollPane(getContentPane())); [/quote]

Ué, mas esse comando cria um novo ScrollPane. Acho que não tem nada a ver com o que ele pediu…

[quote=rogeriopaguilar]Bom, fiz um exemplo simples, tem que fazer alguns ajustes para por exemplo detectar quando chegar
ao final da barra de rolagem cancelar o timer, mas no geral seria algo assim:

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;

public class TesteJF {

	public static void main(String[] args) throws Exception {
		JFrame f = new JFrame();
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setBounds(new Rectangle(500,500));
		JPanel painel = new JPanel(){
			public void paintComponent (Graphics g) {
				super.paintComponent(g);
				for(int x = 0; x < 1000; x+=20) {
					g.drawRect(x + 10, 250, 15, 15);
				}
			}
		};
		painel.setPreferredSize(new Dimension(1000,1000));
		final JScrollPane pane = new JScrollPane(painel);
		f.getContentPane().add(pane);
		TimerTask task = new TimerTask() {
			@Override
			public void run() {
				SwingUtilities.invokeLater(new Runnable() {
					
					@Override
					public void run() {
						pane.getHorizontalScrollBar().setValue(pane.getHorizontalScrollBar().getValue() + 1);
					}
				});
			}
		};
		f.setVisible(true);
		new Timer().schedule(task, 0, 10); 
	}

}

Até mais![/quote]

Vlw brother, era isso aí msm.

Obrigado pela ajuda!

Atenciosamente, ArchV.

Então foi mal.