[RESOLVIDO] Tela com dois Fieldsets

8 respostas
P

Prezados,

Tenho que fazer uma tela conforme esta imagem .

Meu problema é que eu não consigo fazer dois FieldSets (aqueles retângulos em volta de cada grupo de funcionalidades).

Eu consigo fazer um só e mesmo assim tudo fica dentro dele e como vocês podem perceber existe um botão que fica fora do primeiro FieldSet.

Alguém sabe como resolver esse problema? Como fazer os dois FieldSets?

Se alguém puder postar o código só com os fiedsets e como colocar coisas por fora de cada um deles, não precisa ser o botão, pode ser qq objeto Component, eu ficaria muito agradecido.

8 Respostas

V

Você falou em fieldsets. Isso é web?

P

Prezado viniGodoy,

Não é web não, é Swing mesmo. Só que eu não sei o nome de um FieldSet em Java e nem sei se é possível fazer.

Eu fiz uma borda que no meu painel e deu a cara de um fieldset, mas por vc ter apenas um panel no jframe só dá pra fazer uma vez isso e eu preciso fazer como está na figura.

Segue meu código até o momento pra vc ver como está:
package configurarAlertaEstoque.main;

import java.awt.Color;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.WindowConstants;
import javax.swing.border.TitledBorder;

import org.apache.log4j.Logger;

import constants.StringConstants;

public class ExecutorConfiguradorAlertasEstoque extends JFrame {

	private final static Logger log = Logger
			.getLogger(ExecutorConfiguradorAlertasEstoque.class);

	/**
	 * 
	 */
	private static final long serialVersionUID = 8225254197047480128L;

