Erro na tela principal/ Erro Nimbus Look and feel

5 respostas
N

Boa noite pessoal, estou com um erro quando inicio minha tela principal, aparece uma janela, mas com nada dentro, como se nada tivesse visivel, mas quando eu minimizo ela e maximizo de novo, os componentes aparecem, alguém sabe como consertar isso?

Nimbus - Quero utilizar o Nimbus Look and fell, mas quando tento, minha tabbed pane fica só com a borda de cima, as outras somem e parece que ele é parte do JFrame, alguém sabe como arrumar?

5 Respostas

S

Olá amigo

sem o código para analisarmos fica difícil ajudá-lo.

Silvio Guedes

N
public class TelaLogin extends JFrame implements  ActionListener

{
	JButton btlogin = new JButton("Ok");
	JButton btcancelar = new JButton("Cancelar");
	JTextField txtlogin = new JTextField();
	JPasswordField txtsenha = new JPasswordField();    
	public static void main(String args[])
	{
		try 
		{
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		} 
		catch (UnsupportedLookAndFeelException e)
		{
		}
		catch (ClassNotFoundException e)
		{
		}
		catch (InstantiationException e)
		{
		}
		catch (IllegalAccessException e)
		{
		}
		finally
		{
			new TelaLogin();
		}
	}
	public TelaLogin()
	{
		super("Teste");
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setLayout(null);
		setResizable(false);
		setSize(600, 305);
		setLocationRelativeTo(null);
		setVisible(true);

		LeitorImagem li = new LeitorImagem();
		
		JLabel lbllogo;
		JLabel lblfundo;
		ImageIcon icon = li.CriaImagem("N:/TCC/Locare/Locare/Resources/caderno.png", this.getWidth(), this.getHeight(), 0, 0);
		ImageIcon logo = li.CriaImagem("N:/logo200.png", 200, 200, 0, 0);
		ImageIcon icone = new ImageIcon("N:/loguinho.png");  

		if(logo != null)
		{
			lbllogo = new JLabel(logo);
		}
		else
		{
			lbllogo = new JLabel("Imagem não encontrada");
		}
		if(icon != null)
		{
			lblfundo = new JLabel(icon);
		}
		else
		{
			lblfundo = new JLabel("Imagem não encontrada");
		}
		if(icone != null)
		{
			this.setIconImage(icone.getImage());
		}
		
		JLabel lbllogin = new JLabel("Login:");
		JLabel lblsenha = new JLabel("Senha:");

		//lbllogo.setBorder(BorderFactory.createEtchedBorder());

		lbllogo.setBounds(27, 36, 200, 200);
		lblfundo.setBounds(0, 0, this.getWidth(), this.getHeight());
		lbllogin.setBounds(287, 85, 100, 23);
		lblsenha.setBounds(282, 138, 100, 23);

		lbllogin.setFont(new Font("Anjelika Rose", Font.BOLD, 16));
		lblsenha.setFont(new Font("Anjelika Rose", Font.BOLD, 16));

		btlogin.setBounds(338, 193, 100, 23);
		btcancelar.setBounds(448, 193, 100, 23);

		btlogin.setMnemonic(KeyEvent.VK_ENTER);
		btcancelar.setMnemonic(KeyEvent.VK_C);

		btlogin.setToolTipText("Pressiona ALT + ENTER para acionar");
		btcancelar.setToolTipText("Pressiona ALT + C para acionar");

		txtlogin.setToolTipText("Digite seu Login aqui");
		txtsenha.setToolTipText("Digite sua senha aqui");

		btlogin.addActionListener(this);
		btcancelar.addActionListener(this);

		txtlogin.setBounds(338, 86, 212, 23);
		txtsenha.setBounds(338, 139, 212, 23);

		getContentPane().add(txtlogin);
		getContentPane().add(txtsenha);

		getContentPane().add(btcancelar);
		getContentPane().add(btlogin);

		getContentPane().add(lbllogo);
		getContentPane().add(lbllogin);
		getContentPane().add(lblsenha);

		getContentPane().add(lblfundo);
	}
}
S

Olá amigo

Onde está a parte de inicialização da tabbedpane “do minha tabbed pane fica só com a borda de cima”

está faltando algum código deste programa?

tem muitos exemplos aqui:

http://www.java2s.com/Code/Java/Swing-JFC/TabbedPane.htm

Dê uma olhada, acho que pode lhe ajudar.

Silvio Guedes

N

silviogs:
Olá amigo

Onde está a parte de inicialização da tabbedpane “do minha tabbed pane fica só com a borda de cima”

está faltando algum código deste programa?

