Scrollpane é exibido na tela mas não rola[resolvido]

10 respostas
P

Oi
to cm um serio problema ,preciso adicionar uma scrollpane em uma tela para que os itens que serão exibidos possam ser visualizados ja que a tela é pequena mas tipo eu tenho q exibir uma tabela tmbm e se eu adiciono a scroll a tabela aparece mas não posso clicar nela bm ja li outros foruns e tentei varias de varias formas fazer isto mas qnd a sroll aparece na tela ela não rola e trava os outros elementos tmbm.
Tentei add as coisas(jlabel,jtextfield)em um painel,add este painel na scroll e depois add a scroll ao getcontentpane();
tentei cm jdesktoppane…
Alguem pode me ajudar ou me dar um exemplo de como inserir um jscrollpane em um jinternalframe?
obg

10 Respostas

leonardobhbr

Para funcionar crie um JPanel set a propriedade para o tamanho que ele vai ocupar

dele

e ao inves de chamar o metodo

chame

P
ola leonardobhbr! tentei fazer o q vc disse fiz algo assim
painel.setLayout(null);
		painel.preferredSize();
		JScrollPane barra=new JScrollPane();
		barra.setViewportView(painel);

		barra.setHorizontalScrollBarPolicy(
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

		barra.setVerticalScrollBarPolicy(
				JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

		barra.setVisible(true);barra.setSize(999,700);
		pa.add(barra);
painel é o meu painel pa é meu container barra é minha scroll

mas não deu mto certo pode me ajudar a encontrar o erro?
obg
=]

TheKill
painel.add(pa);
barra.add(painel);
P
ola TheKill! fiz o que tu me disseste mas não deu mto certo tipo a tela ficou sem nenhum componente inclusive a barra fiz o seguinte
painel.setLayout(null);
		painel.preferredSize();
		
		JScrollPane barra=new JScrollPane();
		//barra.setViewportView(painel);

		barra.setHorizontalScrollBarPolicy(
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

		barra.setVerticalScrollBarPolicy(
				JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

		barra.setVisible(true);
		barra.setSize(999,650);
		painel.add(pa);
		barra.add(painel);

o que fiz errado?
obg
=]

leonardobhbr
teste o seguinte codigo e adicione os componentes no "pnlFundo"
package br.com.rlider.emailnfe.view;

import javax.swing.JPanel;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import java.awt.CardLayout;
import java.awt.Dimension;


public class Teste extends JInternalFrame
{
	private static final long	serialVersionUID	= 1L;
	private JPanel					jContentPane		= null;
	private JScrollPane			scp					= null;
	private JPanel					pnlFundo				= null;

	public Teste()
	{
		super();
		initialize();
	}

	private void initialize()
	{
		this.setSize(400, 300);
		this.setContentPane(getJContentPane());
	}

	private JPanel getJContentPane()
	{
		if(jContentPane == null)
		{
			jContentPane = new JPanel();
			jContentPane.setLayout(new CardLayout());
			jContentPane.add(getScp(), getScp().getName());
		}
		return jContentPane;
	}

	private JScrollPane getScp()
	{
		if(scp == null)
		{
			scp = new JScrollPane();
			scp.setName("scp");
			scp.setViewportView(getPnlFundo());
			scp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		}
		return scp;
	}

	private JPanel getPnlFundo()
	{
		if(pnlFundo == null)
		{
			pnlFundo = new JPanel();
			pnlFundo.setLayout(null);
			pnlFundo.setPreferredSize(new Dimension(372, 264));
		}
		return pnlFundo;
	}
}
P

leonardobhbr
to testando seu cod tipo eu so add uma jlabel mas nao consegui visualizar esta tela tipo eu fiz estas alterações

JLabel x=new JLabel("ms"); private void initialize() { x.setBounds(20, 30, 150, 25); this.add(x); this.setSize(400, 300); this.setContentPane(getJContentPane()); this.setVisible(true); } public static void main(String args[]) { java.awt.EventQueue.invokeLater (new Runnable () { public void run () { new Teste().setVisible (true); } }); }
obg

leonardobhbr

Nao entendi muito bem vc que um JFrame ou JInternalFrame
JInternalFrame nao pode ser visualizado pel metodo “main” ele depende de uma tela q contenha um JDesktopPane para poder ser visualizado

P

meninos obrigada pela ajuda conseguimos!!!
quando eu vi o exemplo que tu postaste vi que faltou o seguinte item no meu codigo

ah e a parte da tabela agora funciona é que eu tava adicionando ela no getcontetpane e nao no painel

muito :smiley: brigada pela ajuda!!
=]

leonardobhbr
Teste o seguinte codigo se vc desejar que seja um JFrame
import javax.swing.SwingUtilities;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.CardLayout;
import javax.swing.JScrollPane;
import java.awt.Dimension;
import javax.swing.JButton;
import java.awt.Point;
import javax.swing.JLabel;


public class Frame extends JFrame
{
	private static final long	serialVersionUID	= 1L;
	private JPanel					jContentPane		= null;
	private JScrollPane			scp					= null;
	private JPanel					pnlFundo				= null;
	private JButton				jButton				= null;
	private JLabel					lblTeste				= null;

	public Frame()
	{
		super();
		initialize();
	}

	private JScrollPane getScp()
	{
		if(scp == null)
		{
			scp = new JScrollPane();
			scp.setName("scp");
			scp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
			scp.setViewportView(getPnlFundo());
			scp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		}
		return scp;
	}

	private JPanel getPnlFundo()
	{
		if(pnlFundo == null)
		{
			lblTeste = new JLabel();
			lblTeste.setPreferredSize(new Dimension(68, 450));
			lblTeste.setSize(new Dimension(94, 23));
			lblTeste.setLocation(new Point(81, 450));
			lblTeste.setText("Teste Scroll");
			pnlFundo = new JPanel();
			pnlFundo.setLayout(null);
			pnlFundo.setPreferredSize(new Dimension(374, 900));
			pnlFundo.setSize(new Dimension(374, 900));
			pnlFundo.add(getJButton(), null);
			pnlFundo.add(lblTeste, null);
		}
		return pnlFundo;
	}

	private void initialize()
	{
		this.setSize(400, 300);
		this.setPreferredSize(new Dimension(400, 300));
		this.setContentPane(getJContentPane());
		this.setTitle("JFrame");
	}

	private JPanel getJContentPane()
	{
		if(jContentPane == null)
		{
			jContentPane = new JPanel();
			jContentPane.setLayout(new CardLayout());
			jContentPane.add(getScp(), getScp().getName());
		}
		return jContentPane;
	}

	private JButton getJButton()
	{
		if(jButton == null)
		{
			jButton = new JButton();
			jButton.setSize(new Dimension(60, 60));
			jButton.setPreferredSize(new Dimension(60, 60));
			jButton.setLocation(new Point(180, 500));
		}
		return jButton;
	}

	public static void main(String[] args)
	{
		// TODO Auto-generated method stub
		SwingUtilities.invokeLater(new Runnable()
		{
			public void run()
			{
				Frame thisClass = new Frame();
				thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				thisClass.setVisible(true);
			}
		});
	}
}
P

ok
obg
=]

Criado 20 de janeiro de 2011
Ultima resposta 20 de jan. de 2011
Respostas 10
Participantes 3