	/**
	 * Launch the application.
	 */
	public static void main(final String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				try {
					final ExecutorConfiguradorAlertasEstoque frame = new ExecutorConfiguradorAlertasEstoque();
					frame.setVisible(true);
					frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
				} catch (final Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	private JLabel labelIdLoja = null;
	private JPanel painelConteudo = null;
	private JTextField textoIdLoja = null;
	private JButton botaoBuscar = null;
	private JComboBox comboAlertas = null;

	/**
	 * Create the frame.
	 */
	public ExecutorConfiguradorAlertasEstoque() {
		super();
		UIManager.put(StringConstants.GLOBAL_ACAO_DEFAULT_BOTOES, Boolean.TRUE);
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (final ClassNotFoundException e) {
			ExecutorConfiguradorAlertasEstoque.log
					.error(StringConstants.GLOBAL_FALHA_LAYOUT_WINDOWS);
		} catch (final InstantiationException e) {
			ExecutorConfiguradorAlertasEstoque.log
					.error(StringConstants.GLOBAL_FALHA_LAYOUT_WINDOWS);
		} catch (final IllegalAccessException e) {
			ExecutorConfiguradorAlertasEstoque.log
					.error(StringConstants.GLOBAL_FALHA_LAYOUT_WINDOWS);
		} catch (final UnsupportedLookAndFeelException e) {
			ExecutorConfiguradorAlertasEstoque.log
					.error(StringConstants.GLOBAL_FALHA_LAYOUT_WINDOWS);
		}
		this.initialize();
	}

	private void acaoBotaoSair() {
		if (JOptionPane.showOptionDialog(this,
				StringConstants.GLOBAL_DESEJA_REALMENTE_SAIR,
				StringConstants.GLOBAL_TITULO_SISTEMA,
				JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
				null, null) == JOptionPane.YES_OPTION) {
			this.dispose();
		}
	}

	private JButton getBotaoBuscar() {
		if (this.botaoBuscar == null) {
			this.botaoBuscar = new JButton(
					StringConstants.EXECUTOR_CONFIGURATOR_ALERTAS_ESTOQUE_LABEL_BOTAO_BUSCAR);
			this.botaoBuscar.setBounds(124, 12, 86, 20);
		}
		return this.botaoBuscar;
	}

	private JComboBox getComboAlertas() {
		if (this.comboAlertas == null) {
			this.comboAlertas = new JComboBox();
			this.comboAlertas.setMaximumRowCount(4);
			this.comboAlertas.setBounds(213, 12, 150, 22);
		}
		return this.comboAlertas;
	}

	private JLabel getLabelIdLoja() {
		if (this.labelIdLoja == null) {
			this.labelIdLoja = new JLabel(
					StringConstants.EXECUTOR_CONFIGURATOR_ALERTAS_ESTOQUE_LABEL_ID_LOJA);
			this.labelIdLoja.setBounds(8, 12, 62, 22);
		}
		return this.labelIdLoja;
	}

	private JPanel getPainelConteudo() {
		if (this.painelConteudo == null) {
			this.painelConteudo = new JPanel();
			this.painelConteudo.setLayout(null);
			this.painelConteudo.setBorder(new TitledBorder(BorderFactory
					.createLineBorder(Color.black),
					StringConstants.GLOBAL_BUSCA));
			// Adicionando componente ao painel.
			this.painelConteudo.add(this.getLabelIdLoja());
			// Adicionando componente ao painel.
			this.painelConteudo.add(this.getTextoIdLoja());
			// Adicionando componente ao painel.
			this.painelConteudo.add(this.getBotaoBuscar());
			// Adicionando componente ao painel.
			this.painelConteudo.add(this.getComboAlertas());
			this.painelConteudo.setBounds(100, 100, 100, 100);
		}
		return this.painelConteudo;
	}

	private JTextField getTextoIdLoja() {
		if (this.textoIdLoja == null) {
			this.textoIdLoja = new JTextField();
			this.textoIdLoja.setBounds(50, 12, 70, 20);
			this.textoIdLoja.requestFocusInWindow();
		}
		return this.textoIdLoja;
	}

	/**
	 * 
	 */
	private void initialize() {
		this.setBounds(100, 100, 450, 300);
		this.setContentPane(this.getPainelConteudo());
		this.setLocationRelativeTo(null);
		this.setResizable(false);
		this.setTitle(br.com.comprafacil.configurarAlertaEstoque.constants.StringConstants.GLOBAL_TITULO_SISTEMA);
		this.addWindowListener(new java.awt.event.WindowAdapter() {
			@Override
			public void windowClosing(final java.awt.event.WindowEvent e) {
				ExecutorConfiguradorAlertasEstoque.this.acaoBotaoSair();
			}
		});
	}
}
As Strings utilizadas nesta classe estão aqui:
public final class StringConstants {

	public static final String EXECUTOR_CONFIGURATOR_ALERTAS_ESTOQUE_LABEL_ID_LOJA = "ID Loja:"; //$NON-NLS-1$

	public static final String GLOBAL_ACAO_DEFAULT_BOTOES = "Button.defaultButtonFollowsFocus"; //$NON-NLS-1$

	public static final String GLOBAL_BUSCA = "Busca"; //$NON-NLS-1$

	public static final String GLOBAL_DESEJA_REALMENTE_SAIR = "Deseja realmente sair?"; //$NON-NLS-1$

	public static final String GLOBAL_FALHA_LAYOUT_WINDOWS = "Tentativa de iniciar sistema com layout de aplicações para Windows falhou."; //$NON-NLS-1$

	public static final String GLOBAL_TITULO_SISTEMA = "Alertas de Estoque"; //$NON-NLS-1$

	public static final String EXECUTOR_CONFIGURATOR_ALERTAS_ESTOQUE_LABEL_BOTAO_BUSCAR = "Buscar"; //$NON-NLS-1$

}
V

É verdade, vc pode ter um único panel dentro do JFrame.
Mas nada impede de vc ter outros panels sobre esse panel. :slight_smile:

A solução para seu problema é justamente essa. Primeiro, crie áreas distintas usando paineis, para só depois colocar os componentes sobre eles.

P

Prezado ViniGodoy,

Foi exatamente minha solução… Já vou postar o código e editar o problema para resolvido.

P

Conforme prometido, seguem os códigos:

package main;

import java.awt.Component;
import java.awt.Toolkit;
import java.awt.event.WindowEvent;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.WindowConstants;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;

import org.apache.log4j.Logger;

import constants.StringConstants;
import helper.FocusTraversalOnArray;

public class ExecutorConfiguradorAlertasEstoque extends JFrame {

	private final static Logger log = Logger
			.getLogger(ExecutorConfiguradorAlertasEstoque.class);

	private static final long serialVersionUID = 8225254197047480128L;

	/**
	 * Launch the application.
	 */
	public static void main(final String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				try {
					final ExecutorConfiguradorAlertasEstoque frame = new ExecutorConfiguradorAlertasEstoque();
					frame.setVisible(true);
					frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
				} catch (final Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	private JButton botaoAdicionarEmail = null;
	private JButton botaoAdicionarReferencia = null;
	private JButton botaoBuscar = null;
	private JButton botaoDesativar = null;
	private JButton botaoExcluirEmail = null;
	private JButton botaoExcluirReferencia = null;
	private JButton botaoNovo = null;
	private JButton botaoSalvar = null;
	private JCheckBox checkBoxAtivo = null;
	private JComboBox comboAlertas = null;
	private JComboBox comboLoja = null;
	private JLabel labelEmail = null;
	private JLabel labelIdLoja = null;
	private JLabel labelLoja = null;
	private JLabel labelMargem = null;
	private JLabel labelNome = null;
	private JLabel labelReferencia = null;
	private JPanel painelAlertas = null;
	private JPanel painelBusca = null;
	private JPanel painelConteudo = null;
	private JScrollPane painelScrollTabelaAlerta = null;
	private JScrollPane painelScrollTabelaEmail = null;
	private JTable tabelaEmail = null;
	private JTable tabelaReferencia = null;
	private JTextField textoEmail = null;
	private JTextField textoIdLoja = null;
	private JTextField textoMargem = null;
	private JTextField textoNomeAlerta = null;
	private JTextField textoReferencia = null;

	/**
	 * Create the frame.
	 */
	private ExecutorConfiguradorAlertasEstoque() {
		super();
		UIManager.put(StringConstants.GLOBAL_ACAO_DEFAULT_BOTOES, Boolean.TRUE);
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (final ClassNotFoundException e) {
			ExecutorConfiguradorAlertasEstoque.log
					.error(StringConstants.GLOBAL_FALHA_LAYOUT_WINDOWS);
		} catch (final InstantiationException e) {
			ExecutorConfiguradorAlertasEstoque.log
					.error(StringConstants.GLOBAL_FALHA_LAYOUT_WINDOWS);
		} catch (final IllegalAccessException e) {
			ExecutorConfiguradorAlertasEstoque.log
					.error(StringConstants.GLOBAL_FALHA_LAYOUT_WINDOWS);
		} catch (final UnsupportedLookAndFeelException e) {
			ExecutorConfiguradorAlertasEstoque.log
					.error(StringConstants.GLOBAL_FALHA_LAYOUT_WINDOWS);
		}
		this.initialize();
	}

	private JButton getBotaoAdicionarEmail() {
		if (this.botaoAdicionarEmail == null) {
			this.botaoAdicionarEmail = new JButton(
					StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_ADICIONAR);
			this.botaoAdicionarEmail.setBounds(400, 160, 78, 20);
		}
		return this.botaoAdicionarEmail;
	}

	private JButton getBotaoAdicionarReferencia() {
		if (this.botaoAdicionarReferencia == null) {
			this.botaoAdicionarReferencia = new JButton(
					StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_ADICIONAR);
			this.botaoAdicionarReferencia.setBounds(400, 63, 78, 20);
		}
		return this.botaoAdicionarReferencia;
	}

	private JButton getBotaoBuscar() {
		if (this.botaoBuscar == null) {
			this.botaoBuscar = new JButton(
					StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_BUSCAR);
			this.botaoBuscar
					.setIcon(new ImageIcon(
							StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_CAMINHO_ICONE_BOTAO_BUSCAR));
			this.botaoBuscar.setBounds(142, 15, 86, 22);
		}
		return this.botaoBuscar;
	}

	private JButton getBotaoDesativar() {
		if (this.botaoDesativar == null) {
			this.botaoDesativar = new JButton(
					StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_DESATIVAR);
			this.botaoDesativar.setBounds(74, 259, 80, 20);
		}
		return this.botaoDesativar;
	}

	private JButton getBotaoExcluirEmail() {
		if (this.botaoExcluirEmail == null) {
			this.botaoExcluirEmail = new JButton(
					StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_EXCLUIR);
			this.botaoExcluirEmail.setBounds(480, 160, 65, 20);
		}
		return this.botaoExcluirEmail;
	}

	private JButton getBotaoExcluirReferencia() {
		if (this.botaoExcluirReferencia == null) {
			this.botaoExcluirReferencia = new JButton(
					StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_EXCLUIR);
			this.botaoExcluirReferencia.setBounds(480, 63, 65, 20);
		}
		return this.botaoExcluirReferencia;
	}

	private JButton getBotaoNovo() {
		if (this.botaoNovo == null) {
			this.botaoNovo = new JButton(
					StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_NOVO);
			this.botaoNovo.setBounds(536, 57, 59, 23);
		}
		return this.botaoNovo;
	}

	private JButton getBotaoSalvar() {
		if (this.botaoSalvar == null) {
			this.botaoSalvar = new JButton(
					StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_SALVAR);
			this.botaoSalvar.setBounds(8, 259, 64, 20);
		}
		return this.botaoSalvar;
	}

	private JCheckBox getCheckBoxAtivo() {
		if (this.checkBoxAtivo == null) {
			this.checkBoxAtivo = new JCheckBox(
					StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_CHECKBOX_ATIVO);
			this.checkBoxAtivo.setBounds(318, 39, 50, 20);
		}
		return this.checkBoxAtivo;
	}

	private JComboBox getComboAlertas() {
		if (this.comboAlertas == null) {
			this.comboAlertas = new JComboBox();
			this.comboAlertas.setMaximumRowCount(4);
			this.comboAlertas.setBounds(233, 15, 202, 22);
		}
		return this.comboAlertas;
	}

	private JComboBox getComboLoja() {
		if (this.comboLoja == null) {
			this.comboLoja = new JComboBox();
			this.comboLoja.setMaximumRowCount(4);
			this.comboLoja.setBounds(66, 15, 150, 22);
		}
		return this.comboLoja;
	}

	private JLabel getLabelEmail() {
		if (this.labelEmail == null) {
			this.labelEmail = new JLabel(StringConstants.GLOBAL_EMAIL);
			this.labelEmail.setBounds(8, 160, 46, 20);
		}
		return this.labelEmail;
	}

	private JLabel getLabelIdLoja() {
		if (this.labelIdLoja == null) {
			this.labelIdLoja = new JLabel(
					StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_ID_LOJA);
			this.labelIdLoja.setBounds(8, 16, 46, 20);
		}
		return this.labelIdLoja;
	}

	private JLabel getLabelLoja() {
		if (this.labelLoja == null) {
			this.labelLoja = new JLabel(
					StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_LOJA);
			this.labelLoja.setBounds(8, 16, 24, 20);
		}
		return this.labelLoja;
	}

	private JLabel getLabelMargem() {
		if (this.labelMargem == null) {
			this.labelMargem = new JLabel(
					StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_MARGEM);
			this.labelMargem.setBounds(200, 64, 46, 20);
		}
		return this.labelMargem;
	}

	private JLabel getLabelNome() {
		if (this.labelNome == null) {
			this.labelNome = new JLabel(
					StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_NOME);
			this.labelNome.setBounds(8, 40, 32, 20);
		}
		return this.labelNome;
	}

	private JLabel getLabelReferencia() {
		if (this.labelReferencia == null) {
			this.labelReferencia = new JLabel(StringConstants.GLOBAL_REFERENCIA);
			this.labelReferencia.setBounds(8, 64, 58, 20);
		}
		return this.labelReferencia;
	}

	private JPanel getPainelAlertas() {
		if (this.painelAlertas == null) {
			this.painelAlertas = new JPanel();
			this.painelAlertas.setBounds(0, 83, 595, 284);
			this.painelAlertas
					.setBorder(new TitledBorder(
							null,
							StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LEGEND_FIELDSET_ALERTA,
							TitledBorder.LEADING, TitledBorder.TOP, null, null));
			this.painelAlertas.setLayout(null);
			this.painelAlertas.add(this.getLabelLoja());
			this.painelAlertas.add(this.getComboLoja());
			this.painelAlertas.add(this.getLabelNome());
			this.painelAlertas.add(this.getTextoNomeAlerta());
			this.painelAlertas.add(this.getCheckBoxAtivo());
			this.painelAlertas.add(this.getLabelReferencia());
			this.painelAlertas.add(this.getTextoReferencia());
			this.painelAlertas.add(this.getLabelMargem());
			this.painelAlertas.add(this.getTextoMargem());
			this.painelAlertas.add(this.getBotaoAdicionarReferencia());
			this.painelAlertas.add(this.getBotaoExcluirReferencia());
			this.painelAlertas.add(this.getPainelScrollTabelaAlerta());
			this.painelAlertas.add(this.getLabelEmail());
			this.painelAlertas.add(this.getTextoEmail());
			this.painelAlertas.add(this.getBotaoAdicionarEmail());
			this.painelAlertas.add(this.getBotaoExcluirEmail());
			this.painelAlertas.add(this.getPainelScrollTabelaEmail());
			this.painelAlertas.add(this.getBotaoSalvar());
			this.painelAlertas.add(this.getBotaoDesativar());
		}
		return this.painelAlertas;
	}

	private JPanel getPainelBusca() {
		if (this.painelBusca == null) {
			this.painelBusca = new JPanel();
			this.painelBusca.setBounds(0, 0, 595, 54);
			this.painelBusca
					.setBorder(new TitledBorder(
							null,
							StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LEGEND_FIELDSET_BUSCA,
							TitledBorder.LEADING, TitledBorder.TOP, null, null));
			this.painelBusca.setLayout(null);
			// Adicionando componente ao painel.
			this.painelBusca.add(this.getLabelIdLoja());
			// Adicionando componente ao painel.
			this.painelBusca.add(this.getTextoIdLoja());
			// Adicionando componente ao painel.
			this.painelBusca.add(this.getBotaoBuscar());
			// Adicionando componente ao painel.
			this.painelBusca.add(this.getComboAlertas());
		}
		return this.painelBusca;
	}

	private JPanel getPainelConteudo() {
		if (this.painelConteudo == null) {
			this.painelConteudo = new JPanel();
			this.painelConteudo.setLayout(null);
			// Adicionando componente ao painel.
			this.painelConteudo.add(this.getPainelBusca());
			// Adicionando componente ao painel.
			this.painelConteudo.add(this.getPainelAlertas());
			this.painelConteudo.add(this.getBotaoNovo());
			this.painelConteudo
					.setFocusTraversalPolicy(new FocusTraversalOnArray(
							new Component[] { this.getTextoIdLoja(),
									this.getBotaoBuscar(),
									this.getComboAlertas() }));

		}
		return this.painelConteudo;
	}

	private JScrollPane getPainelScrollTabelaAlerta() {
		if (this.painelScrollTabelaAlerta == null) {
			final JTable tabelaReferenciaVar = this.getTabelaReferencia();
			this.painelScrollTabelaAlerta = new JScrollPane(tabelaReferenciaVar);
			this.painelScrollTabelaAlerta
					.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
			this.painelScrollTabelaAlerta.setBounds(8, 87, 582, 71);
			this.painelScrollTabelaAlerta.setPreferredSize(tabelaReferenciaVar
					.getPreferredSize());
		}
		return this.painelScrollTabelaAlerta;
	}

	private JScrollPane getPainelScrollTabelaEmail() {
		if (this.painelScrollTabelaEmail == null) {
			this.painelScrollTabelaEmail = new JScrollPane(
					this.getTabelaEmail());
			this.painelScrollTabelaEmail
					.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
			this.painelScrollTabelaEmail.setBounds(8, 182, 582, 71);
		}
		return this.painelScrollTabelaEmail;
	}

	private JTable getTabelaEmail() {
		if (this.tabelaEmail == null) {
			this.tabelaEmail = new JTable();
			this.tabelaEmail.setEnabled(false);
			this.tabelaEmail.setModel(new DefaultTableModel(new Object[][] {
					{ null, null }, { null, null }, { null, null }, },
					new String[] { StringConstants.GLOBAL_ESPACO,
							StringConstants.GLOBAL_EMAIL }) {
				/**
						 * 
						 */
				private static final long serialVersionUID = 1031830474249153406L;

				boolean[] columnEditables = new boolean[] { false, false };

				Class<?>[] columnTypes = new Class[] { Boolean.class,
						String.class };

				@Override
				public Class<?> getColumnClass(final int columnIndex) {
					return this.columnTypes[columnIndex];
				}

				@Override
				public boolean isCellEditable(
						@SuppressWarnings("unused") final int row,
						final int column) {
					return this.columnEditables[column];
				}
			});
			final TableColumnModel colunas = this.tabelaEmail.getColumnModel();
			final TableColumn coluna = colunas.getColumn(0);
			coluna.setResizable(false);
			coluna.setPreferredWidth(15);
			final TableColumn colunaEmail = colunas.getColumn(1);
			colunaEmail.setResizable(false);
			colunaEmail.setPreferredWidth(567);
		}
		return this.tabelaEmail;
	}

	private JTable getTabelaReferencia() {
		if (this.tabelaReferencia == null) {
			this.tabelaReferencia = new JTable();
			this.tabelaReferencia.setEnabled(false);
			this.tabelaReferencia
					.setModel(new DefaultTableModel(
							new Object[][] { { null, null, null, null },
									{ null, null, null, null },
									{ null, null, null, null }, },
							new String[] {
									StringConstants.GLOBAL_ESPACO,
									StringConstants.GLOBAL_REFERENCIA,
									StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_CABECALHO_TABELA_REFERENCIA_COLUNA_DESCRICAO,
									StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_CABECALHO_TABELA_REFERENCIA_COLUNA_MARGEM_SEGURANCA }) {
						/**
								 * 
								 */
						private static final long serialVersionUID = 8037678798262562338L;

						boolean[] columnEditables = new boolean[] { false,
								false, false, false };

						Class<?>[] columnTypes = new Class[] { Boolean.class,
								Integer.class, String.class, Integer.class };

						@Override
						public Class<?> getColumnClass(final int columnIndex) {
							return this.columnTypes[columnIndex];
						}

						@Override
						public boolean isCellEditable(
								@SuppressWarnings("unused") final int row,
								final int column) {
							return this.columnEditables[column];
						}
					});
			final TableColumnModel colunas = this.tabelaReferencia
					.getColumnModel();
			final TableColumn coluna = colunas.getColumn(0);
			coluna.setResizable(false);
			coluna.setPreferredWidth(15);
			final TableColumn colunaReferencia = colunas.getColumn(1);
			colunaReferencia.setResizable(false);
			colunaReferencia.setPreferredWidth(60);
			final TableColumn colunaDescricao = colunas.getColumn(2);
			colunaDescricao.setResizable(false);
			colunaDescricao.setPreferredWidth(400);
			final TableColumn colunaMargem = colunas.getColumn(3);
			colunaMargem.setResizable(false);
			colunaMargem.setPreferredWidth(107);

		}
		return this.tabelaReferencia;
	}

	private JTextField getTextoEmail() {
		if (this.textoEmail == null) {
			this.textoEmail = new JTextField();
			this.textoEmail.setBounds(63, 160, 250, 20);
			this.textoEmail.setColumns(10);
		}
		return this.textoEmail;
	}

	private JTextField getTextoIdLoja() {
		if (this.textoIdLoja == null) {
			this.textoIdLoja = new JTextField();
			this.textoIdLoja.setBounds(48, 15, 86, 22);
			this.textoIdLoja.setColumns(10);
		}
		return this.textoIdLoja;
	}

	private JTextField getTextoMargem() {
		if (this.textoMargem == null) {
			this.textoMargem = new JTextField();
			this.textoMargem.setBounds(248, 63, 86, 20);
			this.textoMargem.setColumns(10);
		}
		return this.textoMargem;
	}

	private JTextField getTextoNomeAlerta() {
		if (this.textoNomeAlerta == null) {
			this.textoNomeAlerta = new JTextField();
			this.textoNomeAlerta.setBounds(66, 39, 250, 22);
			this.textoNomeAlerta.setColumns(30);
		}
		return this.textoNomeAlerta;
	}

	private JTextField getTextoReferencia() {
		if (this.textoReferencia == null) {
			this.textoReferencia = new JTextField();
			this.textoReferencia.setBounds(66, 63, 100, 20);
			this.textoReferencia.setColumns(10);
		}
		return this.textoReferencia;
	}

	/**
	 * 
	 */
	private void initialize() {
		this.setBounds(100, 100, 600, 390);
		this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
		this.setIconImage(Toolkit
				.getDefaultToolkit()
				.getImage(
						StringConstants.TELA_EXECUTOR_CONFIGURADOR_ALERTAS_CAMINHO_ICONE_TELA));
		this.setContentPane(this.getPainelConteudo());
		this.setLocationRelativeTo(null);
		this.setResizable(false);
		this.setTitle(StringConstants.GLOBAL_TITULO_SISTEMA);
		this.addWindowListener(new java.awt.event.WindowAdapter() {
			@Override
			public void windowClosing(
					@SuppressWarnings("unused") final WindowEvent e) {
				if (JOptionPane.showOptionDialog(
						ExecutorConfiguradorAlertasEstoque.this,
						StringConstants.GLOBAL_DESEJA_REALMENTE_SAIR,
						StringConstants.GLOBAL_TITULO_SISTEMA,
						JOptionPane.YES_NO_OPTION,
						JOptionPane.QUESTION_MESSAGE, null, null, null) == JOptionPane.YES_OPTION) {
					ExecutorConfiguradorAlertasEstoque.this.dispose();
				}
			}
		});
	}
}

As Strings

package constants;

public final class StringConstants {

	public static final String GLOBAL_ACAO_DEFAULT_BOTOES = "Button.defaultButtonFollowsFocus"; //$NON-NLS-1$

	public static final String GLOBAL_DESEJA_REALMENTE_SAIR = "Deseja realmente sair?"; //$NON-NLS-1$

	public static final String GLOBAL_EMAIL = "E-mail:"; //$NON-NLS-1$

	public static final String GLOBAL_ESPACO = " "; //$NON-NLS-1$

	public static final String GLOBAL_FALHA_LAYOUT_WINDOWS = "Tentativa de iniciar sistema com layout de aplicações para Windows falhou."; //$NON-NLS-1$

	public static final String GLOBAL_REFERENCIA = "Refer\u00EAncia:"; //$NON-NLS-1$

	public static final String GLOBAL_TITULO_SISTEMA = "Alertas de Estoque"; //$NON-NLS-1$

	public static final String TELA_EXECUTOR_CONFIGURADOR_ALERTAS_CABECALHO_TABELA_REFERENCIA_COLUNA_DESCRICAO = "Descri\u00E7\u00E3o"; //$NON-NLS-1$

	public static final String TELA_EXECUTOR_CONFIGURADOR_ALERTAS_CABECALHO_TABELA_REFERENCIA_COLUNA_MARGEM_SEGURANCA = "Margem Seguran\u00E7a"; //$NON-NLS-1$

	public static final String TELA_EXECUTOR_CONFIGURADOR_ALERTAS_CAMINHO_ICONE_BOTAO_BUSCAR = "\\images\\find.png"; //$NON-NLS-1$

	public static final String TELA_EXECUTOR_CONFIGURADOR_ALERTAS_CAMINHO_ICONE_TELA = "\\images\\logo.jpg"; //$NON-NLS-1$

	public static final String TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_ADICIONAR = "Adicionar"; //$NON-NLS-1$

	public static final String TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_BUSCAR = "Buscar"; //$NON-NLS-1$

	public static final String TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_DESATIVAR = "Desativar"; //$NON-NLS-1$

	public static final String TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_EXCLUIR = "Excluir"; //$NON-NLS-1$

	public static final String TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_NOVO = "Novo"; //$NON-NLS-1$

	public static final String TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_BOTAO_SALVAR = "Salvar"; //$NON-NLS-1$

	public static final String TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_CHECKBOX_ATIVO = "Ativo"; //$NON-NLS-1$

	public static final String TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_ID_LOJA = "ID Loja:"; //$NON-NLS-1$

	public static final String TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_LOJA = "Loja:"; //$NON-NLS-1$

	public static final String TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_MARGEM = "Margem:"; //$NON-NLS-1$

	public static final String TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LABEL_NOME = "Nome:"; //$NON-NLS-1$

	public static final String TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LEGEND_FIELDSET_ALERTA = "Alerta"; //$NON-NLS-1$

	public static final String TELA_EXECUTOR_CONFIGURADOR_ALERTAS_ESTOQUE_LEGEND_FIELDSET_BUSCA = "Busca"; //$NON-NLS-1$

}

E finalmente o gerenciador de tabulação:

/*******************************************************************************
 * Copyright (c) 2011 Google, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Google, Inc. - initial API and implementation
 *******************************************************************************/
package helper;

import java.awt.Component;
import java.awt.Container;
import java.awt.FocusTraversalPolicy;

/**
 * Cyclic focus traversal policy based on array of components.
 * <p>
 * This class may be freely distributed as part of any application or plugin.
 * 
 * @author scheglov_ke
 */
public class FocusTraversalOnArray extends FocusTraversalPolicy {
	private final Component m_Components[];

	// //////////////////////////////////////////////////////////////////////////
	//
	// Constructor
	//
	// //////////////////////////////////////////////////////////////////////////
	public FocusTraversalOnArray(final Component components[]) {
		this.m_Components = components;
	}

	private Component cycle(final Component currentComponent, final int delta) {
		int index = -1;
		loop: for (int i = 0; i &lt; this.m_Components.length; i++) {
			final Component component = this.m_Components[i];
			for (Component c = currentComponent; c != null; c = c.getParent()) {
				if (component == c) {
					index = i;
					break loop;
				}
			}
		}
		// try to find enabled component in &quot;delta&quot; direction
		final int initialIndex = index;
		while (true) {
			final int newIndex = this.indexCycle(index, delta);
			if (newIndex == initialIndex) {
				break;
			}
			index = newIndex;
			//
			final Component component = this.m_Components[newIndex];
			if (component.isEnabled() && component.isVisible()
					&& component.isFocusable()) {
				return component;
			}
		}
		// not found
		return currentComponent;
	}

	// //////////////////////////////////////////////////////////////////////////
	//
	// FocusTraversalPolicy
	//
	// //////////////////////////////////////////////////////////////////////////
	@Override
	public Component getComponentAfter(
			@SuppressWarnings(&quot;unused&quot;) final Container container,
			final Component component) {
		return this.cycle(component, 1);
	}

	@Override
	public Component getComponentBefore(
			@SuppressWarnings(&quot;unused&quot;) final Container container,
			final Component component) {
		return this.cycle(component, -1);
	}

	@Override
	public Component getDefaultComponent(final Container container) {
		return this.getFirstComponent(container);
	}

	@Override
	public Component getFirstComponent(
			@SuppressWarnings(&quot;unused&quot;) final Container container) {
		return this.m_Components[0];
	}

	@Override
	public Component getLastComponent(
			@SuppressWarnings(&quot;unused&quot;) final Container container) {
		return this.m_Components[this.m_Components.length - 1];
	}

	// //////////////////////////////////////////////////////////////////////////
	//
	// Utilities
	//
	// //////////////////////////////////////////////////////////////////////////
	private int indexCycle(final int index, final int delta) {
		final int size = this.m_Components.length;
		final int next = (index + delta + size) % size;
		return next;
	}
}

Lembrando que esta tela do sistema ainda está toda crua, sem funcionalidade alguma...

Gostaria de que se possível olhassem o código e apontassem melhorias.

Já estou estudando o framework ObjectTableModel para usar aqui ao invés de DefaultTableModel.

Me falaram também que no projeto Towel existe um gerenciador de eventos que é algo que muito me interessa. Acho muito "feio" ficar em cada objeto Component implementando ActionListeners, FocusListeners, KeyListeners e etc.

Fica aí minha contribuição e meu pedido de análise e também de ajuda!

Em anexo segue o ícone do botão buscar, não posso botar a logomarca da empresa, mas isso não é problema, é só substituir a imagem que eu uso por outra no teste de vocês.

G

Pode me dizer o nome do software que usou p fzr o prototipo da tela?
Abraço

P

Prezado Giovanni,

Eu uso o Google WindowBuilder Pro que é um plugin pro Eclipse e tem me atendido muito bem.

G

Valeu pgioseffi!

Criado 14 de abril de 2011
Ultima resposta 16 de abr. de 2011
Respostas 8
Participantes 3