tem muitos exemplos aqui:

http://www.java2s.com/Code/Java/Swing-JFC/TabbedPane.htm

Dê uma olhada, acho que pode lhe ajudar.

Silvio Guedes

Opa, desculpa amigo, me esqueci, segue aqui o mesmo

public class TelaAdd extends JFrame implements ActionListener
{
	BancoDeDados bd = new BancoDeDados();

	LeitorTXT letxt = new LeitorTXT();

	JButton btsal = new JButton("Salvar");
	JButton btlim = new JButton("Limpar");
	JButton btcan = new JButton("Cancelar");
	JButton btadd = new JButton("Adicionar");
	JButton btlimad = new JButton("Limpar");
	JButton btproend = new JButton("O");
	JButton btprocep = new JButton("O");
	JButton btaddmat = new JButton("+");
	JButton btremmat = new JButton("-");

	JTextField txtnome = new JTextField();
	JTextField txtcomp = new JTextField();
	JTextField txtrua = new JTextField();
	JTextField txtbairro = new JTextField();

	JRadioButton rbcpf = new JRadioButton("CPF");
	JRadioButton rbcnpj = new JRadioButton("CNPJ");

	JLabel lblcnpj = new JLabel("CPF:");
	
	MaskFormatter mcpf = Formatar("###.###.###-##");
	
	JFormattedTextField txtcep = new JFormattedTextField(Formatar("#####-###"));
	JFormattedTextField txtcepreg = new JFormattedTextField(Formatar("#####-###"));
	JFormattedTextField txttelres = new JFormattedTextField(Formatar("(##) ####-####"));
	JFormattedTextField txttelcel = new JFormattedTextField(Formatar("(##) #####-####"));
	JFormattedTextField txtregistro = new JFormattedTextField(mcpf);

	DefaultTableModel modelo = new DefaultTableModel(new String [] {"Tipo produto", "Produto", "Quantidade"}, 0);
	JTable tabela = new JTable(modelo);

	JDateChooser centrega = new JDateChooser();
	JDateChooser cretirada = new JDateChooser();

	JTextField txtend = new JTextField();
	JTextField txtnum = new JTextField();
	JTextField txtcom = new JTextField();
	JTextField txtbai = new JTextField();

