Mudar nome JPanel em execução

4 respostas
D

Quero mudar o Nome o JPanel em tempo de execução, por exemplo,

tenho 3 JPanel

Clientes
Funcionarios
Fornec

quero que quando eu executar uma consulta, se houvesse dados na consultar jogasse o valor junto com o nome do JPanel
se a consulta retornar um total de 5 registros deveria ficar assim

Clientes-5
Funcionarios-2
Fornec-0

??

4 Respostas

tRuNkSnEt

Sem querer encher o saco mas daria para ser mais conciso? Entendi nada … que exemplo foi esse?

reizin

Pelo que entendi você está querendo mudar o título da janela???
Se for, basta usar o setTitle("Título que vc quer").
Ex:

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;

public class Teste extends JFrame
{
	private JButton bt;

	public Teste( )
	{
		super("Cliente");
		Container container = getContentPane( );
		container.setLayout(new FlowLayout( ));
		bt = new JButton("Clique");
		container.add(bt);
		AcaoBotao acao = new AcaoBotao( );
		bt.addActionListener(acao);
		setSize(200, 120);
		setVisible(true);
	}

	public static void main(String args[])
	{
		Teste inicia = new Teste( );
		inicia.setDefaultCloseOperation(EXIT_ON_CLOSE);

	}

	private class AcaoBotao implements ActionListener
	{

		public void actionPerformed(ActionEvent evento)
		{

			if (evento.getSource( ) == bt)
			{
				setTitle("Cliente - 001");
			}
		}
	}
}

Falows!!!!

D

Acho que nao me expressei direito

Tenho um JPanel com 3 JTabbedPane

TabbedPane tb= new JTabbedPane();

JPanel jp1= new JPanel();

JPanel jp2= new JPanel();

JPanel jp3= new JPanel();

aqui dou o nome inicial:

c= getContentPane();

c.add(tb);

tb.add(Clients,jp1);

tb.add(Fornecedores,jp2);

tb.add(Funcionarios,jp3);

agora com o programa rodando… depois de executar uma consulta queria mudar os nomes acima para o resultado da consulta

tipo Cliente-5, fornecedores-6, Funcionarios-78

ok…?

reizin
danielp:
Acho que nao me expressei direito

Tenho um JPanel com 3 JTabbedPane

TabbedPane tb= new JTabbedPane();
JPanel jp1= new JPanel();
JPanel jp2= new JPanel();
JPanel jp3= new JPanel();

O contrário não ??? Um JTabbedPane e 3 JPanel... Mais isso não importa.

Use o setTitleAt(int i, String s)
http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JTabbedPane.html

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

public class Teste extends JFrame
{
	private JButton bt;

	JTabbedPane tb;

	public Teste( )
	{
		super("Cliente");
		Container container = getContentPane( );
		container.setLayout(new FlowLayout( ));
		bt = new JButton("Clique");
		container.add(bt);

		tb = new JTabbedPane( );
		JPanel jp1 = new JPanel( );
		JPanel jp2 = new JPanel( );
		JPanel jp3 = new JPanel( );

		tb.add("Clients", jp1);
		tb.add("Fornecedores", jp2);
		tb.add("Funcionarios", jp3);

		container.add(tb);

		AcaoBotao acao = new AcaoBotao( );
		bt.addActionListener(acao);
		setSize(300, 200);
		setVisible(true);

	}

	public static void main(String args[])
	{
		Teste inicia = new Teste( );
		inicia.setDefaultCloseOperation(EXIT_ON_CLOSE);

	}

	private class AcaoBotao implements ActionListener
	{

		public void actionPerformed(ActionEvent evento)
		{

			if (evento.getSource( ) == bt)
			{
				tb.setTitleAt(0, "Teste");
				tb.setTitleAt(1, "Teste - 01");
				tb.setTitleAt(2, "Teste - 02");

			}
		}
	}
}
Criado 7 de julho de 2005
Ultima resposta 8 de jul. de 2005
Respostas 4
Participantes 3