	public TelaAdd()
	{
		super("Locare | Adicionar Pedidos");
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setLayout(null);
		setResizable(false);
		setSize(850, 550);
		setLocationRelativeTo(null);
		setVisible(true);

		DefaultTableCellRenderer numeros = new DefaultTableCellRenderer();
		numeros.setHorizontalAlignment(SwingConstants.CENTER);

		JScrollPane spmat = new JScrollPane(tabela);
		spmat.setBorder(BorderFactory.createEtchedBorder());

		JTabbedPane tpdados = new JTabbedPane();

		((DefaultTableCellRenderer) tabela.getTableHeader().getDefaultRenderer()).setHorizontalAlignment(SwingConstants.CENTER);
		tabela.getColumnModel().getColumn(2).setCellRenderer(numeros);
		tabela.getTableHeader().setReorderingAllowed(false);

		JPanel pdados = new JPanel();
		JPanel pdadosreg = new JPanel();

		//pdados
		JLabel lbltitulo = new JLabel("Novo Pedido");
		JLabel lblnome = new JLabel("Nome completo:");
		JLabel lbltelres = new JLabel("Telefone Residencial:");
		JLabel lbltelcel = new JLabel("Telefone Celular:");
		JLabel lblcomp = new JLabel("Complemento:");
		JLabel lblend = new JLabel("Endereço:");
		JLabel lblbairro = new JLabel("Bairro:");
		JLabel lblcep = new JLabel("CEP:");

		//pdadoreg
		JLabel lblendreg = new JLabel("Endereço:");
		JLabel lblnum = new JLabel("Nº:");
		JLabel lblcom = new JLabel("Complemento:");
		JLabel lblbai = new JLabel("Bairro:");
		JLabel lblhorfes = new JLabel("Hora da Festa:");
		JLabel lbldatent = new JLabel("Data da entrega:");
		JLabel lbldatret = new JLabel("Data da retirada:");

		ButtonGroup group = new ButtonGroup();

		lbltitulo.setFont(new Font("Anjelika Rose", Font.BOLD, 25));
		
		txtregistro.setEnabled(false);

		pdados.setLayout(null);
		pdadosreg.setLayout(null);
	 	
		spmat.setBounds(12, 224, 342, 267);

		rbcpf.setBounds(514, 92, 48, 20);
		rbcnpj.setBounds(568, 92, 60, 20);

		centrega.setBounds(407, 57, 140, 26);
		cretirada.setBounds(664, 57, 140, 26);

		//pdados
		lblnome.setBounds(27, 12, 110, 16);
		lbltelres.setBounds(30, 94, 128, 16);
		lbltelcel.setBounds(284, 94, 105, 16);
		lblend.setBounds(27, 54, 35, 16);
		lblcomp.setBounds(254, 53, 92, 16);
		lblbairro.setBounds(434, 54, 47, 16);
		lblcep.setBounds(658, 53, 35, 16);
		lblcnpj.setBounds(640, 94, 68, 16);

		//pdadosreg
		lblendreg.setBounds(16, 26, 66, 16);
		lblnum.setBounds(420, 26, 27, 16);
		lblcom.setBounds(496, 26, 92, 16);
		lblbai.setBounds(16, 63, 47, 16);
		lbldatent.setBounds(306, 63, 110, 13);
		lbldatret.setBounds(559, 63, 110, 13);
		lblhorfes.setBounds(227, 172, 88, 13);
		lblcep.setBounds(658, 12, 35, 16);


		//pdados
		txtnome.setBounds(130, 9, 502, 23);
		txtrua.setBounds(67, 50, 180, 23);
		txtcomp.setBounds(347, 49, 72, 23);
		txtbairro.setBounds(487, 50, 153, 23);
		txtcep.setBounds(695, 12, 100, 23);
		txttelres.setBounds(164, 89, 100, 27);
		txttelcel.setBounds(385, 89, 110, 27);
		txtregistro.setBounds(675, 89, 110, 27);

		//pdadosreg
		txtend.setBounds(87, 23, 329, 23);
		txtnum.setBounds(444, 23, 37, 23);
		txtcom.setBounds(585, 23, 72, 23);
		txtcepreg.setBounds(280, 26, 100, 23);
		txtbai.setBounds(63, 60, 236, 23);

		btsal.setBounds(420, 380, 120, 54);
		btlim.setBounds(542, 380, 120, 54);
		btcan.setBounds(664, 380, 116, 54);
		btaddmat.setBounds(356, 244, 40, 40);
		btremmat.setBounds(356, 283, 40, 40);

		btsal.setToolTipText("Pressiona ALT + S para adicionar");
		btlim.setToolTipText("Pressiona ALT + L para limpar");
		btcan.setToolTipText("Pressiona ALT + C para cancelar");

		btsal.addActionListener(this);
		btlim.addActionListener(this);
		btcan.addActionListener(this);
		btaddmat.addActionListener(this);
		btremmat.addActionListener(this);

		rbcnpj.addActionListener(this);
		rbcpf.addActionListener(this);

		btsal.setMnemonic('a');
		btlim.setMnemonic(KeyEvent.VK_L);
		btcan.setMnemonic(KeyEvent.VK_C);

		pdados.add(lblnome);
		pdados.add(lbltelres);
		pdados.add(lbltelcel);
		pdados.add(lblcomp);
		pdados.add(lblbairro);
		pdados.add(lblcep);
		pdados.add(lbltelres);
		pdados.add(lbltelcel);
		pdados.add(lblcnpj);
		pdados.add(lblend);

		pdados.add(txtnome);
		pdados.add(txtrua);
		pdados.add(txtcomp);
		pdados.add(txtbairro);
		pdados.add(txtcep);
		pdados.add(txttelres);
		pdados.add(txttelcel);
		pdados.add(txtregistro);

		pdadosreg.add(txtend);
		pdadosreg.add(txtnum);
		pdadosreg.add(txtcom);
		pdadosreg.add(txtbai);

		pdadosreg.add(lblendreg);
		pdadosreg.add(lblnum);
		pdadosreg.add(lblcom);
		pdadosreg.add(lblbai);
		pdadosreg.add(lbldatent);
		pdadosreg.add(lbldatret);

		pdadosreg.add(centrega);
		pdadosreg.add(cretirada);

		pdados.add(rbcpf);
		pdados.add(rbcnpj);
		
		tpdados.addTab("Dados do cliente", pdados);
		tpdados.addTab("Dados do pedido", pdadosreg);

		group.add(rbcpf);
		group.add(rbcnpj);

		pdados.setBounds(0, 0, 816, 157);

		tpdados.setBounds(9, 46, 816, 157);

		lbltitulo.setBounds(23, 6, 190, 33);

		getContentPane().add(lbltitulo);

		getContentPane().add(tpdados);

		getContentPane().add(spmat);

		getContentPane().add(btsal);
		getContentPane().add(btlim);
		getContentPane().add(btcan);
		getContentPane().add(btaddmat);
		getContentPane().add(btremmat);
	}
	public MaskFormatter Formatar(String mascara)
	{
		try
		{
			MaskFormatter mascara1 = new MaskFormatter(mascara);
			return mascara1;
		}
		catch(Exception e)
		{
			return null;
		}
	}
	@Override
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource() == btcan)
		{
			this.dispose();
		}
		else if(e.getSource() == btlim)
		{
			txtnome.setText("");
			txtrua.setText("");
			txtcomp.setText("");
			txtbairro.setText("");
			txtcep.setText("");
			txttelres.setText("");
			txttelcel.setText("");
			int tot = modelo.getRowCount();
			for(int i = tot; tot > 0; tot--)
			{
				modelo.removeRow(modelo.getRowCount() - 1);
			}
		}
		else if(e.getSource() == btaddmat)
		{
			try
			{
				ArrayList<String> teste = bd.procuraTipos();
				String[] lmaterial = new String[teste.size()];
				String[] ltipomat = new String[teste.size()];

				for(int i = 0; i < teste.size(); i++)
				{
					lmaterial[i] = teste.get(i);
				}

				TableColumn material = tabela.getColumnModel().getColumn(0);
				TableColumn col = tabela.getColumnModel().getColumn(1);

				material.setCellEditor(new MyComboBoxEditor(lmaterial));
				material.setCellRenderer(new ComboBoxRenderer(lmaterial));

				col.setCellEditor(new MyComboBoxEditor(ltipomat));
				col.setCellRenderer(new ComboBoxRenderer(ltipomat));

				tabela.setRowHeight(25);

				modelo.addRow(new Object[] {"", ""});

			}
			catch(Exception e1)
			{
			}
		}
		else if(e.getSource() == btremmat)
		{
			int coluna = tabela.getSelectedRow();
			if(coluna >= 0)
			{
				modelo.removeRow(coluna);
			}
		}
		else if(e.getSource() == btsal)
		{
			System.out.println(txtcep.getText());
			try
			{
				String texto = "Dados inseridos:\nNome: " + txtnome.getText()  + "\nRua: " + txtrua.getText();
				texto = texto + "\nBairro: " + txtbairro.getText() + "\nComplemento: " + txtcomp.getText();
				texto = texto + "\nTel Res: " + txttelres.getText() + "\nTel Cel: " + txttelcel.getText();
				JOptionPane.showConfirmDialog(null, texto);

				Pedido pd = new Pedido();

				pd.setNome(txtnome.getText());
				pd.setEndereco(txtrua.getText());
				pd.setBairro(txtbairro.getText());
				pd.setComplemento(txtcomp.getText());

				pd.setTelres(letxt.desformata(txttelres.getText()));
				pd.setTelcel(Integer.parseInt(txttelcel.getText()));
				pd.setCep(Integer.parseInt(txtcep.getText()));
			}
			catch(Exception erro)
			{
				JOptionPane.showMessageDialog(null,"Impossível proceder com campos vazios");
				erro.printStackTrace();
			}
			this.dispose();
		}
		else if(e.getSource() == rbcpf)
		{
			lblcnpj.setText("CPF:");
			txtregistro.setEnabled(true);
			try
			{
				mcpf.setMask("###.###.###-##");
			}
			catch (ParseException e1)
			{
			}
		}
		else if(e.getSource() == rbcnpj)
		{
			lblcnpj.setText("CNPJ:");
			txtregistro.setEnabled(true);
			try
			{
				mcpf.setMask("##.###.###/####-##");
			}
			catch (ParseException e1)
			{
			}
		}
	}
	class ComboBoxRenderer extends JComboBox<String> implements TableCellRenderer
	{
		public ComboBoxRenderer(String[] items)
		{
			super(items);
		}

		public Component getTableCellRendererComponent(JTable table, Object value,
				boolean isSelected, boolean hasFocus, int row, int column) 
		{
			if (isSelected) 
			{
				setForeground(table.getSelectionForeground());
				super.setBackground(table.getSelectionBackground());
			} 
			else 
			{
				setForeground(table.getForeground());
				setBackground(table.getBackground());
			}

			setSelectedItem(value);
			return this;
		}
	}

	class MyComboBoxEditor extends DefaultCellEditor
	{
		public MyComboBoxEditor(String[] items)
		{
			super(new JComboBox<String>(items));
		}
	}
}
S

Olá amigo

você pode mostrar o form principal?

Silvio Guedes

Criado 20 de setembro de 2013
Ultima resposta 24 de set. de 2013
Respostas 5
Participantes 2